Arduino Internet of Things Part 1: Burning The Arduino Bootloader Onto A Blank ATmega328p Chip Using The Arduino Uno
This is the first of several Internet of Things (IoT) tutorials using the ATmega328p board. I chose the ATmega328p board because of its ubiquity in the Arduino maker electronics community, and the low-power consumption and efficiency of the chip. In this tutorial, I discuss the parts needed to make a $3 DIY Arduino board, how to wire that board, how to load the Arduino bootloader onto the ATmega chip, and how to upload a sketch onto the 'breadboard Arduino' to simulate an Arduino Uno environment. Since this is the first of the series, I chose only to discuss the parts and how to go from a blank ATmega chip to a working Arduino board. The next tutorial in the series will continue by optimizing that minimal breadboard Arduino to investigate power consumption and sleep cycles. The primary goal of this tutorial is to create a framework for a low-power, connected, versatile board that can be tailored to specific IoT applications.
Parts List and Breadboard Wiring
- ATmega328p-pu Chip [Amazon, [AliExpress] - $1.40 (AliExpress), 4 for $17 (Amazon, already bootloaded)
- 22pf Capacitors (2) [Amazon] - 50 for $5
- Quartz Crystal Oscillator (16MHz) [Amazon] - Multi-kit for $12
- 10k Resistor (or around that value) [Amazon] - Multi-kit for $11
- Arduino Uno [Amazon,Amazon] - $20-$30, $11
- Mini Breadboard [Amazon] - 6 for $6.50
Average Cost for DIY Board: ≈ $3.00
Some of these components can be purchased elsewhere to drive the cost down even more. Places like AliExpress.com, Ebay.com, and even Mouser.com list many components much cheaper, which can drive the average total cost to less than $2!
IMPORTANT NOTE: You can find Arduino Uno boards online for around $3-$5 from AliExpress. However, we are not building a simple arduino board, we are creating an IoT node. The cheap $3-$5 boards are too large, sink too much power, and are simply unnecessary. The goal of IoT is to create tiny sensor nodes that are efficient and sleek. You may also find Arduino Pro Mini boards out there for around $2. Those are much closer to what we are building, with the exception of the crystal oscillator and power requirement. We want to lower the crystal oscillating frequency (from 16MHz to 8/4 MHz) and also use LiPo batteries at 3.7V or even lower. Both of these adjustments make the nodes very low power, yet still function with Bluetooth modules. There is an 8MHz board out there (AliExpress) for about $4, which could suffice, but I recommend removing the onboard LED to lower the consumption, and again acknowledge the inability to lower the crystal frequency from 8MHz to 4MHz (without de-soldering).
Figure 2: Minimal ATmega328p Arduino
Figures 2 and 3 show the component setup for the minimal Arduino board. The primary reason for the capacitors is to moderate the oscillations from the crystal oscillator. With the inclusion of the crystal oscillator allows us to keep accurate timing, which will in turn permit the use of Bluetooth modules via serial communication - an essential for IoT integration. Here we use a 16 MHz crystal oscillator, which is necessary to upload the Arduino bootloader. Once the bootloader is uploaded, other oscillators can be used to lower the power consumption of the minimal board.
Uploading ArduinoISP to Uno Board
Since we will be using an Uno board to program ATmega328 chips, we need to upload the ArduinoISP sketch to the Uno board before wiring anything together. The steps below should be followed to upload the ArduinoISP sketch.
- Select ArduinoISP under Examples->ArduinoISP
- Uncomment '#define USE_OLD_STYLE_WIRING
- Make sure that Arduino Uno board is selected
- Upload sketch to Arduino Uno board (nothing wired to it)
See below for screenshots of procedure:
Now that the ArduinoISP sketch is wired to the Uno board, it is time to wire the breadboard Arduino to the Uno board. This will prep the Arduino Uno as ISP and allow one to upload the Arduino bootloader to the ATmega328 on the breadboard.
Wiring and Bootloading The External ATmega Board
The ATmega on the breadboard should be wired to the Uno as shown in the table and image below:
|Arduino Uno||ATmega Breadboard
Now, in the Arduino IDE the Programmer needs to be set as 'Arduion as ISP' to upload the bootloader to the ATmega chip.
Finally, once the ATmega is wired to the Arduino Uno and the Programmer is switched to 'Arduino as ISP,' click 'Burn Bootloader' to burn the Arduino bootloader. This process uses the Uno board as an in-circuit serial programmer (ISP) to program the ATmega328p chip as an Arduino board. Once this is done, one can treat the ATmega on the breadboard as a classic Arduino board. In the next section, I cover the simple process of uploading a sketch to the breadboard Arduino.
Uploading a Sketch to ATmega Breadboard Arduino
At this point, the ATmega configuration is an Arduino board! But in order to upload sketches to the chip we need to remove the main chip from the Uno board. This allows the Uno to bypass its chip and serially communicate sketches to the breadboard Arduino via the TX/RX pins. Below is the wiring diagram and table for uploading sketches to the breadboard Arduino.
|Arduino Uno||ATmega Breadboard (pin)|
It is a good idea to upload a simple sketch and ensure the breadboard Arduino is functioning properly. An external LED blink sketch is a good sketch to start with, or even an analog read/write sketch to test that the bootloader has been burned correctly.
This tutorial covered the basics of wiring and flashing a low-cost ATmega328p chip using an Arduino Uno board. It is the first entry into a series of tutorials designed to create and test a network of sensors and smart devices that communicate via Bluetooth and operate for months on a single LiPo battery charge. The framework shown above is the hardware basis that will allow the user to control both the communication via Bluetooth and power consumption through software implementation. The ATmega-based breadboard Arduino can read temperature and humidity sensors, it is capable of registering interrupts via hall sensors or motion sensors; the framwork is also able to read analog signals at 10-bit resolution, and can do almost everything a typical Arduino Uno can - with the exception of certain power limitations depending on the components used. The following tutorial will explore power consumption and methods to optimize the sleep cycles of the breadboard Arduino.