Changes

Jump to navigation Jump to search

Workshop: Introduction to Microcontrollers with Arduino

5,356 bytes added, 00:54, 5 March 2020
Hardware Setup
{{Workshop header}}
== Intro==This certification is for Workshop will introduce you to the use 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 micro-controller set. == outside world!
In order to accomplish this, you'''This workshop will consist of two main objectivesre going to be using Arduino. Arduino can refer to many things (a company, a software suite, a board, a programming language); how in general, Arduino is an ecosystem in which you can conveniently program microcontrollers to control Digital output interact with the outside world. It’s the easiest (as well as most ubiquitous) way to connect hardware with software, and inputs and how the easiest way to control an analog output and input''' get into embedded programming.
The Arduino IDE is a software suite which packages up all the functionality of programming microcontrollers in a higher level language (basic outlinein 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.
1.First, download and install the Arduino IDE into your operating system of choice.
Download and install Teensyduino (as of ==Hardware Setup==You’ll be using a microcontroller today called the writing of this labTeensy 4.0. As its name suggests, version 1.41)it’s pretty small! As such, which adds Teensy support to the Arduino IDE. Just follow silkscreen (the text that appears on the prompts; you don’t need to install all faces of the librariesprinted circuit board, but if you ever want usually indicating things like pin labels) is minimal. In order to work with Teensies in actually utilize the futureTeensy, it’s worth taking the time to install them nowyou’ll need its [https://www.pjrc.com/teensy/card7a_rev1.pdf pinout]:
2.Then double check that you are using the right board by going to Tools then Board and selecting Teensy 3.2 / 3.1, then go to Tools → Port and depending on your operating system go to Windows: select COMX, where X is the largest number (it should also say Teensy 3.2) or OSX[[File: select /dev/cu.usbmodemXXXXXX, where XXXXXX is some numberTeensy_3. This may not show up with Teensy2_3.(You can see that neither of these operating systems handle hardware communication ports very elegantly1_pinout.)png]]
===Set up the default programmer for teensy Teensy on the breadboard===[[File:Breadboard and Teensy.jpg|thumb|Note that in this example the green wire is AVRISP mkIIconnected to 5V. To use ]][[File:Wired Teensy and Breadboard.jpg|thumb|This Teensy and breadboard are ready to go!]]If it go to Programmer and select AVRISP mkIIhasn’t already been done for you, carefully insert the Teensy onto the far edge of the breadboard. Make sure the Teensy straddle’s the gap, so that each row of pins sits on either half (top or bottom).
If the horizontal power rails on your breadboard are separated (like the breadboard in the picture). We will need to use small wires to connect both sides. This extends the horizontal rails to span the entire length of the breadboard.
== Digital output ==
1Connect the top upper rail and the top lower rail. create Similarly, connect the top lower rail to the bottom lower rail. Finally, connect the top-most wire to power (3.3V) and connect the wire below power to ground (GND). If all is correct we now have both a new file ground and power rail for each half of the breadboard. ==Software setup==You're going to need two pieces of software to work with the microcontroller.
[[File:code for teensy.png]]===Download and install===
#Download and install the [https://www.arduino.cc/en/main/software Arduino IDE] on your operating system of choice. ''(Note: if you're using Windows, use the installer, not the app!)''
#Download and install [https://www.pjrc.com/teensy/td_download.html Teensyduino], which adds Teensy support to the Arduino IDE. Just follow the prompts; you don’t need to install all the libraries, but if you ever want to work with Teensies in the future, it’s worth taking the time to install them now.
2. then upload ===The which, the where, and the code how===In order to get the Arduino IDE up and running with your board using the button or CTRL+U. This is actually a compile and program. If - regardless of which board it happens to be - you get any errors, ask must answer for help. Assuming it has programmed correctlythree questions: the which, the where, you should now see and the onboard LED blinking!how.
3#Which board are you using?#*Navigate to ''Tools → Board'' and select ''Teensy 4.Fiddle with 0''#Where is the delay times board connected?#*Navigate to ''Tools → Port'' and reprogram to :#**Windows: select ''COMX'', where ''X'' is the largest number (it should also say Teensy 4.0)#**OSX: select ''/dev/cu.usbmodemXXXXXXXX Serial (Teensy 4.0)'' , where ''XXXXXX'' is some number. This may not show up with Teensy.#**(You can see how that neither of these operating systems handle hardware communication ports very elegantly.)#How are you can affect programming the board? So far, you’ve used the mEDBG device for programming. Teensy won’t work with that - but it will work with the speed of default programmer, the LED blinkingAVRISP mkII.#*Navigate to ''Tools → Programmer'' and select ''AVRISP mkII''.
4.Connect an LED ==Activities==Each Activity in this Workshop will have a Hardware component and a 330Ω resistor (just like in previous labs) Software component. It will be important to D9remember this, and then change to code begin to reference compartmentalize each task you must complete! Ultimately, this new LED’s pinworkshop 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').
5.Compile and Program ===Activity 01: Digital output (aka 'Hello World' for hardware)===In this activity, you will use a pin on the microcontroller to testblink 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]]
#Upload the code to your board using the button or CTRL+U. This is actually a compile and program. If you get any errors, ask for help. Assuming it has programmed correctly, you should now see the onboard LED blinking!
#Fiddle with the delay times and reprogram to see how you can affect the speed of the LED blinking.
#Connect an LED and a 220Ω resistor to D9, and then change to code to reference this new LED’s pin.
#Compile and Program to test.
== Digital Input=='''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!'''
1===Activity 02: Digital Input (aka a button)===In this activity, you will use a button to control an LED - all through software.Navigate Leave the LED and 220Ω resistor connected to File → Examples → 02.Digital → ButtonD9 like in the previous activity.
2#Navigate to ''File → Examples → 02.Digital → Button''.#Connect a button to D8D2.#In the code, change the button pin to D2, and the LED pin to D9.#Make the following change to the code#:<code>pinMode(buttonPin, INPUT_PULLUP);</code>#Compile and Program.#Modify the code so that when you press the button the LED turns on, and when you are not pressing the button, the LED turns off.
3.===Activity 03: Analog Input (aka knobtwisting)===In the codethis activity, change the button pin you will use a knob to D8, and control the blinking speed of an LED pin to D9. 3a.pinMode(buttonPin, INPUT_PULLUP)4- all through software.Compile and upload your code
5#Navigate to ''File → Examples → 03.Modify Analog → AnalogInput''.#Connect a potentiometer to A5.#Change the code so that when you press LED pin to D9. Additionally, change the button he LED turns onanalog input pin to A5.#Compile and Program, and when you are not pressing turn the button, pot to change the speed at which the LED turns off.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'''.
== Analog input ==#In the setup function, add the following line:#:<code>Serial.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 ''Tools → Serial Monitor''. You 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.
'''ERROR: OH NO I CAN’T OPEN THE SERIAL MONITOR / OH NO I CAN’T PROGRAM ANYMORE.''' The Serial Monitor uses the same communication port as the Programmer - you can’t use both at the same time. Program 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.
1.Navigate ===Activity 04: Analog 'Output' (aka breathe)===In this activity, you will program an LED to File → Examples → 03fade in and out.Analog → AnalogInputThere is no input control.
2#Navigate to ''File → Examples → 03.Change the LED pin to D9Analog → Fading''. Additionally, change #Compile and Program the analog input pin to A5code.your LED’s brightness should be fading up and down!
3.Compile ===Activity 05: CHALLENGE===Using all your newly-acquired hardware and Programsoftware prowess, and turn the pot to change the speed at create a device which directly controls the brightness of an LED blinks!with a knob.
4.debug as necessary <br />
5. In the setup function, add the following line:Serial.begin(9600)==Workshop Checklist=='''Learning Objectives'''
6.This initializes By the Serial communications protocol. Now, in loop, after you’ve read the value end of the analog pinthis Workshop, add the following lineyou should understand: Serial.println(sensorValue);
7.Compile and program the code, #What a microcontroller is#How to compile programs for a Teensy#The difference between analog and once it’s successful, open the Serial Monitor with or CTRL+SHIFT+Mdigital inputs/outputs. You should see values printing out on this screen; turn the potentiometer, and the value will change! This number is what is being used as #Using the delay time (in ms) in the code.serial monitor for debugging purposes
'''Measurable Outcomes'''
== Analog output ==By the end of this Workshop, you should be able to:
 1.Navigate to File → Examples → 03.Analog → Fading. 2.Compile and program #Use the code. your LED’s brightness should be fading up Arduino IDE and down. Teensyduino#Make an LED blink (Digital Outputs)#Use a button to control an LED (Digital Inputs)== #Use a potentiometer (Analog final == Outputs)1.Create a project - call it Fade Control - that controls #Change the brightness of an LED. It has two modes: Automatic and Manual. In Automatic mode, it will fade the brightness of the LED up and down (just like Activity 04Analog Inputs). In Manual mode, the position of the potentiometer determines the #Create a device that integrates everything we learned (control an LED's brightness of the LED. The mode can be switched by pressing with a buttonpotentiometer)
47
edits

Navigation menu