Week 5: Embedded Programming¶
group assignment: • demonstrate and compare the toolchains and development workflows for available embedded architectures
For our group assignment we began by each taking on a different embedded architectures…
Arduino IDE (angela)¶
Using the Arduino IDE as the development environment, I started off with an Arduino Nano board, which uses the ATmega328P microcontroller. Then I went through the following steps with the guidance of my instructor:
- Downloaded Arduino IDE
- Walked through the ATmega328P datasheet to take a look under the hood and get an overview of its architecture, memory segments, and features
- Set up the Arduino Nano board with the breadboard and plugged into my computer using USB-C cable
- Perused some of the available example code under File>>Example menu
- Selected my port and board in the Arduino IDE interface
- Ran through simple practice programs, adding various components to the breadboard accordingly (ex. LED, potentiometer, resistor)
Programming Practice¶
Blink (with built-in LED)
For the first practice test, we used the example code available in the Arduino IDE for “blink” which turns an LED on for one second than off for one second repeatedly. I quickly found out that the very thorough documentation and notes within the code make it easy to understand what each line of code is doing. For example, pinMode(LED_BUILTIN, OUTPUT) signifies an initializing of the digital pin of the LED already built into the Nano board as an output. This means the subsequent code will apply to this pin.
After selecting the board and hitting upload, the LED on the board began to blink! By raising the value within the delay code line we could make the LED blink slower and vice versa.

Push button
Then we hooked up a button to the board, putting it in D5 (a digital port) since the button is a digital component. Using the button example code template, I set pin number for the button at 5 and I also ended up tweaking the setup so that the initial setup up of the button when not pressed has the LED on by adding “INPUT_PULLUP” in the code. Uploaded and the button worked.

Dim light
Next, I learned how to go about dimming lights after hooking up an LED to the breadboard with the help of Addie. Since the LED is a digital component, it just turns on or off. To practice with dimming, I learned that we could use the blink code and experiment with the rate at which we blink the light to give the illusion that the light is dimming. After experimenting with the values input for the delay code which dictate how long between the LED turning on and off, I found a time that worked and the light appeared dimmer (even though in reality it is actually turning on and off at a rate faster than the human eye can detect).


Dim light with potentiometer
After learning about the potentiometer component (an analog component) and how to set that up on the breadboard, my final challenge in class was to figure out code for how to dim the light using the potentiometer. I learned that the potentiometer has three legs – one to connect to power, one in the middle to connect to the analog pin which reads the variable voltage as you move the dial, and one to connect to ground and complete the circuit.
From my earlier practice, I know I would need to define the constant pin number where my LED light would be which I put at 5. I would use the code used to dim light but now needed to also inlcude other components in the set-up. After some instruction on initial set up for potentiometer code (setting the pin at A3 and initalizing serial communication at 9600 which essentially establishes a communication channel between the Arduino and computer for reading the variable inputs), I think added in the LED as an output. For the loop, I also learned about how to set up the potentiometer to so that it could be read and to print its reading. From there, I had to figure out what to write in the rest of the code so that the potentiometer input would correlate to the dimming of the light. After some trial and error I found out the I could use the printed “reading” within the delay code. Since the number for the reading goes as high as 1024, I ended up multiplying it by 15 (value used in the previous challenge) and dividing that by 1024. That worked pretty well!

Lesson Learned¶
In experimenting with this workflow, some interested lessons learned:
- If not pulled, pins wil float around which we don’t want. We want them to be pulled to a known state, either pull pins high (5V) or low (ground). You do this within the program code.
- Do not forget semicolons! Just forgetting “;” will cause errors
- code written in all capital letters indicates a constant
- Define variables and constants in the code before the set up and loop functions
- how to use a multimeter to measure voltage, current, and resistance. For example, when you don’t pull a pin you can use the multimeter and see that its “floating” do to the variance in voltage rather than staying constant.
- analog vs digital - digital signal is something on or off (1 or 0) whereas an analog signal is something that will continuously vary. The Arduino nano board has a side of pins for analog and another side for digital.
- how to use a potentiometer which is an analog, variable resistor