Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started.

Similar presentations


Presentation on theme: "Www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started."— Presentation transcript:

1 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started

2 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Setting up RedBoard

3 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Connecting the RedBoard Connecting the CodeBender software to the Board 1.Connect your RedBoard to your Computer a.Use the USB cable provided in SIK kit to connect the RedBoard to one of your computer’s USB inputs. In codebender... b.Select the Arduino Uno or Sparkfun Redboard board c.Select a COM port It is usually the highest port number. Speed should be 9600 d.Speed should be 9600 b c d

4 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Agenda 9:45 AM10:00 AM The Interface – navigating to and registering on the CodeBender website in Chrome or Firefox. 10:00 AM10:10 AM Setup Board – Installing FTDI drivers (for those Advisors that brought their own laptops) 10:10 AM10:15 AM Connecting the CodeBender software to the Board 10:15 AM10:25 AM The Objects 10:25 AM10:35 AM The Code 10:35 AM10:40 AM Syntax is important 10:40 AM10:50 AM Putting the code into action 10:50 AM11:00 AM Simple LED circuit 11:00 AM11:15 AM Sensing using analog inputs 11:15 AM11:35 AM Using the Servo 11:35 AM11:45 AM Questions/Answers

5 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) MESA Kit ●SparkFun RedBoard (Arduino Uno) ●Multiple Colored LEDs ●RGB LED ●Temp Sensor ●Photo Sensor (LDR) ●Resistors (330 Ohm / 10k Ohm) ●Variable Resistor (Trim Pot) ●BreadBoard ●Push buttons ●Battery Holder ●H-Bridge IC ●Servo Motor ●Motors w/ Gearbox ●Battery Pack ●USB Cable Order At: http://sparkfun.com/MESA2015

6 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting started with the RedBoard

7 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Solderless Breadboard Rows of 5 holes are connected internally by a metal clip. “Ditch” divides the two halves. Vertical “rails” on the side are connected vertically.

8 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Objects we will be using Today

9 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Objects Continued

10 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) What is Arduino? Started circa 2005 Small, low-cost micro-controller (mini-computer). “Arduino” describes both the hardware (board) and the programming language / environment. Terms: Sketch - A sketch is the name that Arduino uses for a program. It's the unit of code that is uploaded to and run on an Arduino board.

11 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) About the Arduino code

12 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) General notes Each sketch must have (Bare Minimum): //any text you see with double slash (//) in front of it is a comment and is only for you //the computer ignores that text. It's called a comment. void setup() { //setup runs once at the beginning of the sketch when the board is powered up! } void loop() { //loop runs over and over again really fast until you turn the power off or //you upload other code }

13 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Syntax Syntax is important Everything is as intended; it is intentional to have all CAPS or Camel case. The capitalization, semi colon, braces are required. There are specific commands that are reserved that Arduino has in it. There is a reference sheet to basic commands available on the nmmesa.org website. At the bottom of the codebender window, the error bar displays our error.

14 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Syntax Demo To turn a pin ON or OFF, we use the digitalWrite([pin], [HIGH\LOW]) command: void loop() { digitalWrite(13, HIGH);//(on) digitalWrite(13, LOW); //(off) } void loop() { digitalWrite(13, High)(on) digitalWrite(13, Low); // (off) }

15 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) More general notes All pins are generic. So, you must “configure” a pin before using it. void setup() { pinMode(13, OUTPUT); } void loop() { }

16 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Putting Code Into Action

17 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Saving Your Code Saving your Codebender Sketch. With the sketch open that you want to save… 1.Click on the sketch name 2.Type in a new descriptive name 3.Press the Enter key on the keyboard 4.Click the Save button 5.Verify by going back to the codebender main page. You saved sketch should be visible in the sketch list. Make sketch private. To make your sketch private, Double-click the Icon to the left of the sketch name You can only make one sketch private per user account.

18 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) LED Experiment Simple LED circuit Circuit, has the base word of circle. Our circle is; from power on the board to pin 13 through LED back to ground on the board. Arduino PINs are limited to 40 mA (Milliamps) The LED will pop if you put it into 5v and ground it will burn out the LED. The pins have a current limiter so they are safe. Short leg needs to go to ground 2 1 3 4 Wiring diagram and instructions for Simple LED circuit 1.Plug a LED into the Breadboard with the long pin in Row 1 and the short pin on the LED in Row 2 2.Connect Negative (-) on the Breadboard to GND on the RedBoard 3.Connect A1 on the Breadboard to PIN 13 on the Redboard. 4.Connect A2 on the Breadboard to Negative (-) on the Breadboard

19 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) And more general notes To turn a pin ON but “dim”, we use the analogWrite([pin], [0-255]) command: void loop() { analogWrite(9, 50); } Note: Only pins that have the ~ next to them can do this. Arduino does this using a technique called PWM.

20 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Dimmer Experiment

21 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Dimmer Experiment Continued Upload the Code 1.Go to https://codebender.cc/sketch:142450 https://codebender.cc/sketch:142450 2.Click the Run on Arduino button. View the Trimpot’s output in the Serial Monitor section… 3.Make sure the baud rate is 9600 (data rate bits per second). This will establish what speed it will be. 4.Click Connect button. 5.You will be able to see the output from the Trimpot on the screen. 6.Adjust the Trimpot by turning the knob and look at the results in the serial monitor. 7.Click Disconnect button when done (was the Connect button). 3 4 Read the code, what is it doing? void setup() { /* Initialize the serial communication at 9600 bits per second. This allows you to send or receive sensor values and other data between the Arduino and another device (like your computer). 9600 is the standard speed most devices use.*/ Serial.begin(9600); } void loop() { /* create an integer variable (int) called val make val equal to the sensor reading on pin A0 you should get a sensor reading between 0 and 1023*/ int val = analogRead(A0); //print the string "Val = " over the serial port Serial.print("Val = "); //print the variable val and end the line with a carriage return Serial.println(val); //wait a bit delay(100); }

22 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) A little background on servo motors 3 wires -- black, red, white. Signal is compared to a potentiometer that is connected to the output shaft. Signal is a 50 Hz PWM (20 mS per Period)

23 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Using the Servo

24 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Servo Continued Finally, In the loop, we have the Servo going from 170 degrees to 10 degrees over and over again. The delay() commands tell the Arduino to do nothing for 500 milliseconds so the servo horn has time to move. Read the code, what is it doing? //include the Servo library in your sketch #include //create a servo object called myServo Servo myServo; void setup() { //attach myServo to pin 9 myServo.attach(9); //write the angle of 90 to myServo once myServo.write(90); } void loop() { myServo.write(170); delay(500); myServo.write(10); delay(500); ; } The first line includes the Servo.h library into the sketch. This provides access to new commands and functions to control special devices - like a servo motor. Notice that this is one of the few instances where there is no semicolon at the end of the line. The first line includes the Servo.h library into the sketch. This provides access to new commands and functions to control special devices - like a servo motor. Notice that this is one of the few instances where there is no semicolon at the end of the line. Next, Servo myServo - this creates an object that is called myServo. An object is similar to a variable that has extra properties and commands. The two commands that we care about are: attach () and. write (). The myServo.attach(9) is similar to a setup command. It links the myServo object to pin 9 on the Arduino. The myServo.write(90) is the command that tells the servo motor what angle to rotate to. The range of motion for a servo is roughly 180 degrees. You can use any value from 0 to 180 with this command. The placement in setup sets our starting angle at 90 degrees.

25 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) To set the angle... servo1.write(90); delay(1000); servo1.write(0); delay(1000); servo1.write(180);

26 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Teaching and Learning ***The Big 6*** Program Flow and Control Inputs and Outputs Data, Variables, Math, and Numbers Digital vs. Analog Communication Libraries and Object Oriented Programming (OOP)

27 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) learn.sparkfun.com/mesa2015

28 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) NM MESA website All information and resources for the 2016 MESA day will be updated on the website

29 www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Questions / Contact Your Regional Coordinator Rick Cole NNmmesa.org Thanks!!!


Download ppt "Www.nmmesa.org Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started."

Similar presentations


Ads by Google