Difference between revisions of "EDI Bootcamp"
From Mech
Jump to navigationJump to searchNickMarchuk (talk | contribs)  | 
				NickMarchuk (talk | contribs)   (Replaced content with "Welcome to the Mechatronics portion of Bootcamp!  <video width="400px" controls>   <source src="solder.mp4" type="video/mp4">   Your browser does not support HTML5 video. ...")  | 
				||
| Line 1: | Line 1: | ||
Welcome to the Mechatronics portion of Bootcamp!  | 
  Welcome to the Mechatronics portion of Bootcamp!  | 
||
<video width="400px" controls>  | 
|||
Make sure your kit has the following items:  | 
  |||
  <source src="solder.mp4" type="video/mp4">  | 
|||
* Arduino Uno ([http://www.sparkfun.com/products/9950])  | 
  |||
  Your browser does not support HTML5 video.  | 
|||
* USB A to B cable (B has a large, square end)  | 
  |||
</video>  | 
|||
* 850mAh LiPo ([http://www.sparkfun.com/products/10718])  | 
  |||
* Sparkfun LiPo charger and 5V boost board ([http://www.sparkfun.com/products/10300])  | 
  |||
* USB A to micro cable (micro has a tiny end)  | 
  |||
* RC servo motor  | 
  |||
* 3 axis accelerometer ([http://www.pololu.com/catalog/product/1246])  | 
  |||
* 8ohm speaker ([http://www.sparkfun.com/products/10722])  | 
  |||
* Pushbutton  | 
  |||
* Flex sensor ([http://www.sparkfun.com/products/10264])  | 
  |||
* Force sensitive resistor ([http://www.sparkfun.com/products/9375])  | 
  |||
* 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 [http://www.arduino.cc/]  | 
  |||
You can download the Arduino website for PC, MAC or Linux at [http://arduino.cc/en/Main/Software]  | 
  |||
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]  | 
  |||
You can power your Arduino off USB power while testing, or using the 3.7V LiPo battery with the LiPo Charger/Booster board to go mobile. From the Boost board, connect GND to the Arduino ground, and VCC to the Arduino 5V.  | 
  |||
'''WARNING 1''' Do not connect the USB and battery to the Arduino at the same time  | 
  |||
'''WANRING 2''' Do not pull the battery out of the charging board by the wires, try to pull it out by the white plastic connector  | 
  |||
Revision as of 10:35, 5 September 2014
Welcome to the Mechatronics portion of Bootcamp!
<video width="400px" controls>
<source src="solder.mp4" type="video/mp4"> Your browser does not support HTML5 video.
</video>