Introduction: HackerBox 0051: MCU Lab
Greetings to HackerBox Hackers around the world! HackerBox 0051 presents the HackerBox MCU Lab. The MCU Lab is a development platform to test, develop, and prototype with microcontrollers and microcontroller modules. An Arduino Nano, ESP32 Module, and SMT32 Black Pill are used to explore the feature blocks of the MCU Lab. The MCU Lab feature blocks include switches, buttons, LEDs, an OLED display, buzzer, potentiometer, RGB pixel, logic level shifter, VGA output, PS/2 keyboard input, USB serial interface, and dual solderless prototyping areas.
This guide contains information for getting started with HackerBox 0051, which can be purchased here while supplies last. If you would like to receive a HackerBox like this right in your mailbox each month, please subscribe at HackerBoxes.com and join the revolution!
HackerBoxes is the monthly subscription box service for hardware hackers and enthusiasts of electronics and computer technology. Join us in livin' the HACK LIFE.
Step 1: Content List for HackerBox 0051
- MCU Module 1: Arduino Nano 5V, 16MHz
- MCU Module 2: WEMOS ESP32 Lite
- MCU Module 3: STM32F103C8T6 Black Pill
- Exclusive MCU Lab Printed Circuit Board
- FT232RL USB Serial Adapter
- OLED 128x64 Display I2C 0.96 Inches
- Bidirectional 8-Bit Logic Level Shifter
- WS2812B RGB SMD LED
- Four Surface Mount Tactile Buttons
- Four Red Diffused 5mm LEDs
- Piezo Buzzer
- HD15 VGA Connector
- Mini-DIN PS/2 Keyboard Connector
- 100K Ohm Potentiometer
- 8 Position DIP Switch
- AMS1117 3.3V Linear Regulator SOT223
- Two 22uF Tantalum Capacitors 1206 SMD
- Ten 680 Ohm Resistors
- Four Adhesive Rubber PCB Feet
- Two 170 point Mini Solderless Breadboards
- Eleven 8 pin Female Header Sockets
- 40 pin Breakaway Header
- Bundle of 65 Male Jumper Wires
- Raised Fist Circuit Board Sticker
- Hack The Planet Smiley Pirate Sticker
- Exclusive HackerBox "Remove Before Flight" Keychain
Some other things that will be helpful:
- Soldering iron, solder, and basic soldering tools
- Computer for running software tools
Most importantly, you will need a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.
There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we really appreciate your taking a few minutes to read the FAQ.
Step 2: HackerBoxes MCU Lab
The MCU Lab is a compact, polished version of a development platform we use to prototype and test various microcontroller (MCU) based designs. It is super useful for working with MCU modules (such as an Arduino Nano, ESP32 DevKit, etc) or individual MCU device packages (such as ATMEGA328s, ATtiny85s, PICs, etc). A target MCU can be placed into either of the mini solderless breadboards. Two MCUs can be interfaced together using both breadboards or one of the breadboard spaces can be used for other circuitry.
The "feature blocks" of the MCU Lab are broken out to female headers similar to those found on an Arduino UNO. The female headers are compatible with male jumper pins.
Step 3: Assemble the HackerBoxes MCU Lab
SMD COMPONENTS ON BACK OF BOARD
Start by mounting the AMS1117 (SOT 233 Package) Linear Regulator and the two 22uF filter capacitors on the reverse of the PCB. Note that one side of each capacitor silkscreen is rectangular and the other side is octagonal. The capacitors should be oriented so that the dark stipe on the package aligns to the octagonal silkscreen side.
CONTINUE WITH COMPONENTS ON FRONT OF BOARD
Solder the WS2812B RGB LED. Orient the white marked corner of each LED to correspond to the tabbed corner as shown on the PCB silkscreen.
Four SMD Tactile Buttons
Four Red LEDs with Four Resistors
Level Shifter with VA pin nearest 3V3 marking and VB pin nearest 5V marking. The Level Shifter module can be mounted flush to the PCB by soldering the headers to the module and then sliding the black plastic spacers off the headers before mounting the module to the MCU Lab PCB. Leaving the spacers on is fine as well.
Two strips of the header can be broken off to connect the FT232 module. A smaller 4-pin section of header can also be used for the 5V/GND header just next to the FT232 module.
For now, populate the female VGA header closest to the HD15 VGA connector and Keyboard Socket. However, DO NOT POPULATE the additional header adjacent to that one or the five resistors between those two headers. Specific options for video signal interfacing are discussed later.
Populate the other nine female headers.
Remove adhesive from back of both solderless breadboards to attach them to the MCU Lab PCB.
Position adhesive rubber feet to the bottom of the MCU Lab PCB to protect your workbench from scratches.
HANDLING POWER INPUTS
There are at least two, and more likely as many as four, places where power may come into the MCU Lab. This can cause trouble, so always carefully consider the following pointers:
The header points labeled 5V are all connected. The 5V rail also connects to the keyboard socket, the level shifter, and the WS2812B RGB LED. Power can be supplied to the 5V rail by plugging the FT232 into USB, connecting the four pin power header to an external supply, or by connecting a jumper from one of a 5V pin on the PCB to a powered 5V module (usually powered by USB).
Similarly, the GND pins are all connected. They connect to the USB GND on the FT232 (assuming USB is connected to the FT232). They can also be connected to ground using a jumper between one of them and a powered module as discussed for the 5V net.
The 3V3 rail is driven by the regulator on the back of the PCB. It is a source only and (unlike the 5V rail) it should not be driven by any modules or other circuits since it is driven directly from the regulator on the 5V rail.
Step 4: Arduino Nano MCU Module
One of the most common MCU modules these days is the Arduino Nano. The included Arduino Nano board comes with header pins, but they do not come soldered to the module. Leave the pins off for now. Perform these initial tests on the Arduino Nano module prior to soldering on the header pins. All that is needed is a microUSB cable and the Arduino Nano board just as is comes out of the bag.
The Arduino Nano is a surface-mount, breadboard-friendly, miniaturized Arduino board with integrated USB. It is amazingly full-featured and easy to hack.
- Microcontroller: Atmel ATmega328P
- Voltage: 5V
- Digital I/O Pins: 14 (6 PWM)
- Analog Input Pins: 8
- DC Current per I/O Pin: 40 mA
- Flash Memory: 32 KB (2KB for bootloader)
- SRAM: 2 KB
- EEPROM: 1 KB
- Clock Speed: 16 MHz
- Dimensions: 17mm x 43mm
This particular variant of the Arduino Nano is the black Robotdyn Nano. In includes an on-board MicroUSB port connected to a CH340G USB/Serial bridge chip. Detailed information on the CH340 (and drivers, if needed) can be found here.
When you first plug the Arduino Nano into a USB port of your computer, the green power light should come on and shortly after the blue LED should start to blink slowly. This happens because the Nano is pre-loaded with the BLINK program, which is running on the brand new Arduino Nano.
SOFTWARE: If you do not yet have the Arduino IDE installed, you can download it from Arduino.cc
Plug the Nano into the MicroUSB cable and the other end of the cable into a USB port on the computer. Launch the Arduino IDE software. Select "Arduino Nano" in the IDE under tools>board and "ATmega328P (old bootloader)" under tools>processor. Select the appropriate USB port under tools>port (it is likely a name with "wchusb" in it).
Finally, load up a piece of example code:
Blink is actually the code that was preloaded onto the Nano and should be running right now to slowly blink the blue LED. Accordingly, if we load this example code, nothing will change. Instead, let's modify the code a little bit.
Looking closely, you can see that the program turns the LED on, waits 1000 milliseconds (one second), turns the LED off, waits another second, and then does it all again - forever.
Modify the code by changing both of the "delay(1000)" statements to "delay(100)". This modification will cause the LED to blink ten times faster, right?
Let's load the modified code into the Nano by clicking the UPLOAD button (the arrow icon) just above your modified code. Watch below the code for the status info: "compiling" and then "uploading". Eventually, the IDE should indicate "Uploading Complete" and your LED should be blinking faster.
If so, congratulations! You have just hacked your first piece of embedded code.
Once your fast-blink version is loaded and running, why not see if you can you change the code again to cause the LED to blink fast twice and then wait a couple of seconds before repeating? Give it a try! How about some other patterns? Once you succeed at visualizing a desired outcome, coding it, and observing it to work as planned, you have taken an enormous step toward becoming a competent hardware hacker.
Now that you have confirmed operation of the Nano module, go ahead and solder the header pins onto it. Once the headers are connected, the module can be easily used in one of the solderless breadboards of the MCU Lab. This process of testing out an MCU module by downloading some simple test code, modifying, and downloading again is a best practice whenever using a new, or different type, MCU module.
If you would like additional introductory information for working in the Arduino ecosystem, we suggest checking out the Guide for the HackerBoxes Starter Workshop, which includes several examples and a link to a PDF Arduino Textbook.
Step 5: Explore MCU Lab With Arduino Nano
Connect center pin of potentiometer to Nano Pin A0.
Load and Run: Examples > Analog > AnalogInput
The example defaults to the Nano's onboard LED. Turn the potentiometer to change the blink speed.
In the code, change LedPin=13 to 4
Jumper from Nano Pin 4 (and GND) to one of the red LEDs of the MCU Lab.
Jumper from Buzzer to Nano Pin 8. Be sure the board GND is connected to the GND of the powered Nano since the buzzer ground is hard wired to the board GND net.
Load and Run: Examples > Digital > toneMelody
In the Arduino IDE, use the library manager to install "ssd1306" from Alexey Dyna.
Connect OLED: GND to GND, VCC to 5V, SCL to Nano's A5, SDA to Nano's A4
Load and Run: Examples > ssd1306 > demos > ssd1306_demo
WS2812B RGB LED
In the Arduino IDE, use the library manager to install FastLED
Connect the WS2812's header pin to the Nano's pin 5.
Load: Examples > FastLED > ColorPalette
Change NUM_LEDS to 1 and LED_TYPE to WS2812B
Compile and Run
WRITE SOME CODE TO EXERCISE THE BUTTONS AND SWITCHES
Remember to use pinMode(INPUT_PULLUP) to read a button without adding a resistor.
COMBINE SOME OF THESE EXAMPLES TOGETHER
For example, cycle outputs in some interesting way and show states or input values on the OLED or serial monitor.
Step 6: WEMOS ESP32 Lite
The ESP32 microcontroller (MCU) is a low-cost, low-power system on a chip (SOC) with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 employs a Tensilica Xtensa LX6 core and includes built-in antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power-management modules. (wikipedia)
The WEMOS ESP32 Lite module is more compact than the previous version which makes it easier to use on a solderless breadboard.
Make your initial test of the WEMOS ESP32 module before soldering the header pins onto the module.
Under tools>board, be sure to select the "WeMos LOLIN32"
Load the example code at Files>Examples>Basics>Blink and program it to the WeMos LOLIN32
The example program should cause the LED on the module to blink. Experiment with modifying the delay parameters to make the LED blink with different patterns. This is always a good exercise to build confidence in programming a new microcontroller module.
Once you are comfortable with the module's operation and how to program it, carefully solder the two rows of header pins into place and test loading programs once again.
Step 7: ESP32 Video Generation
This video demonstrates the ESP32 VGA Library and a very nice, simple tutorial from bitluni's lab.
The demonstrated 3-bit implementation (8 colors) uses direct wire jumpers between the ESP32 module and the VGA connector. Making these connections on the MCU Lab's VGA header is fairly easy since no additional components are involved.
Depending upon which MCU is in use, its voltage level, the pixel resolutions, and the desired color-depths, there are various combinations of inline resistors and resistor networks that may be placed between the MCU and the VGA header. If you decide to permanently use inline resistors, they can be soldered onto the MCU Lab PCB. If you would like to maintain flexibility and especially if you want to use more complex solutions, then it is recommended to not solder any resistors into place and simply use using the solderless boards and VGA header to connect up the necessary resistors.
For example, to implement bituni's 14-bit color mode shown at the end of the video, the ESP32 module can be positioned onto one of the mini solderless boards and the other solderless board can be used to connect up the resistors ladders.
Here are some other examples:
In HackerBox 0047 an Arduino Nano drives a simple VGA output with 4 resistors.
Implement a BASIC PC using ESP32 and 3 resistors.
Play Space Invaders on ESP32 using FabGL and 6 resistors.
Generate VGA output on STM32 with 6 resistors.
Step 8: STM32F103C8T6 Black Pill MCU Module
The Black Pill is an STM32-based MCU Module. It's an improved variant on the common Blue Pill and the less common Red Pill.
The Black Pill features the STM32F103C8T6 32bit ARM M3 microcontroller (datasheet), a four-pin ST-Link header, a MicroUSB port, and a user LED on PB12. The correct pull-up resistor on PA12 comes installed for correct operation of the USB port. This pull-up typically required a board modification on other Pill Boards.
While similar in appearance to the Arduino Nano, the Black Pill is far more powerful. The 32bit STM32F103C8T6 ARM microcontroller can run at 72 MHz. It can perform single-cycle multiplication and hardware division. It has 64 Kbytes of Flash memory and 20 Kbytes of SRAM.
Step 9: TXS0108E 8-Bit Logic Level Shifter
The TXS0108E (datasheet) is an 8-Bit Bidirectional Logic Level Shifter. The module is set up to level-shift signals between 3.3V and 5V.
Since the signal level channels are bidirectional, floating inputs can cause the corresponding outputs to be unintentionally driven. An output enable (OE) control is provided to protect in such scenarios. Care should be taken depending upon how the shifter is connected to make sure that an output from the shifter (either "intentional" or due to a floating input on the other side) is never allowed to cross-drive an output from another device.
The OE pin is left disconnected in the PCB traces. A two-pin header is provided below the module for connecting OE and 3V3. Shorting the two-pin header (using a piece of wire or a jumper block) connects OE to 3V3 which enables the IC to drive its outputs. A pulldown resistor and logic control can also be connected to the OE pin.
Step 10: HackLife
We hope you are enjoying this month's HackerBox adventure into electronics and computer technology. Reach out and share your success in the comments below or on the HackerBoxes Facebook Group. Also, remember that you can email firstname.lastname@example.org anytime if you have a question or need some help.
What's Next? Join the revolution. Live the HackLife. Get a cool box of hackable gear delivered right to your mailbox each month. Surf over to HackerBoxes.com and sign up for your monthly HackerBox subscription.