Difference between revisions of "EDI Bootcamp"
NickMarchuk (talk | contribs) (New page: Welcome to the Mechatronics portion of Bootcamp! Make sure your kit has the following items: * Arduino Uno ([http://www.sparkfun.com/products/9950]) * USB A to B cable (B has a large, squ...) |
NickMarchuk (talk | contribs) |
||
Line 24: | Line 24: | ||
A nice Arduino tutorial is at [http://www.ladyada.net/learn/arduino/index.html] (uses a slightly older version of the Arduino board, but otherwise is fine) |
A nice Arduino tutorial is at [http://www.ladyada.net/learn/arduino/index.html] (uses a slightly older version of the Arduino board, but otherwise is fine) |
||
The [[Media:NU32v2_stripchart.zip | NU32v2 Stripchart plotting tool]] is useful for plotting data on your computer. |
|||
Here is the code on the demo Arduino : |
|||
<pre> |
|||
/* |
|||
Example Arduino code for NU EDI Bootcamp 2011 |
|||
Pins used: |
|||
0 - serial rx, hardwired on the board, so don't use it for anything else |
|||
1 - serial tx, hardwired on the board, so don't use it for anything else |
|||
2 - button |
|||
5 - pwm for blue led |
|||
6 - pwm for yellow led |
|||
7 - vibration motor |
|||
8 - speaker, for use with tone() function -> this will mess up |
|||
pwm on pins 3 and 11 |
|||
9 - pwm for the rc servo |
|||
A0 - accelerometer X |
|||
A1 - accelerometer Y |
|||
A2 - accelerometer Z |
|||
A3 - flex sensor |
|||
A4 - pressure sensor |
|||
*/ |
|||
// include files here |
|||
#include "pitches.h" // so that we can play notes, not used here |
|||
#include <Servo.h> // to control the rc servo motor |
|||
// define global variables here |
|||
Servo myservo; |
|||
int X, Y, Z, flex, pressure; |
|||
// setup() runs once, |
|||
// use it to initialize functions and variables |
|||
void setup() { |
|||
Serial.begin(115200); // setup the serial port to talk at 115200 baud |
|||
myservo.attach(9); |
|||
pinMode(2, INPUT); // setup pin 2 as an input for the switch |
|||
pinMode(7, OUTPUT); // setup pin 7 as an output for the vibration motor |
|||
} |
|||
// loop() runs forever, |
|||
// put your code in here |
|||
void loop() { |
|||
X = analogRead(A0); // read the value, returns 0-1023 for 0-5V |
|||
Y = analogRead(A1); |
|||
Z = analogRead(A2); |
|||
flex = analogRead(A3); |
|||
pressure = analogRead(A4); |
|||
if (digitalRead(2)) { |
|||
int pos = map(Y, 0, 1023, 0, 180); // change the full range of the sensor |
|||
// to the full range of the servo |
|||
myservo.write(pos); // pos is the angle of the servo, 0-180 degree |
|||
int freq = map(Z, 0, 1023, 31, 5000); |
|||
tone(8, freq); // 8 is the pin, freq is the frequency to play |
|||
int blue = map(flex, 0, 1023, 0, 255); |
|||
analogWrite(5, blue); |
|||
int yellow = map(pressure, 0, 1023, 0, 255); |
|||
analogWrite(6, yellow); |
|||
digitalWrite(7, HIGH); // turn on the vibration motor |
|||
} |
|||
else { |
|||
noTone(8); // turn off the sound |
|||
digitalWrite(7, LOW); // turn off the vibration motor |
|||
// if the button is not pushed, send the analong values to the computer |
|||
// divide by 2 because Stripchart can only show numbers 0-512 |
|||
Serial.print(X/2); |
|||
Serial.print(" "); |
|||
Serial.print(Y/2); |
|||
Serial.print(" "); |
|||
Serial.print(Z/2); |
|||
Serial.print(" "); |
|||
Serial.print(flex/2); |
|||
Serial.print(" "); |
|||
Serial.println(pressure/2); |
|||
} |
|||
delay(20); // wait this many ms before going again |
|||
} |
|||
</pre> |
|||
The functions you can use in your code are listed at [http://arduino.cc/en/Reference/HomePage] |
Revision as of 14:15, 31 August 2011
Welcome to the Mechatronics portion of Bootcamp!
Make sure your kit has the following items:
- Arduino Uno ([1])
- USB A to B cable (B has a large, square end)
- 850mAh LiPo ([2])
- Sparkfun LiPo charger and 5V boost board ([3])
- USB A to micro cable (micro has a tiny end)
- RC servo motor
- 3 axis accelerometer ([4])
- 8ohm speaker ([5])
- Pushbutton
- Flex sensor ([6])
- Force sensitive resistor ([7])
- Breadboard
Also available are 5mm super bight LEDs in blue, red, green, yellow and white, IR LEDs, IR sensitive phototransistors, red sensitive phototransistors, small RC servo motors, and tiny vibration motors.
The Mechatronics Lab has 6 workstations, each with power supply, multimeter, function generator, oscilloscope, soldering iron, wire, wire strippers and cutters, solder, and a PC with the Arduino software installed. The white cabinets contain resistors, capacitors, potentiometers, and a variety of useful ICs.
You can learn more about the Arduino on the website [8]
You can download the Arduino website for PC, MAC or Linux at [9]
A nice Arduino tutorial is at [10] (uses a slightly older version of the Arduino board, but otherwise is fine)
The NU32v2 Stripchart plotting tool is useful for plotting data on your computer.
Here is the code on the demo Arduino :
/* Example Arduino code for NU EDI Bootcamp 2011 Pins used: 0 - serial rx, hardwired on the board, so don't use it for anything else 1 - serial tx, hardwired on the board, so don't use it for anything else 2 - button 5 - pwm for blue led 6 - pwm for yellow led 7 - vibration motor 8 - speaker, for use with tone() function -> this will mess up pwm on pins 3 and 11 9 - pwm for the rc servo A0 - accelerometer X A1 - accelerometer Y A2 - accelerometer Z A3 - flex sensor A4 - pressure sensor */ // include files here #include "pitches.h" // so that we can play notes, not used here #include <Servo.h> // to control the rc servo motor // define global variables here Servo myservo; int X, Y, Z, flex, pressure; // setup() runs once, // use it to initialize functions and variables void setup() { Serial.begin(115200); // setup the serial port to talk at 115200 baud myservo.attach(9); pinMode(2, INPUT); // setup pin 2 as an input for the switch pinMode(7, OUTPUT); // setup pin 7 as an output for the vibration motor } // loop() runs forever, // put your code in here void loop() { X = analogRead(A0); // read the value, returns 0-1023 for 0-5V Y = analogRead(A1); Z = analogRead(A2); flex = analogRead(A3); pressure = analogRead(A4); if (digitalRead(2)) { int pos = map(Y, 0, 1023, 0, 180); // change the full range of the sensor // to the full range of the servo myservo.write(pos); // pos is the angle of the servo, 0-180 degree int freq = map(Z, 0, 1023, 31, 5000); tone(8, freq); // 8 is the pin, freq is the frequency to play int blue = map(flex, 0, 1023, 0, 255); analogWrite(5, blue); int yellow = map(pressure, 0, 1023, 0, 255); analogWrite(6, yellow); digitalWrite(7, HIGH); // turn on the vibration motor } else { noTone(8); // turn off the sound digitalWrite(7, LOW); // turn off the vibration motor // if the button is not pushed, send the analong values to the computer // divide by 2 because Stripchart can only show numbers 0-512 Serial.print(X/2); Serial.print(" "); Serial.print(Y/2); Serial.print(" "); Serial.print(Z/2); Serial.print(" "); Serial.print(flex/2); Serial.print(" "); Serial.println(pressure/2); } delay(20); // wait this many ms before going again }
The functions you can use in your code are listed at [11]