Changes

Jump to navigation Jump to search

Workshop: Introduction to Microcontrollers with Arduino

5,362 bytes added, 00:54, 5 March 2020
Hardware Setup
This certification is for the use of the micro-controller set. {{Workshop header}}
==Intro==This workshop Workshop will consist introduce you to the world of two main objectives; how to control Digital output microcontrollers: tiny computers that do a specific task. Effectively, what you'll be doing today is interfacing hardware and inputs and how to control an analog output and input software together: you will write code which will interact with the outside world!
In order to accomplish this, you're going to be using Arduino. Arduino can refer to many things (basic outlinea company, a software suite, a board, a programming language); in general, Arduino is an ecosystem in which you can conveniently program microcontrollers to interact with the outside world. It’s the easiest (as well as most ubiquitous) way to connect hardware with software, and the easiest way to get into embedded programming.
1.First, download and install the The Arduino IDE (as of is a software suite which packages up all the writing functionality of programming microcontrollers in a higher level language (in this labcase, version 1the Arduino language!).85Its underlying compiler inherits from the C++ language (and by extension, C) into your operating system of choice, so to those who have used C++, C, or any language with a C-like syntax, this will look very familiar.
Download and install Teensyduino (as of the writing of this lab, version 1.41), 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 double check that you are ==Hardware Setup==You’ll be using a microcontroller today called the right board by going to Tools then Board and selecting Teensy 34.2 / 30.1As its name suggests, then go to Tools → Port and depending it’s pretty small! As such, the silkscreen (the text that appears on your operating system go to Windows: select COMXthe faces of the printed circuit board, where X usually indicating things like pin labels) is minimal. In order to actually utilize the largest number (it should also say Teensy 3.2) or OSX, you’ll need its [https: select /dev/cuwww.usbmodemXXXXXX, where XXXXXX is some numberpjrc. This may not show up with Teensycom/teensy/card7a_rev1.(You can see that neither of these operating systems handle hardware communication ports very elegantly.)pdf pinout]:
the default programmer for teensy is AVRISP mkII[[File:Teensy_3. To use it go to Programmer and select AVRISP mkII2_3.1_pinout.png]]
===Set up the Teensy on the breadboard===
[[File:Breadboard and Teensy.jpg|thumb|Note that in this example the green wire is connected to 5V.]]
[[File:Wired Teensy and Breadboard.jpg|thumb|This Teensy and breadboard are ready to go!]]
If it hasn’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).
Digital output
1If 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. create a new file
[[File:code for teensy.png]]
Connect the top upper rail and the top lower rail. 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 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.
2. then upload the code to your board using the button or CTRL+U. This is actually a compile ===Download and program. If you get any errors, ask for help. Assuming it has programmed correctly, you should now see the onboard LED blinking!install===
3#Download and install the [https://www.arduino.cc/en/main/software Arduino IDE] on your operating system of choice.Fiddle with ''(Note: if you're using Windows, use the installer, not the delay times app!)''#Download and reprogram install [https://www.pjrc.com/teensy/td_download.html Teensyduino], which adds Teensy support to see how the Arduino IDE. Just follow the prompts; you don’t need to install all the libraries, but if you can affect ever want to work with Teensies in the speed of future, it’s worth taking the LED blinkingtime to install them now.
4.Connect an LED ===The which, the where, and the how===In order to get the Arduino IDE up and a 330Ω resistor (just like in previous labs) running with your board - regardless of which board it happens to D9be - you must answer for it three questions: the which, the where, and then change to code to reference this new LED’s pinthe how.
5#Which board are you using?#*Navigate to ''Tools → Board'' and select ''Teensy 4.Compile 0''#Where is the board connected?#*Navigate to ''Tools → Port'' and Program :#**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 that neither of these operating systems handle hardware communication ports very elegantly.)#How are you 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 default programmer, the AVRISP mkII.#*Navigate to test''Tools → Programmer'' and select ''AVRISP mkII''.
Digital Input==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').
1.Navigate ===Activity 01: Digital output (aka 'Hello World' for hardware)===In this activity, you will use a pin on the microcontroller to File → Examples → 02.Digital → Buttonblink an LED.
2#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 button 220Ω resistor to D9, and then change to code to reference this new LED’s pin.#Compile and Program to D8test.
3.In the code, change the '''NOTE: There is a button pin to D8, and on the LED pin to D9Teensy. 3aThis button does not do what you think it does.pinMode(buttonPinThis button is a program button, INPUT_PULLUP)4meaning that when you press it, the device takes the most-recently compiled code and sticks it in its program memory.Compile and upload your codeThis is not a reset button!'''
5.Modify the code so that when you press the ===Activity 02: Digital Input (aka a button he LED turns on)===In this activity, and when you are not pressing the will use a button, to control an LED - all through software. Leave the LED turns offand 220Ω resistor connected to D9 like in the previous activity.
Analog input#Navigate to ''File → Examples → 02.Digital → Button''.#Connect a button to D2.#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.
1.Navigate to File → Examples → ===Activity 03.: Analog → AnalogInputInput (aka knobtwisting)===In this activity, you will use a knob to control the blinking speed of an LED - all through software.
2#Navigate to ''File → Examples → 03.Analog → AnalogInput''.#Connect a potentiometer to A5.#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!
3There isn't a way (yet) to see ''exactly'' how long each of those delays is happening for. Let's change that.Compile and Program, and turn the pot You're going to add some '''debugging''' functionality to change your code - by incorporating the speed at which the LED blinks!'''Serial Monitor'''.
4#In the setup function, add the following line:#:<code>Serial.debug 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 necessary the delay time (in ms) in the code.
5'''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. In Program the setup functiondevice, add then open the following line:SerialMonitor. If it’s still not working, check to make sure the IDE knows where the board is connected.begin(9600)
6.This initializes the Serial communications protocol. Now===Activity 04: Analog 'Output' (aka breathe)===In this activity, you will program an LED to fade in loop, after you’ve read the value of the analog pin, add the following line: Serialand out. There is no input control.println(sensorValue);
7#Navigate to ''File → Examples → 03.Analog → Fading''.#Compile and program Program the code, and once it’s successful, open the Serial Monitor with or CTRL+SHIFT+M. You your LED’s brightness should see values printing out on this screen; turn the potentiometer, be fading up and the value will changedown! This number is what is being used as the delay time (in ms) in the code.
Analog output===Activity 05: CHALLENGE===Using all your newly-acquired hardware and software prowess, create a device which directly controls the brightness of an LED with a knob.
1.Navigate to File → Examples → 03.Analog → Fading.<br />
2.Compile and program the code. your LED’s brightness should be fading up and down. ==Workshop Checklist=='''Learning Objectives'''
Analog final By the end of this Workshop, you should understand:
1.Create #What a microcontroller is#How to compile programs for a project - call it Fade Control - that controls the brightness of an LED. It has two modes: Automatic Teensy#The difference between analog and Manualdigital inputs/outputs. In Automatic mode, it will fade #Using the serial monitor for debugging purposes '''Measurable Outcomes''' By the brightness end of this Workshop, you should be able to: #Use the Arduino IDE and Teensyduino#Make an LED blink (Digital Outputs)#Use a button to control an LED up and down (just like Activity 04Digital Inputs). In Manual mode, the position of the #Use a potentiometer determines (Analog Outputs)#Change the brightness of the an LED (Analog Inputs)#Create a device that integrates everything we learned (control an LED. The mode can be switched by pressing 's brightness with a buttonpotentiometer)
47
edits

Navigation menu