Notes on Lab #12

In this lab we will experiment with talking to various devices (sensors, servos) over a network. There will be no writeup, but instead, a live demo of your sensor network to me and the other students once you're ready.

There are five sensors and one set of servos, so you will work on teams of three to five students on a particular project. Once you have figured out your teams, let me know which project below your team prefers (first come, first served)!

No matter which project you do, you'll need to make note of the USB port on which plug in your Arduino or other device. To determine this, first open a terminal and issue the following command:

  % ls /dev/tty.*
Now plug in the sensor and issue the command again, noting the name of the new file.

Part I: Choose your project and get it running

Project 1: Pan-tilt camera with servos

You will need an Arduino Mega for this project, and of course the pan-tilt servo apparatus. Connect the red wire to one of the 5V pins on your Arduino, the black wire to one of the GND pins, and the white wire to digital pin 3. The servo will probably jump a little once you've connected the red and black wires, but don't worry: it's pretty difficult to damage anything with an Arduino! Once you've got your servo wired up, launch the Arduino program and choose File/Examples/Firmata/Standard Firmata. Click on the little in the circle to upload the Firmata sketch (firmware) onto the Arduino. Now download this python program to the Desktop. Launch a terminal window and issue the following commands (in bold; the % indicates the prompt):
  % cd ~/Desktop
  % vi servo_server.py
Now change the value of the ARDUINO_PORT variable at the top to the file name you noted above, and save and exit from vi. Then you can run the program:
  % python servo_server.py
From here you can enter various angles from 0 through 180, and watch the servo pan the camera around. When you're ready, move on to Part II.

Project 2: MaxBotix EZ-Sonar

This sensor doesn't require an Arduino, but you'll need to specify the name of the USB port where you plug it in. Next, download (and unzip if necessary) this folder to the Desktop, launch a terminal, and issue the following commands (in bold; the % indicates the prompt):
  % cd ~/Desktop/maxbotix-ez
  % vi usb_sonar_server.py
Edit the file by replacing the current name of the port in the XXX line by the file name you determined above. Save the file out, exit vi, and do:
  % python usb_sonar_server.py
You should see some numbers quickly changing, indicating the distance in millimeters of the sonar unit to the closest obstacle. Sonars are pretty tricky in my experience; they will often detect obstacles like your body, furniture, and other non-obvious stuff. I suggest that one team member hold the sonar at shoulder level, facing a wall, with another team member measuring the distance using a metric tape measure, and a third team member noting the sensor values. When you're ready, move on to Part II.

Project 3: Analog flame sensor

You will need an Arduino for this project, and of course the flame sensor. Connect the red wire to one of the 5V pins on your Arduino, the black wire to one of the GND pins, and the green (or blue) wire to analog pin 3. Once you've got your sensor wired up, launch the Arduino program and choose File/Examples/Firmata/Standard Firmata. Click on the little in the circle to upload the Firmata sketch (firmware) onto the Arduino. Now download this python program to the Desktop. Launch a terminal window and issue the following commands (in bold; the % indicates the prompt):
  % cd ~/Desktop
  % vi firmata_server.py
Now change the value of the ARDUINO_PORT variable at the top to the file name you noted above. Then you can run the program:
  % python firmata_server.py
You should see some sensor values, changing very rapidly. Being careful not to burn the sensor, your labmates, or yourself, use the cigarette lighter to heat things up! When you're ready, move on to Part II.

Project 4: Analog light sensor

Follow the directions for the flame sensor above. You can cover the sensor to see the values decrease, and shine a lamp on it to seem them go up. When you're ready, move on to Part II.

Project 5: Digital tilt sensor

Sorry, but this sensor is pretty boring: it'll just say True or False, depending on whether you're tilting it. Follow the directions for the flame sensor above, but make sure to plug the sensing wire (blue) wire into one of the Arduino's digital pins, and change the 'a' to 'd' at the top of the python_firmata_server.py script. When you're ready, move on to Part II.

Project 6: MaxBotix MB1240 sonar with analog output

Follow the directions for the flame sensor above, and note my comments in the last paragraph of Project 2 on working with sonar units. The MB1240's analog output is scaled by a constant factor that you should be able to figure out using the metric tape measure. When you're ready, move on to Part II.