22 January, 2010 **************** Getting the source Go to a directory where you want to store your work and execute the following commands $ cd YOUCHOOSEDIR $ ( cd /home/brock/public_html/classes/Spring2010/csci373/ ; \ tar cf - ./MakingThingsTalk ) | tar xfv - We'll talk about what is happening in class. [You do need to be a bit of a Linux guru for some of this course.] **************** Voltage play Next we are going to experiement with voltages. Place a potentiometer on your board ... Red in 5V Black in GND If you have a multimeter try to measure voltage between black and green [If you don't have a potentiometer, just use a couple of resistors as a voltage divider.] **************** Arduino analog input Now let's do this with an Arduino board Use the book program analog_sensor_reader/analog_sensor_reader.pde Make the program a bit more C-like. Add the following define at the beginning of the problem, where XX is the Arduino pin where your green line is connected. #define ANALOG_PIN XXX Change the program to read from this input. Slow down the output by changing the delay. Potentiometer should give readings between 0 and 1023 **************** Arduino analog input on Linux Exit from your Arduino program. We're going to read the input directly. Execute the following command to list USB devices by device ID. Try to figure out which device is your Arduino. $ lsusb Now look at the system interfaces to "tty" devices. $ ls -l /dev/tty* | more $ ls -l /dev/pts How are the devices associated with files? 1) Kernel device drivers associate real devices with major,minor numbers 2) OS utilities or system admin associates major,minor numbers with file names, using mknod See which device is associated with your shell $ tty Unplug the device and see how if the device files disappear **************** Reading outside of Arduino Read your Arduino output directly with commands like $ cat /dev/ttyUSBn If you get a device busy, someone other program has it open. Try turning the knob and seeing the changes. **************** Trying a different device Repeat the last couple of steps, but use other forms of voltage dividers. Perhaps a photosensor in series with a resistor. DO NOT SHORT the board! Use a resistor beween GND and 5V! **************** Reading from a Python program First try reading from python $ python >>> sin = open('/dev/ttyUSB1', 'r') >>> line = sin.readline() >>> print line >>> num = int(line.split()[0]) >>> print Read input as you wish, but close when done. You can also try a someone more elaborate Python program that reads several numbers from serial input looking for the largest. It's at http://www.cs.unca.edu/embedded/lab-22-01-2010.py **************** Reading from processing I'd prefer that you modify the Python program to do something interesting -- like print the highest and lowest values within the last minute. But you can also go on to processing and see if you can get it working with your inputs.