HackerBox 0098: Escape
Welcome to HackerBox 0098. Escape into a world of hardware fantasy. Create your own HAL 9000 interface panel and explore the science of computer speech synthesis. Work with RP2040, ESP32-S2, and ATmega32U4 microcontroller chips programmed in CircuitPython and C/C++. Implement touch inputs, LED controls, audio playback, signal amplification, and wireless USB exploits. As always, learn some cool tricks along the way.
HackerBox is the original monthly subscription box for electronics, computer technology, and hacker culture. Each HackerBox is a discovery box, which means all members await and enjoy a new surprise each month. Tech, toys, knowledge, and fun. It's like having a hacker convention, your birthday, and the first day of school - every month - right in your mailbox.
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'd really appreciate it if you can take a few minutes to read the FAQ.
Supplies
This Instructable contains information for getting started with HackerBox 0098. The full box contents are listed on the product page for HackerBox 0098 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month, you can subscribe at HackerBoxes.com and join the party. Subscription members save at least $15 every month and automatically receive each new HackerBox shipped immediately off the production line.
A soldering iron, solder, and basic assembly tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Workshops for tools and supplies along with a wide array of introductory activities and experiments.
The most import thing you will need is 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.
WEAR SAFETY GLASSES WHEN SOLDERING, WHEN TRIMMING WIRE LEADS, OR WHEN CUTTING, DRILLING, ETC.
HAL 9000
HAL 9000 (Heuristically Programmed Algorithmic Computer 9000) is a fictional artificial intelligence character and the main antagonist in Arthur C. Clarke's Space Odyssey series. First appearing in the 1968 film 2001: A Space Odyssey, HAL is a sentient artificial general intelligence computer that controls the systems of the Discovery One spacecraft and interacts with the ship's astronaut crew. While part of HAL's hardware is shown toward the end of the film, he is mostly depicted as a camera lens containing an illuminated red dot. (wikipedia)
Computer Speech Synthesis
One of the most noteworthy characteristics of the movie character HAL 9000 is his synthesized voice.
Speech synthesis is the artificial production of human speech. A computer system used for this purpose is called a speech synthesizer, and can be implemented in software or hardware. Synthesized speech can be created by concatenating pieces of recorded speech that are stored in a database. Alternatively, a synthesizer can incorporate a model of the vocal tract and other human voice characteristics to create a completely "synthetic" voice output. (wikipedia)
You might enjoy this video, which even mentions our friend HAL 9000: The Evolution of Computer Speech
D.I.Y. HAL 9000 Kit
The D.I.Y. HAL 9000 Kit is based on the Raspberry Pi RP2040 Microcontroller. The kit features an exclusive printed circuit board, a Seeed Studio XIAO RP2040 module, a PAM8302A audio amplifier, a 3W speaker, an APA106 addressable RGB LED, and a couple 1M SMD1210 resistors to support touch inputs.
The Seeed Studio XIAO RP2040 microcontroller module is compatible with the Raspberry Pi Pico ecosystem as they share the same RP2040 chip. It supports multiple languages including MicroPython, CircuitPython, C, and Arduino Sketch code. It is a great tool for getting started with microcontroller hardware hacking.
BEFORE SOLDERING ANYTHING: Start with the XIAO RP2040
Power up the XIAO RP2040 by connecting it to your computer using a USB-C cable.
The tiny RGB LEDs (next to USB connector) will cycle and the NeoPixel (between the two buttons) will light up red, green, and then blue.
If you aren't familiar with NeoPixels, check out the Adafruit NeoPixel Überguide. We'll even be adding our own APA106 RGB LED later.
Starting with CircuitPython
Download the latest stable release of the CircuitPython UF2 from this page.
There are installation instructions linked from there, but this is the crux:
- Hold the BOOT (B) button while plugging the XIAO into your computer
- A drive named "RP1-RP2" will appear on the computer
- Paste or drag the .uf2 file onto the RP1-RP2 drive
- Verify that the name of the drive changes to "CIRCUITPY"
- That drive should have a code.py file (or grab this one)
- The comments in code.py explain that two libraries are required
- neopixel.mpy
- adafruit_pixelbuf.mpy
- They can be found here (be sure to match the version number)
- Put those two libraries into the folder CIRCUITPY/lib
- The NeoPixel should now blink RED
- Open code.py in an editor (consider installing Mu)
- Change pixels.fill((255, 0, 0)) to pixels.fill((0, 0, 255))
- Now the NeoPixel should be blinking BLUE
Now that we have the RP2040 module working and CircuitPython all set to go, let's build HAL 9000...
Assemble the HAL 9000 Kit
Connections Inside the PCB (just FYI)
Pin D7 from the RP2040 feeds the data-in line of the RGB LED.
There are two touch inputs:
- Pin A0 into the RP2040 connects to the metal ring around the LED on the front of the PCB
- Pin A1 connects to TP1 (test pad) on the back of the PCB
Each touch input line is also grounded through a 1M resistor.
There are two audio outputs:
- Pin A3 from the RP2040 connects to A+ of the audio amplifier
- Pin A2 connects to A- of the audio amplifier and also a grounding jumper
Solder the A- Grounding Jumper Closed
We will only be using the A3 (A+) audio output signal. Putting a little solder on the jumper labeled (GND A-) will tie the other audio line A2 (A-) to ground. While this jumper is soldered, never drive an output to pin A2 of the RP2040, as that will make it very hot and angry. Should you ever want to use the differential input into the audio amplifier, just be sure to open the grounding jumper first.
Place the two 1M Resistors
If you want a visual on how to easily solder these, watch around 4:15 into this video. Resistors are not polarized, so they can be soldered into place in either orientation, or even upside down if you're feeling especially crazy.
Solder the PAM8302A Amplifier Module - Bumps First
Start by placing five small bumps of solder on the pads for the amplifier module as shown in the photo above. Next, place the module onto the bumps and heat each one of the five header holes while melting a small amount of solder into the hole. This will fill each hole with molten solder which will nicely join up with the bump of solder on the PCB and marry the module to the PCB (both electrically and mechanically). Be sure not to short any solder between the holes or between the pads beneath.
This "bump first" technique may seem unusual, but it is actually quite easy. It's a bit like soldering castellated mounting holes (tutorial here) which is what we'll be doing next...
Place the Seeed Studio XIAO RP2040 Module
The important part of this one is getting the module lined up exactly with the pads. Take time to get this right, and then the soldering should be pretty simple. Just come up to the castellation from the side (along the PCB) and allow a little molten solder to wick up under the castellation. If you watch through the hole in the castellation, you'll probably notice the solder flowing in, which is oddly satisfying.
One APA106 Addressable RGB LED
Insert the LED through the front of the PCB. Orient the LED with its flat edge directed closest to the HACKERBOX logo on the back of the PCB. The pins are quite close together, but we've found that if the pins are trimmed flush to the back of the PCB prior to soldering, there is far less likelihood of solder bridging between the pins.
Place the Audio Speaker
The speaker can be fix into place with some hot glue as shown in the photo. Use a couple pieces of wire to solder the speaker to the output pins of the amplifier module. It doesn't matter which pin is connected to which speaker terminal.
Nameplate Decal
Carefully cut out and affix a label if you wish to identify this 9000 series computer as either HAL 9000 or SAL 9000.
"Will I dream?"
Programming Time
A simple program can be used to give HAL his voice using phrases stored in MP3 audio files.
Place the two attached files into the CIRCUITPY folder on the RP2040.
Rename HAL9000.py to code.py
The metal ring around the LED on the front of the PCB serves as the touch input.
The program illuminates the LED to red and waits for a touch input to trigger the voice.
Of course, you can change the MP3 file, or add more, as you wish. (e.g. I'm sorry Dave)
Voice Synthesis - Allophones and More
An interesting approach to synthesizing voice (instead of using prerecorded audio files) involves allophones as presented by the 8-Bit Guy in his video How Speech Synthesizers Work. An old-school voice chip, the SPO256-AL2, leveraged allophones. The SPO256-AL2 has been emulated on the RP2040 in this project.
Lastly, keep an eye on the talkberry project as it evolves.
ESP32 S2 Mini
The most notable feature of the S2 variant of the ESP32 is hat it does not require an external USB chip. It has built-in USB support along with all the features we've come expect from an ESP32 including Wi-Fi and Bluetooth support.
USB ADAPTER
As the ESP32 S2 Mini module features a female USB-C socket, a male-to-male USB adapter can be used to directly plug into a computer's USB port. Either a USB-A or USB-C type adapter can be used depending upon your target PC.
FIRST POWER ON
When we first plug the ESP32 S2 Mini module up to USB power, it does a bunch of nothing. No LEDs, or anything else. It is not broken. We just need to program it...
CONFIGURING THE ARDUINO IDE
Follow this Random Nerd Tutorial to install the Arduino IDE software and set up the ESP32 board support package in the Arduino IDE.
But, stop at the heading "Testing the Installation" because they are using a different type of ESP32.
Instead, in the Arduino IDE, navigate to:
Tools > Board > ESP32
and then scroll down to select "LOLIN S2 Mini"
To force the MCU into download mode, hold down the "0" button on the board, press and release the "RST" button, and then release the "0" button. You should only have to do this the first time you use the Arduino IDE, but now you know how it's done whenever you need it.
Name navigate to:
Tools > Board > Port
and select the appropriate USB port.
HELLO WORLD
Open the example sketch:
File > Examples > Basics > Blink
Compile and download the sketch to the ESP32.
Hit the "RST" button on the board again.
The sketch will blink the onboard LED.
This is what we consider the "Hello World" of embedded processor work.
ANOTHER INITIAL TEST, THIS TIME WITH MORE Wi-Fi
Open the sketch:
File > Examples > WiFi > WiFiScan
Compile and download the sketch to the ESP32.
Open Tools > Serial Monitor
Set the baud rate to 115200
HACK THE PLANET
DISGUISE IT AS A USB STICK
As illustrated in the image above, a 3D printable "USB Stick" enclosure could be used to unite the ESP32 S2 Mini and a USB male-to-male adapter together into a seamless package.
Consider OpenSCAD, which is known as The Programmer's Solid 3D CAD Modeler. It does not focus on the artistic aspects of 3D modeling but instead on the CAD aspects using parametric codes. It is something like a 3D-compiler that reads in a script file that describes the object and renders the 3D model from this script file. This gives you (the designer) full control over the modeling process and enables you to easily make designs that are defined by configurable parameters. (tutorial)
As an example of the power of this approach, you can take an existing parametric definition of a USB drive enclosure (like this one or this one) and modify the dimension parameters with those of a Super Wi-Fi Duck!
ADDITIONAL RESOURCES
Enjoy this introduction to BadUSB exploits and defenses.
ATmega32U4 Touch Key Module
The ATmega32U4 microcontroller is most familiar for its application on Arduino Pro Micro modules used in keyboard and macropad projects like the ones found in HackerBox 0074 and HackerBox 0083. It's an easy microcontroller to apply in USB Human Interface Device (HID) projects serving as keyboard, mice, game controllers, etc.
For example, an early open source touch module featured here has the ATmega32U4 wired up for touch inputs that generate mouse and keyboard events. The design served as the hardware for the original MaKey MaKey educational tool. The latest version of which can be purchased, along with other educational goodies, from makeymakey.com. Here is a cool video about the original MaKey MaKey and various details, including the schematic, can be found here.
Programming the ATmega32U4 Microcontroller
- Connect the miniUSB port to your PC
- Open the Arduino IDE
- Select Tools > Board > Arduino AVR Boards > Arduino Leonardo
- Select the appropriate option under Tools > Port
- Open the sketch File > Examples > Basics > Blink
- Change LED_BUILTIN to 17 in all three locations
- Compile and upload the sketch
Manipulating the D17 output causes the two LEDs adjacent the mouse icons to blink in unison.
Next, switch all three locations of the sketch from I/O 17 to I/O 30 and reprogram the MCU. The two LEDs adjacent to the keyboard icons should be blinking in unison.
Examine the schematic (link above) to see how D17 and D30 (labeled PD5) are each connected to two LEDs.
From the schematic, decipher how to illuminate each of the six LEDs that show through the PCB by the setting I/O pins 9(PB5), 10(PB6), and 11(PB7) to the respective combinations of high and low.
The sketch for the original MaKey MaKey project can be found in this github folder if you wish to explore how the touch inputs were implemented for the ATmega32U4 microcontroller. As an advanced exercise, compare this with how touch input is implemented on the Raspberry Pi 2040 microcontroller.
For Those About to Hack...
We hope you are enjoying this month's HackerBox adventure into electronics, computer technology, and hacker culture. Reach out and share your success in the comments below or on other social media. Email support@hackerboxes.com anytime with questions or whenever you need some help.
Want more? Surf over to HackerBoxes.com and join us as a monthly HackerBox subscription member. You'll get a cool box of hackable gear delivered right to your mailbox every month and you'll enjoy a generous member discount.
Please consider sharing this free Instructable with others who may be interested in learning about these subjects. We really appreciate your support and "word of mouth advertising" is the greatest compliment that we can receive.