Arduino Spooky Projects Class 3 PDF
Arduino Spooky Projects Class 3 PDF
Arduino Spooky Projects Class 3 PDF
Class 3
21 Oct 2006 - machineproject - Tod E. Kurt
Remove ProtoShield
First half of class, we dont need it And we want to observe the Arduino board
Recap: Programming
Edit Compile
Reset
Upload
Can talk to not just computers. Most things more complex than simple sensors/actuators speak serial.
Arduino Says Hi
serial_hello_world
Click on Serial Monitor to see output Watch TX LED compared to pin13 LED
This sketch is located in the handout, but its pretty short. Use on-board pin 13 LED, no need to wire anything up.
You type H
LED blinks
This sketch is in Examples/serial_comm/serial_read_basic. Notice how you might not always read something, thus the -1 check. Can modify it to print hello world after it receives something, but before it checks for H. This way you can verify its actually receiving something.
Arduino Communications
is just serial communications
Psst, Arduino doesnt really do USB It really is serial, like old RS-232 serial All microcontrollers can do serial Not many can do USB Serial is easy, USB is hard
serial terminal from the olde days
Serial Communications
Serial because data is broken down into
bits, each sent one-by-one on a single wire: H = 0 1 0 0 1 0 0 0 = L H L L H L L L =
HIGH LOW
Toggle a pin to send data, just like blinking an LED Only a single data wire is needed to send data. One other to receive.
Arduino Mini
aka. Arduino Stamp If you dont talk with a computer, the USB-to-serial functionality is superuous.
Arduino to Computer
Laptop
TX USB
Arduino board
RX
Arduino programmer
-OR-
RX
USB to serial
chip
TX
Arduino microcontroller
Processing sketch
-OR-
Java program
-OR...
Also, USB is a host/peripheral protocol. Being a USB host means needing a lot of processing power and software, not something for a tiny 8kB microcontroller. It can be a peripheral. In fact, there is an open project called AVR-USB that allows AVR chips like used in Arduino to be proper USB peripherals. See: http://www.obdev.at/products/avrusb/
C/C++, Perl, PHP, Java, Max/MSP, Pick your favorite one, write some code for
Arduino to control
If interested, I can give details on just about every language above.
Another Example
serial_read_blink
Type in a
number 1-9 and LED blinks that number number typed into usable number
Converts
For example...
PWM
Output voltage is averaged from on vs. off time
output_voltage = (on_time / off_time) * max_voltage
5 volts
3.75 Volts
0 volts 75% 25% 75% 25% 75% 25%
5 volts
2.5 Volts
0 volts 50% 50% 50% 50% 50% 50%
1.0 Volts
PWM
Used everywhere
Three characteristics of
PWM signals
Pulse width range (min/max) Pulse period (= 1/pulses per second) Voltage levels (0-5V, for instance)
height
width
period
Servomotors
Can be positioned
from 0-180
circuitry & gearing takes care of the hard stuff PWM 5V interface
More specically, these are R/C hobby servos used by remote control enthusiasts In general, servomotor is a motor with an inherent feedback mechanism that allows you to send position commands to it without requiring you to do the position reading.
Any time you need controlled, repeatable Can turn rotation into linear movement
with clever mechanical levers
http://www.technologyreview.com/read_article.aspx?id=17639&ch=infotech
Servos
Come in all sizes from super-tiny to drive-your-car But all have the
same 3-wire interface 9g
157g
http://rctoys.com/ http://hobbypeople.net/
http://www.sierragiant.com/prod28.html
Servos
180
PWM freq is 50 Hz (i.e. every 20 millisecs) Pulse width ranges from 1 to 2 millisecs 1 millisec = full anti-clockwise position 2 millisec = full clockwise position
Servo Movement
0 degrees 45 degrees 180 degrees
high
high
high
To position, send a pulse train from 1 to 2 ms To hold a position, pulses must repeat Takes time to rotate, so pulse too fast & it wont move
Servo Movement
0 degrees 90 degrees 180 degrees
1000 microsecs
1500 microsecs
2000 microsecs
Moving a Servo
Move the servo across its full range of motion
servo_move_simple
Uses
delayMicroseconds()
Sketch is in the handout Created a custom function to handle making servo pulses New function delayMicroseconds(). Like delay(), but !sec instead of msec. (and actually, just delaying 20 msec is kinda wrong. should be: 20 - (pulsewidth/1000)
Serial-controlled Servo
servo_serial_simple
Controlling Arduino
Any program on the computer, not just the
Arduino software, can control the Arduino board command-line can do it:
Unix is rad.
Take a Break
If a servo is not being constantly told what to do, it goes slack and doesnt lift/push/pull
Update the servo when needed, not just when called at the right time
Multiple Servos
The updateServo() technique can be
extended to many servos pins you have though
Only limit really is number of digital output It starts getting tricky after about 8 servos
Arduino PWM
why all the software, doesnt Arduino have PWM?
Arduino has built-in PWM On pins 9,10,11 Use analogWrite(pin,value) It operates at a high, xed frequency (thus not usable for servos) But great for LEDs and motors Uses built-in PWM circuits of the ATmega8 chip - no software needed
The PWM speed used for analogWrite() is set to 30 kHz currently. When programming AVRs, PWM speed can be set to just about any value.
R,G,B LEDs
Three PWM outputs and three primary colors. Just screams to be made, doesnt it?
Arduino board pin 11 pin 10 pin 9 gnd 220 (red,red,brown) or 330 (orange,orange,brown)
red
green blue
Put back on the ProtoShield for this. Use either the 220 or 330 ohm resistors in your kit, if you dont have enough of one or the other I have lots more 220 if you need them
R,G,B LEDs
Cut leads of resistors and LEDs to make for a more compact circuit. Also, less likely to short against itself.
Mood Light
Diffuser made from piece of plastic scratched with sandpaper
Serial-controlled RGB
serial_rgb_led
g50
This sketch is located in the handout. Color command is two parts: colorCode and colorValue colorCode is a character, r, g, or b. colorValue is a number between 0-255. Sketch shows rudimentary character string processing in Arduino
Pay no attention to the pointer symbol (*) Must be careful about calling readSerialString() too often or youll read partial strings
Going Further
R,G,B LEDS You can pretty easily
your computer replicate the Ambient Orb ($150) functionality
Glowing Orb
Going Further
Servos Mount servo on a video camera
computer-controlled camera motion
Make a robot (a little obvious) Lots of spooky uses theyre the core of movie animatronics
Im not too mechanical, so I dont have many concrete and still working examples of servo use.
Going Further
Serial communications Not just for computer-to-Arduino
communications
Many other devices speak serial Older keyboards & mice speak are serial
(good for sensors!)
Serial Examples
to Wi-Fi
to Ethernet
Lantronix Wi-Port and Lantronix Xport http://lantronix.com/ Seetron Serial Graphic display and Mini SSC http://www.seetron.com/slcds.htm
Serial Examples
to Roomba
Hacking Roomba, out in a few weeks, by me. ;-) http://hackingroomba.com/
Next Week
All about piezos Building a melody player Using piezos as pressure & knock sensors Using Processing with Arduino Stand-alone Arduino
Tod E. Kurt
tod@todbot.com