HackerBoxes 0016: Cellular Metal
by HackerBoxes in Circuits > Microcontrollers
17522 Views, 27 Favorites, 0 Comments
HackerBoxes 0016: Cellular Metal
CELLULAR METAL: This month, HackerBox Hackers are exploring cellular mobile communication for embedded IoT (Internet of Things) and M2M (Machine-to-Machine) systems. We are also exploring the beauty of working close to the bare metal of a computing machine.
This Instructable contains information for working with HackerBoxes #0016. If you would like to receive a box like this right to your mailbox each month, now is the time to subscribe at HackerBoxes.com and join the revolution!
Topics and Learning Objectives for this HackerBox:
- Compiling and Uploading Code onto an Arduino Board
- Connecting a GSM Mobile Radio Module to an Arduino
- Communicating on a Global Mobile Cellular Network
- Building a Breadboard-Based Arduino from Scratch
- Using an Existing Arduino as a DIY In-System-Programmer
- Exploring an Online Microcontroller Course
- Implementing a Minimal 8-Pin ATtiny Arduino
- Dropping Down into Assembly and Machine Languages
- Considering Machine Architecture through Assembly Language
HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. And we are the dreamers of dreams.
HackerBoxes 0016: Box Contents
- HackerBoxes #0016 Collectable Reference Card
- Hologram Global IoT/M2M SIM Card
- SIM800L 5V GSM Module with Rubber Ducky Antenna
- RobotDyn Arduino UNO R3 Microcontroller Board
- CP2102 MicroUSB-Serial Module
- Solderless Breadboard
- 65 Piece Jumper Wire Set for Breadboard
- ATmega328P 28-Pin DIP Microcontroller Chip
- ATtiny85 8-Pin DIP Microcontroller Chip
- Various Discrete Components for Breadboard Arduino
- Various Discrete Components for Microcontroller Course
- Exclusive Tux "Hack The Planet" Stress Toy
- Exclusive Apple Hacker Fan Art Decal
Some other things that will be helpful:
- Soldering iron and solder
- Computer for running development tools
Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Hardcore hobbyist electronics aren't always easy, but when you persist and enjoy the adventure, a great deal of satisfaction may be derived from persevering and getting your projects working. Just take each step slowly, mind the details, and don't hesitate to ask for help.
Setting Up the Arduino UNO
Arduino Veteran:
If you are already up to speed with using an Arduino UNO, already have the Arduino IDE installed, and already have the CH340 USB driver installed, you can skip to the next step. However, you should probably at least plug in your UNO and make sure you can compile and upload an example (such as blink.ino) just to make sure everything is ready to go.
Less of a Veteran:
Check out Step 12 of the instructions for the HackerBoxes Starter Workshop. There, you will find an overview of the Arduino ecosystem, the RobotDyn UNO in particular, and most importantly details on installing the CH340 USB drivers.
Next, proceed to Step 13 of the instructions for the HackerBoxes Starter Workshop. There, you can grab a free copy of the Introduction to Arduino book by Alan Smith, Install the Arduino IDE, wire up your first Arduino circuit, and write your first Arduino program.
Optional Extra:
Continue on to Step 14 of the instructions for the HackerBoxes Starter Workshop to explore the world of Arduino even further. The components in this HackerBox #0016 happen to include everything needed to work through section 3.2 of the book. This is worth doing if you are new to Arduinos. You may also want to look at section 5.1 to learn about the serial monitor. While it is well beyond the scope of this current Instructable, the components for the remaining chapters list in Step 14 are included in the HackerBoxes Starter Workshop.
Wire Up the SIM800L Module to the Arduino UNO
Of course we've all had times when we would like to have a project communicate over the cellular communications network. Sometimes Wi-Fi is not available or just doesn't have enough range.
For example, maybe you want your project to send you a text message when a sensor is triggered. Or perhaps it needs to report data to another system from various mobile locations not serviced by Wi-Fi.
The SIM800L module (datasheet) is a great solution. It has a quad-band radio (850/900/1800/1900MHz) supporting 2G Global System for Mobile Communications (GSM) including data packet transport via General Packet Radio Services (GPRS).
The SIM800L can be simply wired to an Arduino UNO as shown here. The SIM800L is fairly easy to control using an AT command set or function from an existing library. Examples for both of these options are outlined in this quickstart tutorial.
As a first step, you might want to wire the SIM800L to the Arduino without the antenna feed line or the SIM card, just to make sure that you can get a response to an "AT" or an "AT+CFUN?" command. In the next step we will move on to using the SIM card.
Reference Links:
Hologram - the Global IoT SIM Card
HackerBoxes is very excited to partner with Hologram to bring you this ready-to-use, global IoT/M2M SIM along with a $5 promotional balance.
To mitigate the various challenges in putting your project or product online anywhere, Hologram has built a global SIM and cell network built for IoT and M2M data with simple activation and transparent pricing. The Global Hologram Cellular Network support connectivity in over 100 countries allowing us to connect our IoT devices seamlessly from one country and carrier to another.
Follow the links here to activate your SIM. You will see a link to "Apply Promo Code" where you can enter the activation code: HACKERBOX5.
The Hologram SIM card is a triple SIM. Be sure to only pop out the microSIM, which is the size used by the SIM800L modules.
Hologram has put together a wonderful Cellular IoT Tutorial and library that leverages the components in this HackerBox. Definitely check it out!
Bare Metal
Programming on the "Bare Metal" or "Near the Metal" or "Close to the Metal" is defined by Wikipedia as programming a machine without an operating system, which is a bit of an over-simplification. After the development of programmable computers, which did not require physical changes to run different programs, but prior to the development of operating systems, programs were fed to the computer system directly using machine language by the programmers without any system software support. This bare metal approach bootstrapped the development of operating systems. Modern operating systems evolved through various stages, from quite elementary to the present day complex, highly-sensitive, real-time systems.
Today, bare metal work is mostly applicable to embedded systems and firmware, while everyday programs are executed by a runtime system within an operating system. That said, even the Arduino platform that has become almost ubiquitous in the embedded world, uses a bootloader and various libraries to abstract us away from the metal of the AVR microcontroller. It is time to dig deeper.
DIY Arduino From a Bare AVR Micrcontroller Chip
Starting with a stock (completely blank) ATmega328P chip, you can do some amazing things. This the same chip that is used on the Arduino UNO R3 boards. The ATmega328P is a high-performance 8-bit AVR RISC-based microcontroller. It combines 32KB ISP flash memory with read-while-write capabilities, 1024B EEPROM, 2KB SRAM, and 23 general purpose I/O lines.
Take a look at the schematic shown here with the components needed from the HackerBox.
This video tutorial from PyroElectro shows how to wire up a DIY Arduino on a breadboard from components.
Notice that the schematic we are using here has a slight variation from the one in the video. While the video shows use of a battery and a regulator circuit as the power supply, we are simply using the 5V supply from the Serial-USB module. The Serial-USB Module uses the CP2102 bridge chip. If you do not have drivers installed for this chip, they may be found here.
Another important difference is that the video tutorial assumes that the ATmega328P chip already has an Arduino bootloaded burned onto it. Since we are starting from a blank chip, we will need to need to program the bootloader onto the ATmega328P chip. We can use the UNO as an In System Programmer (ISP) as shown under the Burning The Bootloader heading on this page.
Online Course for Microcontrollers From PyroElectro
The PyroElectro video in the last step is actually just one part of an entire ten lesson online course covering microcontrollers. You may wish to work through the other lessons as well. You have all of the necessary components in HackerBox #0016 to do these lessons aside from some of the extra "user interface" components used in lesson 8. As an added exercise, see if you can replace these hardware interface elements with a user interface leveraging the serial monitor.
Lesson 10, AVR vs Arduino, covers precisely the "bare metal" issue we are addressing here, so we definitely recommend that you at least watch the video for Lesson 10.
Much respect for the work done by PyroElectro on these lessons.
Minimal Arduino With the 8-pin ATtiny85
The ATtiny85 is a great option for running simple Arduino programs. It’s small, cheap, and relatively easy to use. Compared to the ATmega328P (from the Arduino UNO), the ATtiny85 has fewer pins, meaning you can’t connect as many components. It has less flash memory (8KB instead of 32KB), meaning your programs can’t be as big. It has less RAM (512 bytes instead of 2KB), meaning you can’t store as much data. And there’s no hardware serial port or I2C port, so communication can be a little trickier. However, if your project requires only a few simple inputs and/or outputs, you’re probably fine using an ATtiny85.
This tutorial from High-Low Tech can show you how its done!
Assembly Language for AVR Microcontrollers
Now that we've used bare AVR micros to build up DIY Breadboard Arduinos, we can go a step further and drop down to writing machine code directly on the chip. This is an advanced topic, but there is no better way to learn the deep details of how processors work. Luckily, there is an entire online book covering the subject of AVR Assembly Programming.
Note that you can also embed inline assembly code within a traditional Arduino program when added efficiency or tight execution is called for.
Further down the rabbit hole, you might want to explore more of a general or academic view of assembly/machine programming and how it relates to the underlying computer architecture. If so, check out the CMU lectures on Computer Architecture or the lectures and slides for CS24 at Caltech.
Hack the Planet
Thank you for joinging our adventures into mobile cellular IoT/M2M communications and bare metal computing. If you have enjoyed this Instrucable and would like to have a box of electronics projects like this delivered right to your mailbox each month, please join us by SUBSCRIBING HERE.
Reach out and share your success in the comments below and/or on the HackerBoxes Facebook page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of HackerBoxes. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!