Welcome to Arduino A MICROCONTROLLER Robotics at University

Welcome to Arduino A MICROCONTROLLER

Robotics at University


Before we start, handling the boards… • Once they are powered up please don’t touch the boards • Our fingers can create a short circuit on the board and ZAP it

Make sure we are good to go…(from last lesson) • Standard install, nothing complicated • We need to tell the computer software what kind of Arduino we have: • <Tools>, <Board>, <Arduino UNO> • We need to tell the computer software where the Arduino is plugged in: • <Tools>, <Port>, <comxArduino> for Windows OS • <Tools>, <Serial Port>, <dev/tty. USB 0> for Linux OS • (most likely as the UNO is the standard board, otherwise specify as required) • Good to go!

‘Hello’ – of in our case Mr Blinky • We are going to plug our Arduino into the computer. • Then we create or load a sketch (program) and then upload it to the Arduino. • A lot of software programs use a hello command as a test when you first start. • The programming language we use with Arduino is called C • In our case we are going to do a blink test.

Blink test • We load an example sketch: • <File>, <Examples>, <01. Basics>, <Blink> • The sketch (program) is now loaded into the window…. • It will make the LED blink (Light Emitting Diode) when we upload it • We are looking at….

IDE • Integrated Development Environment, has 3 main parts: Tools Sketch Window Message Window Board and Serial connection details

IDE • Screen dump this (CTRL + PRTSCR) or use the snipping tool • (For MS Windows: click on <start>, in the <run> window type ‘snipping’ and select the app) • Print the IDE out TWICE (one blank, one with the blink sketch) • Stick both in your journal with room to label them • Label it with the main IDE window functions

Journal entry: • Will look something like… • Use one to label the IDE • Use the second (with blink) to label the sketch (later)


‘ello, wot ‘ave we here…. • */ is a comments section • // are comments (the sign of good coding practice!) • Void setup is run once at the start to set up the environment • Void Loop is where the sketch program is mainly written and does all the work

What does it all mean? • Arduino is a 5 V system • pin. Mode sets a particular pin to be either an input or an output • HIGH means ‘give all she's got Scotty’ = 5 V • LOW means turn ‘off’ = 0 V • Delay means to wait for ‘x’ milli seconds • digital. Write is a name of something

Programming Language (jargon) • pin. Mode is an Output in this ‘blink’ example (rather than an input) • HIGH and LOW are arguments. They are passed to a function when it is called. • Delay is a singular argument. We can split arguments up with comma’s • digital. Write is a name of a built-in function, it needs to know where to pass the information to when it is called. We put this in parentheses {} to define what is being called. • The parentheses and the code in between them are know as a block of code • We then compile our code and upload it to the Arduino

Compile and Upload Compile/Error check Upload New Open Save Open Serial Monitor Add this to the first journal picture

IDE labels • • • To the second IDE picture in your journal add: Void loop section Void setup section Note a comments section (*/…. /*) Note a comment (//) Note an Output (or input) Note an argument (high/low) Note a singular argument (delay) Note a name (digitalwrite)

So…

Does it work? • Check where the pins are plugged into • Turn the LED 180 o • The long leg is positive

So lets mix it up • What might happen when you change the delay times? • Try it • Change the delay time and upload it to the Arduino • Observe what happens to the blink rates

Another blink test… • Time to write your own code from the beginning, open the Arduino console:

Enter…. //My 1 st Project – LED flasher int led. Pin = 9; Voide setup() { pin. Mode (led. Pin, OUTPUT); } Void loop() { NOTE: The sketch/program is CASe s. NESitive and S P A C E sensitive digital. Write(led. Pin, HIGH); delay(1000); digital. Write(led. Pin, LOW); delay(1000); } That is the key point of this exercise

Take the LED and…. • Problem – you can burn out the LED • So add a 100 Ω resistor… • Connect and insert it into…. • Pin 9 • GND

This leads to: • Adding a breadboard (note diagram uses Pin 9 like our code) • More on breadboards in the next lesson.

Fritzing diagram • http: //fritzing. org/home/ • Used this last lesson • Create the diagram • Save the diagram with a name such as LED project 1, LED project 2 • Print the 2 diagrams • Add the diagrams to your journal

This way was can add more LED’s… • The next project: • http: //arduino. sundh. com/
- Slides: 25