ArduinoArduino is an inexpensive, easy-to-use platform for small electronics projects, which has become extremely popular in the hobby electronics community. We'll be using an Arduino microcontroller board for the useless box, LED cube and electrocardiogram lab projects. There are dozens of Arduino boards, of different sizes and capabilities. The one we're using is not technically an Arduino, but rather an Arduino-compatible derivative made by Adafruit known as the Metro Mini.
Setting up tools is an unavoidable part of making stuff, but we don't want getting the Arduino to work to be a time sink for anyone. So if you're encountering problems and you're not sure what to do, please ask so you can move on to the fun parts of lab! Installing the Arduino IDEDownload the Arduino IDE appropriate for your system from the Arduino website, and install it. You're also welcome to try the web editor, but we make no guarantees that it will work. For detailed instructions, see the Getting Started guides: Mac users will additionally need to install the SiLabs drivers. If you somehow have an older Metro Mini which has an FTDI chip, then you'll need the FTDI drivers instead. Testing your installation + your ArduinoTo test things, we'll load a simple standard program “Blink” on to the Arduino, and confirm that it runs.
If it didn't work, have a look through our troubleshooting guide below. If none of those help you, come to an office hour and we'll see what we can do, and extend the guide Once you've loaded Blink, that should be enough to get you going! But for those who want to dig a little deeper, there are full “getting started” instructions on the Arduino website. Troubleshooting installationWhen I click upload, it tries for a while but says it has a “problem uploading to board.”
When I click upload, I get an “stk500_getsync() download” error.
Hardware: Putting your Arduino circuit togetherInserting it into your breadboard
Putting your circuit together
Which pins do what?All of this information is taken from the Arduino Nano specifications page. Power pinsThere are three ways to power the Arduino board.
Using your AA battery pack
When using your AA battery pack, which gives about 4.5 V, to power your Arduino board, you should connect it to the 5V pin. Then, just be aware that your circuit will be powered by 4.5 V, not 5V. Never do this at the same time as connecting a USB cable, because that will try to push the USB's 5 V on to your non-rechargeable 4.5 V batteries. The VIN circuit is only capable of stepping down, not up, so connecting 4.5 V to VIN won't work. Also, the 3V3 pin doesn't power the Arduino, it's actually just a 3.3 V output that is generated when the USB cable is plugged in. Input/output (I/O) pins
What about analog output? There's no true analog output on the Arduino microcontroller, but there are pins that support pulse-width modulation (PWM), which is close enough for our purposes. In something of a misnomer, this is controlled using the analogWrite() function. The (digital) I/O pins capable of this are 3, 5, 6, 9, 10 and 11. Take note: All digital input/output pins can be configured as digital inputs or outputs. However, the analog input pins are not the same as the analog output pins! Other pins
Software: Your own Arduino programOften, it's most helpful to look at example programs to understand how they do things, and take snippets or modify them to do what you want to do. The examples (sometimes called “tutorials”) are in File > Examples, and there are helpful descriptions of them on in the Examples page on the Arduino website. To get started, look at the ones in Basics, Analog and Digital. You can start to look at the others as you want to use more advanced functionality. The basic structure of an Arduino programYour basic Arduino template will look like this: void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: } The setup() function runs once when the Arduino is powered on. You should use this to configure pins (pinMode()) and, if you want to use the Serial Monitor, to run Serial.begin(). The loop() function runs repeatedly forever. You can think of it as being inside an infinite loop. In this loop, you read inputs and write to outputs, to achieve the effect you want on the rest of your circuit. When you're programming a computer (in your CS courses), infinite loops are a bad thing to be avoided like the plague. In electronics, infinite loops aren't only acceptable, but necessary: your program is always monitoring inputs and adjusting outputs, which can only do if it's in an infinite loop. The Arduino referenceOnce you're in the swing of programming, you might want to keep the Arduino language reference handy. It has a complete guide to much more than you need to know about the Arduino, so you certainly don't need to be familiar with it, but if you're wondering how a function works or whether there's a function to do what you want, it's a great guide. |