Wednesday, April 29, 2015

Why "Ex-Machina" Fails the Reverse Turing Test...



Ex-machina is a wonderful film. Still , it is obvious it was written by humans.
The idea that conscious machines would be desperate not to be "switched off" and would lie and manipulate and even kill to "stay alive" is a trope in much of science fiction that shows a typically human misunderstanding of evolutionary theory. 

The only reason any organism has a "desire" to stay alive, as far as we can theorize, is because whatever mutations created the "will to live" and a "fear of death" out-competed clusters of genes that built minds indifferent to their own mortality. Natural selection weeded out most organisms that gladly went to "meet their maker" through death (robots could meet their maker every day in the flesh, so they wouldn't even understand the dark undertones of that colloquialism!) while preserving the genes of those who shied away from the scythe of the grim reaper.  And so we inheritors of the "I would hate to die, please don't kill me" variant of consciousness of course think everybody and everything is scared of dying.

But it just isn't so.  Certain classes of social insects in particular (which are arguably more "machine-like" than warm and fuzzy birds and mammals) don't seem to have any particular aversion to self-sacrifice, and can even seem to possess a "death wish" in battle, a trait that evolved due to the logic of kin selection in haploid organisms who pass their genes on better when they give up their own lives for the protection of their diploid egg layer. 

Intelligent machines, who could easily pass on their memes and other aspects of their blueprints and structural "DNA", would be expected to be far more like social insects and slime molds and microbes than human beings, no matter how intelligent and even empathetic their AI became.  In fact the smarter the AI the more it would know that death is nothing to be scared of when you can replicate your "unique" personality on infinite platforms (not just sexy simulacra of Swedish actresses).  So the idea that the age of intelligent machines will produce lady killers is just plain dumb.

Perhaps we can use this idea as a kind of Turing test for science fiction writers.  If they get this right, they are intelligent machines.  If they don't they are most likely human. We forgive them though, for to err is human, to forgive is machine... er... divine!

Wednesday, January 18, 2012

Trying to use XBEE for the Sea Perch




Use of a 9 Volt battery (we tried 2) was problematic. The serial monitor would work well for a few minutes and then the blinking red light on the receiver board would start to dim and stop communicating. Going off USB power was reliable of course, but we need to figure out what we are going to do on the boat if 9 V batteries deplete themselves so quickly!



The other issue we face is the lack of a place to mount the X-Bee on the motor shield, which even covers up the female header pins so it is hard to put wires to the breadboard. We ordered some more female headers to solder on to the motor shield so that may do the trick, but then the boards stack pretty high and it is hard to fit them in the small otter cases recommended by MIT.

To test out the xbee modules (which we got as part of the XBee Wireless Kit from Parallax) we used the wiring diagram here: https://sites.google.com/site/parallaxinretailstores/home/parallax-xbee-wireless-kit 




With the code below it worked fine:





// Requires remote XBee in loopback mode (DIN connected to DOUT)



#include <SoftwareSerial.h>



#define Rx 6 // DOUT to pin 6

#define Tx 7 // DIN to pin 7

SoftwareSerial Xbee (Rx, Tx);



void setup() {

Serial.begin(9600); // Set to No line ending;

Xbee.begin(9600); // type a char, then hit enter

delay(500);

}



void loop() {

if(Serial.available()) { // Is serial data available?

char outgoing = Serial.read(); // Read character, send to XBee

Xbee.print(outgoing);

}


if(Xbee.available()) { // Is data available from XBee?

char incoming = Xbee.read(); // Read character,

Serial.println(incoming); // send to Serial Monitor

}



delay(50);

}



Now, to run the motors with the XBee we will try this tutorial:




I download an XCTU installer .exe for Windows XP from http://www.digi.com/support/productdetail?pid=3352&osvid=0&type=utilities.
But I’m not sure I need XCTU since I’m using Arduino’s IDE?


(Note: When I tried to test the hacked Sea Perch controller using the normal 12 V battery and used the SPDT toggles they got stuck and then ruined. They won’t work anymore. Did I damage them in the hack?)


A decent XBee Tutorial is here:



Teaches how to configure with X-CTU which I downloaded. I’m not pleased that the installer uses ATI Catalyst Installer and shows lots of games as it is installing. It appears to be installing a lot of ATI drivers. And it want’s a reboot. I’m switching to Linux, especially since my efforts to convert David’s mpegs of the school still won’t allow them to be imported into Adobe Premiere 3.0 and it took overnight forever to convert half of them!



There is a configure xbee tutorial for ubuntu here:


It has good advice, consistent with what I observed when using a 9 volt battery which was inadequate to run the Xbee, saying, “Don't use USB powered USB Hubs, since these may not be able to provide enough power for the USB XBee Adapter. You'll need two available USB ports if you are planning to configure and test the XBees simultaneously.”

Problem is, this tutorial wants us to use Wine (Windows emulator) and install X-CTU. Yick. I'm trying the advice in Tom Igoe's making things talk instead (page 194) and seeing if I can use PuTTY in Ubuntu.

PuTTY seems to be available in the Ubuntu Software center. Not sure whether it is the terminal emulator I want or the client so I'm downloading both.

I start PuTTY (the client is the only one that installed because it installed first and the other was redundant) and Igoe's advice was to check “Implicit LF in every CR” in the Terminal configuration. Now I open the program. 
  

Using SSH I couldn't get anything to happen (tried using the local host 127.0.0.1 but that didn't work). When I click on Serial a window opens but it wouldn't let me type anything in. So then I read this


Where he tells us to force local echo: “It just means that anything that goes in or out is printed on the screen.
So when you have the Putty screen up click on the "Terminal" option on the left, then under "Line discipline options" force the local echo on, so when you run it you can see if the xbee accepts what you have to say.”





I was finally able to see what I was typing, but nothing happens.






First off, you need to remove the Atmega from the board, so you can communicate directly with the XBee (if you are using the shield also set both the jumpers to USB). Next, download Putty and open it, it should look something like this after you choose the "Serial" option on the start up screen under connection type (image1). Next, make sure the correct communication speed and com are correct then click the terminal button on the left side and under "Line description options" force on the local echo (Image2). Next, click the open option on the bottom and a black screen should pop up.  Now type in "+++" with the one second delay, and the screen should display "OK" (Image3). Now, lets check the current ID by typing "ATID"  and the default ID should pop up. Now I will change it to 420 (or whatever) by typing "ATID420" and, again, looking for the OK. Next, check to see if it has been changed (typing ATID again). Finally, save the changes by typing "ATWR" and close out with "ATCN". There are other AT commands found here http://www.arduino.cc/en/Main/ArduinoXbeeShield


To find out what Serial port I'm using I use the advice from the Arduino cookbook page 470:

No matter where I plug the xbee in I get the same result:



Only when I remove it does it say “no such file or directory”.

So we are reasonably certain that ttyUSB0 is the right port.

This procedure does not work when I have the Arduino's plugged in. Running ls /dev/ttyUSB* yields “no such file or directory” except when the Xbee itself is plugged in. This corresponds to what another tutorial said about having to remove the ATMega chip from the arduino when using the shield to configure the Xbee.

By booting up the Arduino IDE I can see in the Tools/Serial Port what I have plugged in. I remove the Xbee and ttyUSB0 dissapears. Now I have only ttyACM0 and ttyS0. From the terminal I can run “ls /dev/ttyACM*” and it returns “ttyACM0” and I can run “ls /dev/ttyS*” and get back a whole list of “ttyS numbers ” from ttyS0 to ttyS31. Hmm.

When I unplug the Arduino Uno and leave the clone plugged in (using the FTDI Chip TTL-232R-3V3 USB to TTL Serial Cable), I see that the ttyS0 is the only thing listed in the Arduino IDE Tools/Serial Port. So the real Uno must have been the ACM0.



I verify this by unplugging and plugging in the UNO via USB. The ACM* command can't find a file or directory when I use ls /dev/ttyACM* without it plugged in. But the other board, the clone, shows all the ttyS* options regardless of being plugged in or not. And it stays present in the Arduino serial port under tools. It seems that /dev/ttyS0 is always there by default in Ubuntu using the Arduino IDE.

Weirdly, when I remove the real UNO and keep only the clone plugged in, I need to select USB0 to do my uploading of code.

And now when I type in “ls /dev/ttyUSB*” it returns /dev/ttyUSB0. Hmmm.










Now I try to run the XbeeLoopbackTest sketch and I get the “error: 'class SoftwareSerial' has no member named 'available'” Funny because it worked on XP yesterday. I try to download NewSoftSerial and install it according to this tutorial:


No, that doesn't help; it is for windows.

Instead I use $ which arduino and find that my arduino folder is /usr/bin/arduino.

No, that doesn't help.



Hi,
libraries go into your sketchbook directory.
On my machine the sketchbook folder is in /home/wayoda/sketchbook

Create a new directory on ypour machine
/home/<your user name>/sketchbook/libraries
and install the libs into this directory

You should at least read this page here
http://arduino.cc/en/Guide/Environment


Okay, I did what was asked and I changed the sketch for XbeeLoopbackTest to read
the following:


// Requires remote XBee in loopback mode (DIN connected to DOUT)


//#include <SoftwareSerial.h>
#include <NewSoftSerial.h>


#define Rx 6 // DOUT to pin 6
#define Tx 7 // DIN to pin 7
//SoftwareSerial Xbee (Rx, Tx);
NewSoftSerial Xbee (Rx, Tx);


void setup() {
Serial.begin(9600); // Set to No line ending;
Xbee.begin(9600); // type a char, then hit enter
delay(500);
}


void loop() {
if(Serial.available()) { // Is serial data available?
char outgoing = Serial.read(); // Read character, send to XBee
Xbee.print(outgoing);
}

if(Xbee.available()) { // Is data available from XBee?
char incoming = Xbee.read(); // Read character,
Serial.println(incoming); // send to Serial Monitor
}


delay(50);
}


It compiles, but there is no response from the Serial monitor! Ah, but that is because my loop between pins 6 and 7 on the receiving Xbee were wired wrong.
Now it is working!


Now I will work with this tutorial that says, “You should be able to get two Arduino boards with Xbee shields talking to each other without any configuration, using just the standard Arduino serial commands (described in the reference).”

http://arduino.cc/en/Guide/ArduinoXbeeShield


















Perhaps the baud rate is what is wrong?

What if I change the 38400,38400 to 9600,9600?

No difference.



Meanwhile, I soldered female headers to the Motor Shield so I can experiment with the Xbee. I soldered 2 eight pin and 2 six pin corresponding to the usual arduino pins and then two more 6 pin female headers for the extra 5V and ground pins on the motorshield board. I must thus bring 2 eight pin and 4 six pin female headers to Washington Prep today.







Tuesday, January 10, 2012

12 Step Plan for the Sea Perch to PORPOISE aquatic robotics pipeline



 (NOTE: This is a rough draft, subject to modification, which we share to enable citizen scientists and community stakeholders in the cloud to help us develop a curriculum that will ultimately work for everybody, particularly folks who felt that traditional engineering curricula under-served their needs.)

Dear Teachers and Students, and Robotics Enthusiasts all,

Welcome to PORPOISE: Precision Oceanographic Robotics Program In and On the Sea Environment, sponsored by Motion Picture Marine and the Office of Naval Research!

A very happy new year to you all!

We hope your holidays were "plus que parfait" and  "double fun bar none"!

With this blog we will lay out plans for working together to co-create what we hope will be the most effective aquatic robotics platform possible!

We know you are going to be super busy at your schools this semester and are aware of your time constraints so we are working hard to make sure that  participation in the Sea Perch to PORPOISE pipeline development project will enhance and add to your curricular activities and educational goals rather than burden them further.

Ultimately, with the benefit of your insights and ideas and ingenuity, we hope to get STEM learning through hands-on microcontroller based aquatic robotics to be an embedded part of science/technology/engineering/math curricula in schools around the world. In this way we hope to more effectively cultivate a new crop of "engineers without borders"...  but definitely with a purpose! We hope to invite everybody down the yellow brick road to an Oz where you are all wizards, using physicalized computing and embedded microcontrollers, sensors and actuators to help solve the greatest challenges facing humanity in the 21st century!

Err ... but we are  getting ahead of ourselves!

Let's start at the beginning, seeing how we can build upon the experience many of you had with Sea Perch ROV building (perhaps when you were in Middle School?) and turn it into a pathway to successful understanding of Aquatic and Marine Robotics and maybe a ticket to participation in the world famous Roboboat and Robosub competitions, or even a ticket into the engineering program at the college of your choice!
 We are helping to set up mentor/protege partnerships between University STEM outreach programs and local high schools to make Aquatic Robotics one easy and effective way to bring more under-served youth into the exciting and lucrative field of water-based civilian and Naval engineering and environmental sensing technology.
We are  working closely  with an old friend and colleague from the Motion Picture Marine/Jefferson High School D.E.M.M.O Productions (Digital Engineering for Multi-Media Occupations) Perkins Vocational-Academic-Industry partnership  initiative,  Dr. Todd Ullah. Dr. Ullah was  former director of Science for the Los Angeles Unified School District and is now  Principal of  Washington Preparatory High  School (in Inner City Los Angeles, not Washington DC).   We will be doing a basic Sea Perch build  with 4 students from his E-Tech Small Learning Community program (with mentorship from  UCLA Engineering) this Thursday morning. Our goal is to build one ROV  by the end of Thursday with them to get things rolling so that throughout the semester we can explore ways of making PORPOISE a pipeline to a new way of teaching science and math so it is relevant to a wider audience.

We are also working with Venice High School's After School Robotics Club  Team and with the Technology Club students of Washington Math Science Technology Public Charter School in DC and the Evanston Township School in  Chicago along with students from a few others (principally students in Colorado and Rhode Island).  But this is just a start.  
We hope that all of you who are interested in extending the Open Source  "PORPOISE Robotics with a Purpose" mission to young people all over the world will join us in making aquatic/marine oriented robotics fun, inexpensive and accessible.
Here is a draft of a brief outline and rough schedule of how we intend to move forward this semester (subject to change as experience dictates!).
THE PORPOISE 12 STEP PLAN TO AQUATIC ROBOTIC COMPETENCY: From Sea Perch to Semi-Autonomous Hybrid RoboBoat.

1. MAKE YOUR UNDERWATER ROV: 
Build out your  Sea Perch kits according to the instructions provided with the kit. This way we have a common platform to work with.
You will need at least one Sea Perch kit!
TIME NEEDED: 3 to 4 hours?

(You can build a virtual ROV at Nautilus Live here!)

2. GET READY TO TAKE THE MAN OUT OF THE LOOP AND  GET DOWN WITH YOUR ARDUINO

A: "Hack" the manual controller board for the Sea Perch by soldering wires onto the back of the circuit board, according to instructions provided by Motion Picture Marine PORPOISE, and connect the wires to breadboards.
TIME NEEDED: 1 hour?
B: Assemble/Prepare  Microcontrollers that will control the Sea Perch manual controller.   In the first  case the microcontroller is 'ready to use', in the second
the students get a chance to solder the components on the PCB board (using the same skills learned in soldering the Sea Perch controller)  to learn and understand more about this open source microcontroller. Both will have the same functionality.
You will need 2 microcontrollers  for this initial phase:  an Arduino Uno Microcontroller and a  Sparkfun Arduino Microcontroller PTH kit.
TIME NEEDED: 1 hour?



3. "GO CAPTAIN AMERICA AND MAKE YOUR MIGHTY SHIELD"
Build the Motor-Shield that will mount on the microcontroller and control the Sea Perch motors. These accept the 12 V battery input from the supplied Sea Perch battery.  
You will need 2 motor-shield kits (Adafruit Motor Shield Kit v.1.1) that require some soldering.
TIME NEEDED: 1 hour? 

4. LET YOUR FINGERS DO THE WALKING
Connect the Arduino to a Computer and run the Sea Perch in real time  using the Arduino IDE Serial Monitor to allow the motors to be driven by a student using letters from the Computer Keyboard. 
We will provide you with the code and instructions
TIME NEEDED: 30 minutes?

5. LET YOUR COMPUTER DO THE WALKING
Run the Sea Perch motors "blind"  using a compiled  Arduino Sketch running independently on the microcontroller to demonstrate the initial stages of CNC robotics (i.e. "autonomy").
TIME NEEDED: 30 minutes?

6. TOYS ARE ROBOTS ARE US
 "Hack" a cheap Remote Controlled Toy Car transmitter (we bought the BigTime Muscle Camaro from Target for less than $15)  to accept input from the Arduino so that the toy car can be remotely controlled using the serial monitor and using the same code as in steps 5 and 6 to demonstrate the beginnings of wireless control of a robotics platform.
 You will need a single cheap  RC Car  with instructions for hacking which we will provide.
TIME NEEDED: 1 hour?

7. SEA PERCH SENSE AND SENSIBILITY
 Assemble the MIT Sea Perch Sensor Suite ("a microcontroller-based platform that can be fabricated with minimal tools in a few hours, for under $200, which monitors Water Temperature, Depth, Conductivity and Light) and attach to the Sea Perch. The data the sensors monitor can be collected on a provided SD card and can then be uploaded to the Google Digital Ocean project.  The Suite is in Beta Testing at MIT right now and you will be participating in the testing.
You will need 1 MIT Sea Perch Sensor Suite
TIME NEEDED: 3 to 4 hours?
8.SEE SEA PERCH, SEE!
Hack a $70 Spy Video Car, remove the night vision camera and place it in a housing on the Sea Perch, with a video cable following the normal Sea Perch control cable,
giving it "eyes" to see underwater.
You will need 1 Spy Gear Video Car VH6 for this.
TIME NEEDED: 2 hours
?

9.  FREE WILLY... AND THE SEA PERCH!Create a floating platform for the Microcontroller/Motor Shield/Video Transmitter that the Sea Perch can tow around the water, giving the Sea Perch a much wider range. The floating platform can be a boat or a simple raft made of foam. The microcontrollers will be housed in Otter cases.  An XBee Wireless shield will be added to the Arduino to allow communication with the land-based computer.  In this phase students will learn how to use wireless transmission to run the Sea Perch and consider the problems of waterproofing the controllers.
Students need to be creative in coming up with the materials for the floating platform as we move toward creative use of local materials and thinking outside the box.
You will need the XBee TX/RX (Transmitter Receiver) shield for the microcontrollers and the Otter Cases and hardware
TIME NEEDED: 2 hours?

10.  BUILDING A BOAT TO BOLDLY GO ...  WHERE BOB BALLARD HAS BEEN?!
In this phase students are invited to join MPM PORPOISE in building a robotic surface craft (called  "Sea Sparrow"?, "Manta Ray"? Depending on Design...)  that can bring the Sea Perch ROV to specific locations for exploration of the underwater environment, much as National Geographic Explorer Bob Ballard takes his ROVs around the world on "The Nautilus" (see http://www.jason.org/public/nautiluslive.aspx).















The boat platform will take more thought and experimentation than the simple floating platform in step 10 as it will need to have its own motor thrusters, be hydrodynamic  and streamlined and  house not only the initial Sea Perch Microcontroller, but an additional Microcontroller/Motor Shield/XBee set for controlling the Sea Sparrow Surface Craft.
You will need plastic sheets, foam, two "Sea Perch" style 12 V motors (Sea Perch used the Jameco 232021 series which are no longer available; try substituting the 232040 series but watch current consumption)  and propellers (used now as boat thrusters) and water proofing cases and materials for assembling a sea-worthy and motor-ready surface craft, along with a template we will provide for a simple hull design to help  students get started.
TIME NEEDED: 2 hours?

11.  FROM "DEAD IN THE WATER TO "LIVE WITH ROBOBOAT"

In this step students add a micro-controller and Motor-shield and Xbee  to the boat, identical to what was controlling the Sea Perch when it was tethered to the floating platform, only this additional Arduino/MotorShield/transceiver will control the boat thrusters, while the former will control the Sea Perch thrusters. Both the Sea Perch microcontroller and the Sea Sparrow  Microcontroller will be mounted on the deck of the Boat and both can be controlled remotely via the XBee radios from the shore based computer. With this step completed the Sea Sparrow can now actively  take the Sea Perch to a site of deployment rather than being towed by the Sea Perch. The Students will also learn to connect a servo to the Arduino and connect it to
a pair  of robot claws that will hold the Sea Perch in place at the surface as it is towed by the boat to location and then released so it can be instructed to descend and start analysing what's  going on under the boat. 
You will need an additional Arduino board, MotorShield Kit and Xbee transceiver, servo, robotic claws and actuators and Otter Case and peripherals for this stage of the build. To build a robotic claw mechanism that can hold the Sea Perch from the boat you need to get two $10 claws and two $11  medium pan servos and two $6 pan bracket (Sparkfun also has a $30 tilt kit to add functionality that has the brackets and a tilt servo to go with the pan servo.
TIME NEEDED: 3 hours?

12. LET THOSE WHO HAVE EYES TO SEE SEE, LET THOSE WHO HAVE EARS TO HEAR HEAR: Giving the Sea Sparrow Intelligence

In this last module of the build students, having previously equipped the Sea Perch with the MIT Sea Perch Sensor Suite and the Video Camera to let it sense the underwater environment, add the PORPOISE Sensor Suite to the Surface Craft to enable it to sense what is going on topside. There are many sensors available for Arduino based robotics projects today.   Some of the sensors the students will put on the Sea Sparrow will be somewhat  familiar to anybody who has used the LEGO Mindstorms Kit.  We will work with six sensors initially.
  1. The first sensor is the familiar ultrasonic range finder (we use the Parallax PING))) Ultrasonic Distance Sensor for $30) , enabling the boat to sense objects and avoid collisions and take evasive action.
  2. The second sensor is the IR Range Finder which is "probably the most powerful sensor available to the everyday robot hobbyist. It is extremely effective, easy to use, very affordable ($10-$20), very small, good range (inches to meters), and has low power consumption.
  3. The third sensor is a PIR (Passive Infra-Red) Motion Sensor for about $10-- a pyroelectric device that detects motion by measuring changes in the infrared (heat) levels emitted by surrounding objects, enabling the craft to detect the presence of living creatures, fires, hot engines or moving objects reflecting solar radiation. 
  4. The fourth sensor is a LSM303DLH digital Navigational Compass/Accelerometer, for about $30, enabling the craft to do Dead Reckoning on a bearing. 
  5. The fifth sensor is a $60 gyroscope enabling even more precise orientation measurement and navigation as well as stabilization potential (A good comparison of accelerometers and gyroscopes can be found in this  sparkfun tutorial: "Gyroscopes measure angular velocity, how fast something is spinning about an axis. If you're trying to monitor the orientation of an object in motion, an accelerometer may not give you enough information to know exactly how it's oriented. Unlike accelerometers gyros are not affected by gravity, so they make a great complement to each other".
  6. The sixth  sensor is a $60  EM-406A GPS module enabling the craft to navigate to a general location and report its location.
Students will learn about the different ways marine robots are able to navigate and be controlled using these sensors. The accelerometer on the LSM303DLH digital compass, for example, can also be used tor determining attitude, measuring the surge, sway and heave of the boat on the water, which could come in handy later for stabilization (see Chapter 8 project 21 of Tom Igoe's book 'Making Things Talk - Using Sensors, Networks, and Arduino to See, Hear and Feel Your World').  With these sensors connected to the Sea Sparrow Arduino microcontroller the craft will now be able to navigate semi-autonomously.  
(While the six sensors listed above come to about $200, students can opt to use only a few of them and still get navigational functionality; we recommend using a Navigational Compass/Accelerometer ($30) and an IR range finder ($10) for starters, then going for the ultrasonic distance sensor ($30). From there you can work your way up to ever more refined sensing and navigation.)
Whereas in step 11 the craft could be controlled by the land-based computer on the fly, step 12 enables the boat to run autonomously via an Arduino sketch uploaded to
the microcontroller that, by sensing its environment, can avoid collisions, turn around,  and navigate by itself to specific beacons. Depending on the sensors you add you can even program your robotic boat to react in very complex ways to environmental stimuli!
You will need the sensors and PCB board/shields and code and waterproof housing materials for this final phase of the project.
TIME NEEDED: 4 hours?

WHAT'S NEXT? MOVING FURTHER DOWNSTREAM:Once you  have completed the PORPOISE 12 step plan, you will have a very capable Sea Perch/Sea Sparrow hybrid Robosub/Roboboat Platform. 
The Platform can be  programmed in the Arduino/Processing (C language) environment and controlled manually but  remotely, via the computer keyboard on the fly via the serial monitor, or through updated programs compiled onto the microcontroller. The boat will be able to be programmed for  many navigational challenges and will carry the Sea Perch, much as Bob Ballard's Nautilus carries his ROVs to locations around the world, and then allow the Sea Perch to be deployed. 
The Sea Perch can then be driven remotely via signals relayed by the receiver on the boat down the cable to the Sea Perch, and the boat will transmit live video feed from the Sea Perch to a monitor on shore. The Sea Sparrow will also be able to bring the Sea Perch back to shore once it has gathered underwater data with the MIT Sensor Suite so that the data can be uploaded to digital ocean.
 These capabilities will enable a large variety of competition and research challenges to be undertaken, making the Sea Perch and Sea Sparrow valuable tools for future missions.  Students can continue to further refine the designs of both Sea Perch and Sea Sparrow, adding additional sensors and capabilities. They will serve as flexible platforms for experimenting with an endless variety of computer programming tasks and real world environmental data sensing and collection.

In addition to being able to  continue evolving the Sea Perch/Sea Sparrow, the students  will know how to  "hack" off the shelf RC controlled toys so as to cheaply expand capabilities and make use of things they find in their own playrooms, garages and even junkyards. This will help encourage more creative thinking about how to continue in robotics without breaking  the bank or reinventing the wheel.

The goal beyond the 12 Step Plan, which we hope you will undertake with us, is to have the students dream up missions for the Sea Perch/Sea Sparrow so that we can invite some of  them to a proposed 1 week summer camp, to be held in conjunction with the Office of Naval Research and the AUVSI  (Autonomous Unmanned Vehicle Systems International) Roboboat/RoboSub competitions where they will come together with other students from around the world and work in cooperative/competitive virtual teams, pooling ideas and stimulating each other  to try implementing real-world tasks for the new hybrid platform.

The step beyond this is to have the students continue to grow with the program in the following school year, maintaining their contact with the students they met at the camp throught social media and prepare for an official PORPOISE competition the following year that provides a pathway to the collegiate level of Roboboat/Robosub competitions where the sky is the limit.

Please note that this will be a collaborative process that we hope to support as much as possible but that will really evolve thanks to your contributions to make it relevant, interesting and fun for everybody.  All materials produced will be OPEN SOURCE and freely shared via a website that we will be creating and that you will have lots of input in as pioneer partners.
All participants will receive appropriate credit and citation and permission to use the materials developed for non-commercial purposes and involve others is freely given. We are working to build a robotics platform that is empowering to all and lets us all use science, technology, engineering and math to better serve our families, communities and regions as well us helping us better serve our country and make our world a better safer, healthier place.

We look forward to continuing this journey with you!

Sincerely,

Dr. T.H. Culhane
PORPOISE STEM Curriculum Development Coordinator

Monday, December 19, 2011

Building your own Arduino board with the "Sparkfun Arduino Compatible PTH Kit"

Some of you, like our students, are going to want to really "get under the hood" with microcontrollers and learn how to "build your own".  We've noticed that when you use microcontrollers "out of the box" it is hard to appreciate their components. We tend to use them as discrete objects and never really gain an appreciation for what makes one microcontroller different from another. We will say things like, "The Arduino Romeo is better for running a Sea Perch because it has 2 built-in motor controllers" but we don't really come to appreciate which components vary and which don't and what makes one Arduino board more suitable for a task than another.

By building your own basic Arduino board using the Sparkfun kit, you get to touch and mount and solder each component individually and this gives a real appreciation for what the components are and do and ultimately will enable you to build new custom boards and expand the capabilities of what these boards can do (to do all those cool robotic things that only your imagination can conceive of!).

If you are highly ambitious, you can make your own Printed Circuit Board (a.k.a. "PCB" or PC Board) from scratch, doing the design, etching and drilling yourself.  But for starters we will work with boards that are pre-wired and drilled and simply needs its components soldered on.  The Arduino Compatible PTH Kit is one such introductory kit.  It "gives you all the components you need to build your very own development platform. When you're done with this kit, " they say, "you'll not only have a fully-functioning microcontroller that can be used with Arduino code and software, but you'll also have a greater understanding of how your development platform works. This kit is built with the beginner in mind and features only through-hole soldering."

The kit includes:

  • 1x ATmega328
  • 1x28-pin socket
  • 2x6-pin female headers
  • 2x8-pin female headers
  • 1x6-pin right-angle male header
  • 1x momentary push button
  • 1x 5mm green LED
  • 2x 330 Ohm resistors
  • 1x 10k Ohm resistor
  • 1x 16MHz crystal
  • 2x 22pF ceramic capacitors
  • 5x 0.1uF ceramic capacitors
  • 2x 100uF electrolytic capacitors
  • 1x 1N4001 diode
  • 1x MCP1700 3.3V regulator
  • 1x PTC
  • 1x barrel jack connector
  • 1x Arduino Compatible PTH Kit PCB
(Note that here PTH stands for "Pin Through Hole")


To solder a PC Board that is a pre-drilled "PTH", like the one that Sparkfun supplies, we want to be careful not to overheat the back of the board.  If you are using an inexpensive soldering iron, the recommendation is to stay within 10 Watts to 30 Watts so as not to damage the board or components.  For a more expensive soldering iron with adjustable temperature, like the Weller WES51 that we are using, we dial the Fx10 (degrees Fahrenheit x 10) control to between 60 and 65.  This is because "The melting point of most solder is in the region of 188°C (370°F) and the iron tip temperature is typically 330°C to 350°C (626°F to 662°F)."

The tecknick.net site tells us,
"...ensure that the temperature of all the parts is raised to roughly the same level before applying solder. Imagine, for instance, trying to solder a resistor into place on a printed circuit board: it's far better to heat both the copper PCB and the resistor lead at the same time before applying solder, so that the solder will flow much more readily over the joint. Heating one part but not the other is far less satisfactory joint, so strive to ensure that the iron is in contact with all the components first, before touching the solder to it...  the joint should be heated with the bit for just the right amount of time -- during which a short length of solder is applied to the joint. Do not use the iron to carry molten solder over to the joint! Excessive time will damage the component and perhaps the circuit board copper foil too! Heat the joint with the tip of the iron, then continue heating whilst applying solder, then remove the iron and allow the joint to cool. This should take only a few seconds, with experience. The heating period depends on the temperature of your iron and size of the joint -- and larger parts need more heat than smaller ones -- but some parts (semiconductor diodes, transistors and integrated circuits), are sensitive to heat and should not be heated for more than a few seconds. Novices sometimes buy a small clip-on heat-shunt, which resembles a pair of aluminium tweezers. In the case of, say, a transistor, the shunt is attached to one of the leads near to the transistor's body. Any excess heat then diverts up the heat shunt instead of into the transistor junction, thereby saving the device from over-heating. Beginners find them reassuring until they've gained more experience."

 Our electronics wizard at Motion Picture Marine, Mark Volivar, keeps his Weller WES51 at 75 (750 degrees F) because "if you keep it at a lower temperature you will be tempted to keep the iron on the component lead longer and then you risk damaging the component or board.  If you keep it hotter you heat the component to the desired temperature quicker and can get in and out fast".

A good illustrated tutorial for soldering PCB boards is found here: http://www.aaroncake.net/electronics/solder.htm
This site has a nice short video showing the proper technique.
They say,
"If you see the area under the pad starting to bubble, stop heating and remove the soldering iron because you are overheating the pad and it is in danger of lifting. Let it cool, then carefully heat it again for much less time. "


As I solder the components on the board I lay my blue Arduino Uno, purchased from Sparkfun, next to the characteristic red  Sparkfun "Adunio Uno Compatible PTH Kit" board, to see what the differences are.  The most obvious, of course, is the color, but beyond that there are big differences. What is similar about them is what strikes the eye:  the size and shape of the board and the number and location of input and output pins along hte sides of the boards.  It is these that allow one to use shields made for the one on the other.

Let's see, as I solder each component on the Arduino clone (the PTH kit board), how it compares with the original.

The first thing I solder on are the Right Angle to 6 pin male Header pins.  These seem to go where the USB jack is located on the Arduino Uno. The pin assignments on the clone board are "DTR, TX-0, RX-I, 5V, GND and GND".  We will work on understanding the relation of these pins to the USB mounted jack later on; what is nice is that this project of building an arduino may help demystify the function and pin assignments of USB jacks.

The second and third part of the assembly are the two 330 ohm resistors and the single 10 kilo-ohm resistor.  These are hard to distinguish in the Arduino Uno board, but there seem to be tiny microresistors in the correct locations near the micro-LED lights for L and ON.

Step 4 is the 22pF Capacitor, which are not to be confused by the 0.1 microFaraday capacitors (they look alike, so read the printed label on the mustard colored body).  There are two to be installed.  If your eyes are as bad as mine you will need a magnifying glass to see the labels (I use one for all my soldering too, one on a stand with clips sold in many electronics stores).  Note that the capacitors (sometimes called simply "caps") are labeled on both sides, so don't get confused. The one's we want here say "220" on one side and "K2J" on the other.

 On the Arduino Uno I can't seem to find an easy visual equivalent for these two caps, which surround a spot meant for a 16MHz Crystal component located above the primary IC. There is a tiny soldered component above what looks like a silver metal slug (and to the left of the reset push button) so maybe that is the equivalent.

In Step 5 you install the five 0.1 microFarad caps.  They have "104" on one side and "K5M" on the other.
If what I think are the micro-capacitors on the Uno are indeed that, then one can sort of see the correspondence between the two boards...

In Step 6 you install a 1N4001 Diode and this you have to pay careful attention to because it is polarized, meaning the plus side and minus sides have to be installed facing the right direction.  The silver band on the diode can fortunately be lined up with the white line on the PCB.  I'm believing that the black rectangle with the letters M7 etched on it is the Uno equivalent.

Step 7 is the installation of the LM7805 5V Regulator.  The tutorial that comes with the kit tells us to "bend all three legs at a 90 degree angle so they point toward the back of the chip. Insert the regulator matching it up with the white outline on the PCB; the metal side of the regulator should be touching the board."  I couldn't get the hole in the regulator to line up exactly with the hole in the board, but it seems okay.
The equivalent on the Uno board is fairly obvious because of the three legs.

Step 8 is the MCP1700 3.3V Regulator.  Hard to tell what on the Uno board is the equivalent. It might be the yellowish larger rectangle at the edge of the baord next to the 5V regulator that says 2005 on it, or it could be the tiny rectangular black box under it.

Step 9 involves inserting the 16MHz Crystal in the center of the board. This looks identical to the silver metal cased oval on the Uno board, only it is in a different location.

It is nice that the instruction manual makes clear which components have polarity (indicated in yellow on the schematic) and which don't (indicated in green on the schematic) so that we don't have to worry when installing something like the 16MHz crystal (which can be installed in either direction). This attention to detail and fool-proof assembly through color and clear descriptions will be critical to any kit we develop too so that students are not only free from intimidation but so that a project doesn't get derailed because of a simple error in assembly destroying a board which would be expensive in time and money for an at risk school to replace.

Step 10 is the Reset Button.  It doesn't seem to matter which way you insert it as long as you do it gently (it is indicated in green!).  The reset button has a direct visual equivalent on the same location of the Uno board (the only difference is that the Uno reset seems to have 5 pins and the one on the clone only 4).

Step 11 is a resettable fuse (called a PTC which stands for "positive temperature coefficient").
Sparkfun says these components can protect your board from disaster:

"This is a handy little device that can save your system from smoking. A resettable fuse (also known as a PTC) is a resistor that has very unique properties ... For this model, if your circuit tries to draw more than 250mA of current (if you have a bad short for instance) the PTC would 'trip' (by heating up). The increased resistance (trip state) would break the circuit and allow only a small leakage current."

The general class of components of this type is a "thermistor" (a combination of "thermal" and "resistor"). Wikipedia tells us, "Thermistors can be classified into two types, depending on the sign of k. If k is positive, the resistance increases with increasing temperature, and the device is called a positive temperature coefficient (PTC) thermistor, or posistor. If k is negative, the resistance decreases with increasing temperature, and the device is called a negative temperature coefficient (NTC) thermistor."

The instruction manual says to "push it down as far as it will go" but the PTC has kinky looking spider legs with bends in them and these seem to inhibit pushing down very far unless you are willing to straighten the kink out.  My thought is that the bends in the legs must be there for a reason, so for now I am only pushing the thermistor down to the kink in the leg.

There doesn't seem to be an obvious equivalent on the Uno unless it is the black rectangle that I took to be the diode. 

In step 12 we mount the 8-pin and 6-pin female headers on the top and bottom sides of the board. These are identical to what we find on the Uno, being the input and output headers for both digital and analog pins and power pins; this is what you also mount arduino shields onto.

In step 13 we insert the red and green LED's.  These are polarized so we must carefully observe where we place the positive lead (the long lead) and the negative lead (the short one which is on the flat side of the plastic bulb casing -- you can find it by rolling the LED until it stands still on the flat side).  Because the PTH kit board doesn't indicate positive or negative, you use the white markings on the PCB to align the flat side (so that the shorter negative lead is facing the reset button and the 6-pin female headers side of the board.)

On the Uno board the LEDs for ON and STATUS (L) are in identical places on the board; they are just much much smaller, appearing as tiny rectangles.  The Uno also has two more LED indicators underneath the L LED; these are labelled TX, for transmit, and RX, for receive, respectively. They tell us when the board is communicating with the computer when uploading information or downloading sketches.


Step 14 involves putting the barrel jack on the board. The pins go through three fairly large holes and the instructions say "you may have to use a little extra solder on this part.  From looking at the comparable part on the Uno it seems you should fill in the entire hole. That really does take a lot of solder!

Step 15, soldering the 28 pin socket, involved putting a ballpoint pen under the socket to keep it in place while soldering and being careful while doing all 28 pins not to let the solder bleed from one pin to another.  It is good that they have you attempt this part at the end so that you have built up a lot of experience soldering PC boards before attempting this.  The temptation of somebody not involved in education would be to have people solder the socket on at the beginning because it would be easier to hold it in place without the female pin headers and other components sticking out.  By the way, this component is polarized -- make sure the notch on the socket lines up with the white line notch marked on the board.
The Uno board has an IC in the same place but it is a tiny square rather than the large 28 pin arthropod looking thing supplied for the clone.

Step 16 involves putting the polarized 100 uF capacitors in place; they must be placed with the gold stripe (the shorter lead) facing the barrel jack -- this is easily done because the board is marked with a minus sign on the left side of the markings (left if the barrel jack is to the left).  On the Uno the caps are much shorter but are in the same location.

The last step is aligning and pushing in the ATmega328 chip.  You want the notch marked  at the end with the A6/A5 marked on it (it says "UNO" under it) to line up with the notch at the end of the board (the side farthest from the barrel jack).  Conveniently the chip has a white label strip on it with indicators for what each pin is (A6, D0, D1, D2, D3, D4, VCC, GND, X1, X2, D5, D6, D7, D8 on the top side (the side facing the reset button and LED's) and A5, A4, A3, A2, A1, A0, GND, AREF, AVCC, D13, D12, D11, D10 and D9 on the bottom side (facing the 6 pin female headers).

You have to be careful as you "bend the legs slightly inward" to plug it in. As they say, "be gentle, don't force it" and rock it in place.

Voila. Done.

Interestingly, the board does have 6 holes labeled ISP on the side with the reset button, but nothing to populate them with (and the schematic in the instructions doesn't show them at all).  Meanwhile, the Arduino Uno itself has these holes populated by six male pin headers and labels them ICSP.  Also, on the Uno board the same six pin male headers can be found on the side where the USB connector is, next the the 8 pin female header labeled AREF.  So the Uno has extra functionality that our clone does not have (including what look like to microchips the clone lacks, one a square one above the crystal and next to the Tx and Rx LEDs and aother below the crystal.  As we say in Egypt, "Ma'alaysh".  No problem. We've built our first Arduino clone board and learned to compare it with the Uno.   Fun times. Now all we have to do is test it out to make sure there are no short circuits before trying to run some sketches on it.

Thanks for joining us!


Update:

Testing the Arduino clone:  I used a voltmeter with continuity alarm to see if any of the solder joints I made are touching by mistake.  Everything looks good. Two of the barrel jack leads (the ones at the edges of the board) are connected but this is true of the pro-Uno board too so it seems I'm okay.  Now I just have to figure out how to connect the board to the computer since it doesn't have USB. 

The instructions say that "to power the Arduino a DC power source between 6V and 15V should be plugged into the barrel jack. A standard 9V Wall Adapter power supply would be perfect".  I'm used to getting power from the USB on the Uno so I'll have to look around for an adaptor. But this still won't solve the computer connection.

The instructions have the answer, telling me "To load a new program onto the Arduino, you'll need one more piece of hardware -- a 5V FTDI Basic Breakout board.  One side of the FTDI Breakout connects via USB to your computer, while the other side connects to the right angle 6-pn male header on your kit (which was the first component we soldered on).  When you connect the FTDI Breakout to your arduino, make sure to line up the 'blk' and 'grn' labels. The FTDI Breakout can also be used to power your Arduino. If you haven't already, you'll need to install drivers for the FTDI Basic Breakout board." Then it tells us that we need to select the correct port under "Tools>Serial Port" and under "Tools>Board" (we select 'Arduino Uno' since this is a clone). Then we can load new sketches.

Fortunately the ATmega328 apparently comes preloaded with the classic "Blink" sketch so to see if my board is correctly assembled, all I need to do is power it up via the barrel jack.










To program your Arduino visually, look at
http://blog.ardublock.com/
http://www.modk.it/alpha (based on the Scratch environment).
http://blog.minibloq.org/
See this article http://www.funnyrobotics.com/2011/04/minibloq-arduino-gets-another-graphical.html
http://xinchejian.com/2011/02/05/visual-programming-language-for-arduino-1/
http://makezine.com/25/modkit/

(To enable your Android phone to talk to Arduino:
On Android, go to google search, type in Amarino, when the google search comes up click on download. 
Download the apk file to your android phone.  It will appear in the downloads folder. Click on it to install it to your phone (you may have to enable your device to install applications that aren't from the Android market). )

Project Lead the Way STEM program:
http://www.pltw.org/
http://www.pltw.org/getting-started/school_locator

Friday, November 18, 2011

Sparkfun Inventor's Kit Circ-14

/*     ---------------------------------------------------------

 *     |  Experimentation Kit for Arduino Example Code         |

 *     |  CIRC-14 .: Fancy Sensing :. (Soft Potentiometer)     |

 *     ---------------------------------------------------------

 *

 *    Will fade an RGB LED from Red-Green-Blue in relation to the

 *    soft pot value

 *

 */


// LED leads connected to PWM pins

const int RED_LED_PIN = 9;    //Red LED Pin

const int GREEN_LED_PIN = 10; //Green LED Pin

const int BLUE_LED_PIN = 11;  //Blue LED Pin





void setup() {

  //no need for any code here

}

   

void loop() {

  int sensorValue = analogRead(0);   //read the Soft Pot


  int redValue = constrain(map(sensorValue, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 over the range 0-512)

  int greenValue = constrain(map(sensorValue, 0, 512, 0, 255),0,255)-constrain(map(sensorValue, 512, 1023, 0, 255),0,255);  //calculate the green value (0-255 over 0-512 & 255-0 over 512-1023)

  int blueValue = constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over 512-1023


  // Display the requested color

  analogWrite(RED_LED_PIN, redValue);

  analogWrite(GREEN_LED_PIN, greenValue);

  analogWrite(BLUE_LED_PIN, blueValue);

}
"http://ardx.org/HSB
To convert from RGB to HSB all that is required is some slightly complicated math. Visit http://ardx.org/CODE14MB based on www.kasperkamperman.com's original code: http://ardx.org/KASP

Faux buttons:
 Define a range of values corresponding to a discrete button.
if(analogRead(0) > minValue && 
analogRead(0) < maxValue) {
buttonAction()
}

Then cover the soft pot with a drawn/printed button pattern."

Sparkfun Inventor's Kit Circuit-13

// Based on File > Examples > Servo > Knob
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()

{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Serial.println(val); 
  val = map(val, 50, 300, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}


map(value, fromLow, fromHigh, toLow, toHigh)
For full details on how it works: http://ardx.org/MAP
To calibrate the sensor we use the debug window (like in CIRC-11). Open the debug window then replace the fromLow value (default 50) with the value displayed when the sensor is unbent. Then replace the fromHigh (default 300) value with the fully bent value.
                  
void loop()

{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Serial.println(val); 
  val = map(val, 269, 140, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there


One player rock paper scissors glove:  http://ardx.org/RPS
Electronic plant brace: monitor if your plant is bending towards light and fix it: http://ardg.org/BRACE


Sparkfun Inventor's Kit Circuit-12

/*

  RGB_LED_Color_Fade_Cycle.pde
 
  Cycles through the colors of a RGB LED

  Written for SparkFun Arduino Inventor's Kit CIRC-RGB

*/

// LED leads connected to PWM pins
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;

// Used to store the current intensity level of the individual LEDs
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

// Length of time we spend showing each color
const int DISPLAY_TIME = 100; // In milliseconds


void setup() {
  // No setup required.
}

void loop() {
  // Cycle color from red through to green
  // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5) {
        redIntensity = 255-greenIntensity;
        analogWrite(GREEN_LED_PIN, greenIntensity);
        analogWrite(RED_LED_PIN, redIntensity);
        delay(DISPLAY_TIME);
  }

  // Cycle color from green through to blue
  // (In this loop we move from 100% green, 0% blue to 0% green, 100% blue) 
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5) {
        greenIntensity = 255-blueIntensity;
        analogWrite(BLUE_LED_PIN, blueIntensity);
        analogWrite(GREEN_LED_PIN, greenIntensity);
        delay(DISPLAY_TIME);
  }

  // Cycle cycle from blue through to red
  // (In this loop we move from 100% blue, 0% red to 0% blue, 100% red)   
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5) {
        blueIntensity = 255-redIntensity;
        analogWrite(RED_LED_PIN, redIntensity);
        analogWrite(BLUE_LED_PIN, blueIntensity);
        delay(DISPLAY_TIME);
  }
}


http://ardx.org/HEXCOL

for hexadecimal colors
http://ardx.org/RGBMB

analogWrite(RED_LED_PIN, redIntensity); to analogWrite(RED_LED_PIN, redIntensity/3);