Changes

Jump to navigation Jump to search

Workshop: Introduction to Microcontrollers with Arduino

835 bytes added, 14:43, 20 February 2019
final first pass on major overhaul
== Intro ==
 
This Workshop will introduce you to the world of microcontrollers: tiny computers that do a specific task. Effectively, what you'll be doing today is interfacing hardware and software together: you will write code which will interact with the outside world!
The Arduino IDE is a software suite which packages up all the functionality of programming microcontrollers in a higher level language (in this case, the Arduino language!). Its underlying compiler inherits from the C++ language (and by extension, C), so to those who have used C++, C, or any language with a C-like syntax, this will look very familiar.
Each Activity in this Workshop will have a Hardware component and a Software component. It will be important to remember this, to begin to compartmentalize each task you must complete! Ultimately, this workshop will consist of two main objectives: how to control digital pins (both as inputs and outputs) and how to control an analog pins (both as inputs and 'outputs').
== Hardware Setup ==
 
You’ll be using a microcontroller today called the Teensy 3.2. As its name suggests, it’s pretty small! As such, the silkscreen (the text that appears on the faces of the printed circuit board, usually indicating things like pin labels) is minimal. In order to actually utilize the Teensy, you’ll need its [https://www.pjrc.com/teensy/card7a_rev1.pdf pinout]:
=== Set up the Teensy on the breadboard ===
 (add pictureand description)
== Software setup ==
 
You're going to need two pieces of software to work with the microcontroller.
In order to get the Arduino IDE up and running with your board - regardless of which board it happens to be - you must answer for it three questions: the which, the where, and the how.
# Which board are you using?\
#* Navigate to ''Tools → Board'' and select ''Teensy 3.2 / 3.1''
# Where is the board connected?
#* Navigate to ''Tools → Programmer'' and select ''AVRISP mkII''.
== Activities ==
Each Activity in this Workshop will have a Hardware component and a Software component. It will be important to remember this, to begin to compartmentalize each task you must complete! Ultimately, this workshop will consist of two main objectives: how to control digital pins (both as inputs and outputs) and how to control an analog pins (both as inputs and 'outputs').
=== Activity 01: Digital output (aka 'Hello World' for hardware) ===This In this activity sees , you using will use a pin on the microcontroller to blink an LED.
# Navigate to ''File → Examples → 01.Basics → Blink''.<br>The code which appears should look something like this:<br>[[File:code for teensy.png]]
'''NOTE: There is a button on the Teensy. This button does not do what you think it does. This button is a program button, meaning that when you press it, the device takes the most-recently compiled code and sticks it in its program memory. This is not a reset button!'''
=== Activity 02: Digital Input (aka a button) === 1.Navigate to File → Examples → 02.Digital → Button. 2.Connect a button to D8. 3.In the code, change the button pin to D8, and the LED pin to D9. 3a.pinMode(buttonPinthis activity, INPUT_PULLUP)4.Compile and upload your code 5.Modify the code so that when you press the button he LED turns on, and when you are not pressing the will use a button, the LED turns off.  == Analog input ==  1.Navigate to File → Examples → 03.Analog → AnalogInput. 2.Change the LED pin to D9. Additionally, change the analog input pin to A5. 3.Compile and Program, and turn the pot to change the speed at which the control an LED blinks! 4.debug as necessary  5. In the setup function, add the following line:Serial- all through software.begin(9600) 6.This initializes the Serial communications protocol. Now, in loop, after you’ve read the value of the analog pin, add the following line: Serial.println(sensorValue);
7# Navigate to ''File → Examples → 02.Compile and program Digital → Button''.# Connect a button to D2.# In the code, change the button pin to D2, and once it’s successful, open the Serial Monitor with or CTRL+SHIFT+MLED pin to D9. You should see values printing out on this screen#: <code>pinMode(buttonPin, INPUT_PULLUP); turn </code># Compile and Program.# Modify the potentiometercode so that when you press the button the LED turns on, and when you are not pressing the value will change! This number is what is being used as the delay time (in ms) in button, the codeLED turns off.
=== Activity 03: Analog Input (aka knobtwisting) ===
In this activity, you will use a knob to control the blinking speed of an LED - all through software.
== # Navigate to ''File → Examples → 03.Analog output ==→ AnalogInput''.# Change the LED pin to D9. Additionally, change the analog input pin to A5.# Compile and Program, and turn the pot to change the speed at which the LED blinks!
There isn't a way (yet) to see ''exactly'' how long each of those delays is happening for. Let's change that. You're going to add some '''debugging''' functionality to your code - by incorporating the '''Serial Monitor'''.
1# In the setup function, add the following line:#: <code>Serial.Navigate begin(9600);</code> <br> This initializes the Serial communications protocol.# Now, in loop, after you’ve read the value of the analog pin, add the following line:#: <code>Serial.println(sensorValue);</code> <br> (The method name reads as “print line”.)# Compile and program the code, and once it’s successful, open the Serial Monitor with CTRL+SHIFT+M or by going to File ''Tools Examples → 03Serial Monitor''.Analog → FadingYou should see values printing out on this screen; turn the potentiometer, and the value will change! This number is what is being used as the delay time (in ms) in the code.
2'''ERROR: OH NO I CAN’T OPEN THE SERIAL MONITOR / OH NO I CAN’T PROGRAM ANYMORE.Compile and program ''' The Serial Monitor uses the codesame communication port as the Programmer - you can’t use both at the same time. your LED’s brightness should be fading up and downProgram the device, then open the Serial Monitor. If it’s still not working, check to make sure the IDE knows where the board is connected.
=== Activity 04: Analog 'Output' (aka breathe) ===
In this activity, you will program an LED to fade in and out. There is no input control.
== # Navigate to ''File → Examples → 03.Analog final ==→ Fading''. # Compile and Program the code. your LED’s brightness should be fading up and down!
1.Create === Activity 05: CHALLENGE ===Using all your newly-acquired hardware and software prowess, create a project - call it Fade Control - that device which directly controls the brightness of an LEDwith a knob. It has two modes: Automatic and Manual. In Automatic mode, it will fade the brightness of the LED up and down (just like Activity 04). In Manual mode, the position of the potentiometer determines the brightness of the LED. The mode can be switched by pressing a button

Navigation menu