HackerBox 0075: AV Club

by HackerBoxes in Circuits > Microcontrollers

4621 Views, 10 Favorites, 0 Comments

HackerBox 0075: AV Club

Whole Box HB0075.png

We are proud to present HackerBox 0075. Get ready to configure tools for programming the ESP32 D1 Mini Microcontroller featuring Wi-Fi, Bluetooth, and a number of other powerful interface blocks. Integrate the ESP32 D1 Mini with the AV Club Printed Circuit Board as a platform to explore a number of audio/video hacks that exploit structures of the ESP32 SoC. Experiment with a number of peripheral devices including a color display module, a 3.5mm audio/video output jack, an I2S digital audio converter with integrated amplifier, a microSD card slot, and two USB sockets that can be configured to support soft USB host ports and keyboard interfaces. Leverage signal conversion hardware to render composite video and audio signals onto modern HDMI media channels.

HackerBoxes is the monthly subscription box of 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

Assembled HB0075.png

This Instructable contains information for getting started with HackerBox 0075. The full box contents are listed on the product page for HackerBox 0075 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 with a $15 discount, you can subscribe at HackerBoxes.com and join the party!

A soldering iron, solder, and basic soldering 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 basic tools and 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.

Audio/Video Hacks

Bitluni Brings All the ESP-32 Multimedia Hacks to Supercon

 The ESP32 has some interesting internal structures that allow for some crazy multimedia hacks: sound buses used for video signaling, direct memory access (DMA) pipes, complex digital to analog converters, and even some rather elaborate hacks for bit-banging soft USB host ports within a microcontroller that doesn't technically have hardware USB support.

When exploring these techniques, let's remember that most of them are quite elaborate hacks. They do not always behave perfectly, but we can learn a lot from how they are implemented.

Zipper Bag of Small Parts

Parts Bag.png

The zipper bag of small parts contains several items. In addition to the zipper bag, there is also a 40-pin male header that is useful for assembling the AV Club Kit.

The surface mount resistors and capacitors are 1206 sized, which is relatively large by SMD standards. They should not be too challenging to solder. Take care when identifying the two single capacitors. The 10uF capacitor is packaged in a clear plastic strip while the 10nF capacitor is packaged in a white cardboard strip. While they look very similar, the 10uF capacitor is noticeably thicker than the 10nF capacitor.

The small SMD components can sometimes be hiding inside the USB sockets. If so, you must arm yourself with tweezers and bravely venture within to rescue the captive components. You can also just shake them out, but that doesn't sound quite as cool.

ESP32 D1 Mini

ESP32 D1 Mini Pinout.png

This ESP32 is a low-power SOC (system on chip) microcontroller with integrated Wi-Fi and dual-mode Bluetooth. It features a dual-core Tensilica Xtensa LX6 microprocessor.

In this Step we will configure and test the tools to program the microcontroller. This should be done without soldering any of the pin headers onto the module. The only connection that needs to be made is attaching a microUSB cable to the module and plugging the cable into your computer.

First, follow these instructions to setup the Arduino IDE and configure the ESP32 Board Support Package within the Arduino IDE. Preferably, use the procedure outlined on that page under "Installing using Boards Manager" since that is the quickest and easiest method.

After restarting the IDE, select:

Tools > Board > ESP32 Arduino > WEMOS D1 MINI ESP32

Open the example sketch:

File->Examples->Basics->Blink

Compile and upload the sketch to the ESP32 by clicking the UPLOAD button (the arrow icon) just above the sketch code.

Once the upload is complete, the BLUE LED on the ESP32 module should be slowly blinking.

Looking closely, you can see that the sketch code turns the LED on, waits 1000 milliseconds (one second), turns the LED off, waits another second, and then loops to do it all again - forever.

Modify the sketch by changing both of the "delay(1000)" statements to "delay(100)". This modification will cause the LED to blink ten times faster, right?

Load the modified code into the ESP32 by clicking the UPLOAD button again. Once the upload is complete, your BLUE LED should be blinking much faster.

This is how code is written (modified in this case) and uploaded to the ESP32 to be run.

AV Club PCB

Schem for PCB.png

The AV Club Printed Circuit Board (PCB) serves as a platform to connect the ESP32 microcontroller module with a number of peripheral devices. These include a color display module, a 3.5mm audio/video output jack, an I2S digital audio converter with integrated amplifier, a microSD slot, and two USB sockets that can be configured to support various I/O modes.

There are a lot of I/O pins on the ESP32, but they are not all completely available at all times. Some I/O pins are input only, some have special functions during power-up, some are used by the integrated flash memory, and so forth. So how do we select which ESP32 I/O pins to use for what? This tutorial is a great resource to review when making such decisions, especially for a design like the AV Club PCB where the available I/O pins are being stretched to their limit connecting the ESP32 to numerous peripherals.


Initial Assembly of AV Club PCB

PCB and SMD on Back.png

Always start assembling a PCB with the smallest components first. In this case, start with the surface mount devices (SMDs) on the back side of the AV Club PCB.

AV Output

Solder three components (all three can go either direction):

  • The 10uF capacitor (packaged in clear plastic tape) goes onto the pads labeled C1
  • The 10nF capacitor (packaged in white paper tape) goes onto the pads labeled C2
  • One of the five 1K resistors goes onto the pads labeled R5

Two USB Sockets

There are a few options for configuring use of the USB sockets and the associated I/O pins. The suggested configuration makes one of the ports a "soft USB" host port and puts the other into a PS/2 keyboard mode. This is the suggested configuration because it is the most interesting and versatile. If you want to wait and consider the other USB options later, just leave R1, R2, R3, and R4 unpopulated for now. To follow the suggested configuration follow the four bullets below:

  • One of the five 1K resistors goes onto the pads labeled R1
  • One of the five 1K resistors goes onto the pads labeled R2
  • A short of solder (or wire) goes onto the pads labeled R3
  • A short of solder (or wire) goes onto the pads labeled R4

Four Adhesive Silicon Feet

Apply these feet to the corners on the underside of the PCB. The underside shows the small SMD components discussed above.

Integrate ESP32 and AV Club PCB

ESP32 D1 Mini with Headers.png

Mounting the ESP32 module to the AV Club PCB uses some of the pin headers that came in the static bag with the ESP32 module as well as the extra 40 pin header.

Option 1 - Socketed ESP32 Module:

Solder four 1x10 male header sections to the ESP32 module. Position the male headers such that the black insulator and the long sides of the pins are on the back of the module (opposite from the USB connector) and the small sides of the pins extend up through to the front of the module (the side with the USB connector).

Solder all four 1x10 female headers onto the PCB extending from the top of the PCB through to the bottom of the PCB where the silicon feet are. The pins can be trimmed off the bottom side of the PCB so that they are all flush, or nearly flush, against the bottom of the PCB.

The ESP32 can now be plugged into the female headers on the PCB. It can also be unplugged and connectors (such as female DuPont jumpers) can be used to access the male header pins separately from the AV Club PCB.

Option 2 - Permanent, Flush-Mounted ESP32 Module:

Solder four 1x10 male header sections to the ESP32 module. Position the male headers such that the black insulator and the long sides of the pins are on the back of the module (opposite from the USB connector) and the small sides of the pins extend up through to the front of the module (the side with the USB connector).

Set aside the four female header sections and position the ESP32 directly onto the AV Club PCB. Solder the pins of the ESP32 module directly to the AV Club PCB. The pins can be trimmed off the bottom side of the PCB so that they are all flush, or nearly flush, against the bottom of the PCB.

Wire Jumper:

For the suggest USB configuration, connect a wire jumper between I/O pin 33 and I/O pin 12(TDI), as shown. With these two pins connected together, take caution to always leave IO33 unconfigured (making it an input) to avoid cross-driving outputs from IO33 and IO12.

SAFETY NOTE: WHENEVER CUTTING PINS OR WIRE LEADS, ALWAYS WEAR PROTECTIVE GLASSES

Full Color IPS Display Module

Color LED.png

This 1.3-inch color display features 240 x 240 resolution. It can display 65,000 full, rich colors. In-plane switching (IPS) technology provides a super wide viewing angle. The display module's ST7789 chipset supports a 4-line SPI bus interface to the microcontroller.

Information page on LCD Wiki

The display module comes with a seven pin header already attached. Use this header to solder the display module onto the AV Club PCB seven. Once soldered into place, the pins can be carefully trimmed down.

In the Arduino IDE, use Tools > Manage Libraries to search for and install the TFT_eSPI library.

Next, find the Arduino/libraries folder on your PC. Under that, go into the TFT_eSPI folder and open up the file named "User_Setup.h" for editing.

Under // Only define one driver, the other ones must be commented out

Use this one (by uncommenting it and leaving the others commented out):

#define ST7789_DRIVER 


Under // For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation

Use these settings:

#define TFT_WIDTH 240

#define TFT_HEIGHT 240 


Under // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP  ######

Use these settings:

#define TFT_MISO -1

#define TFT_MOSI 23

#define TFT_SCLK 18

#define TFT_CS  -1 // Chip select control pin

#define TFT_DC  5 // Data Command control pin

#define TFT_RST  19 // Reset pin (could connect to RST pin)

#define TFT_BL  15 // LED back-light


Near the bottom of the file, uncomment the following line:

#define USE_HSPI_PORT


After all of these updates, save the "User_Setup.h" file.


Open and upload an example sketch that came with the TFT_eSPI library.  

This one works well: 

File > Examples > TFT_eSPI > 320 x 240 > TFT_Clock

MAX98357A I2S Audio Converter and Amplifier Module

MAX and AMP.png

The MAX98357A accepts a digital audio stream through a I2S interface, converts it to an analog output signal, and amplifies it to allow direct connection to an audio speaker.

Configure the Hardware

Solder the module onto the AV Club PCB using the seven pin header.

The tiny speaker can be affixed to the PCB using double-sided tape or hot glue.

The wire leads from the speaker can be soldered directly to the audio module or connected using the provided screw terminal. The red wire connects to the "+" terminal and the black wire connects to the "-" terminal.

If you notice popping, or other instability in the speaker output, it might help to set the amplifier gain. This can be done by connecting to GAIN pin to the GND pin on the MAX98357A module. It is probably easiest to connect a short piece of wire onto the backside of the PCB at the header for the MAX98357A module.

Configure the Software

Download and install this ESP32-audioI2S Library.

Open the sketch File > Examples > ESP32-audioI2S > I2Saudio

Change the pin settings to match the AV Club PCB like so:

#define SD_CS      22
#define SPI_MOSI   17
#define SPI_MISO   16
#define SPI_SCK    21
#define I2S_DOUT   14
#define I2S_BCLK   27
#define I2S_LRC    32

Put the SSID and Wi-Fi Password into the sketch where shown. (must be a 2.4GHz WLAN)

Uncomment the "connect to speech" line. This uses google text to speech to generate an audio stream.

Modify the function parameters to try something in English:

audio.connecttospeech("Hack the Planet", "en");

Stream an Internet Radio channel. For example, uncomment and modify a connect to host option like so:

audio.connecttohost("http://somafm.com/defcon.pls");

In any of these cases, you can observe what is happening through the Serial Monitor.

MicroSD Module and File Access

MicroSD.png

The same sketch from the last Step can play an audio file (such as an MP3) from a microSD card.

Solder on the microSD reader module onto the AV Club PCB using the six in header.

Put an audio file on a microSD card. (You can get some free MP3 files here.)

Uncomment an SD line in the sketch and specify the file name for the audio file on the card:

audio.connecttoFS(SD, "test.mp3");

USB Sockets

USB Socket.png

USB1 (Left USB Socket - Closest to the ESP32)

The suggested configuration sets USB1 for PS/2 keyboard mode.

This mode only works for keyboards and specifically only PS/2 keyboards that are designed to internally operate on either a USB port or a PS/2 port. The easiest way to identify such keyboards is that they generally have a USB connector on their cables but then also come supplied with a passive USB PS/2 adapter like the one illustrated here.

For this suggested configuration, R1 and R2 are both populated with 1K Resistors. ESP32 I/O pin 0 connects to the D+ pin of the USB socket but is used as the PS/2 Keyboard Clock signal. ESP32 I/O pin 4 connects to the D- pin of the USB socket but is used as the PS/2 Keyboard Data signal. These clock and data signals can be decoded using the Arduino PS2 Keyboard Library.


USB2 (Right USB Socket - Furthest from the ESP32)

The suggested configuration sets USB2 as a "soft USB" host port.

For this suggested configuration, R3 and R4 are both shorted (zero ohms) and a wire jumper in placed between I/O pin 33 and I/O pin 12(TDI) of the ESP32 module. ESP32 I/O pin 13 connects to the D+ pin of the USB socket. ESP32 I/O pin 12 connects to the D- pin of the USB socket. The ESP32-USB-SOFTHOST code can be used to decode certain USB inputs after being modified to represent the following pin configuration:

#define DP_P0   13 
#define DM_P0  12 
#define DP_P1  -1
#define DM_P1  -1


Other USB Socket Options

To use both USB sockets as "soft USB" host ports, the best option is to leave off the microSD card reader to obtain the necessary addition pins. The I/O pin pairs 16/17 and 21/22 (from the microSD reader) can be wire-jumped directly to the USB socket D+/D- pins while leaving R1-R4 unpopulated. Consult the AV Club PCB schematic for additional information.

Alternatively, the four connecting pins supplied on the PCB for each USB socket present ESP32 I/O pins 0, 4, 13, and 33 as well as 5V and GND. These pins can be used for making other connections by simply leaving the USB sockets off and shorting the associated resistors pads R1-R4. Consult the AV Club PCB schematic for additional information.

Composite Video and Audio Output

AV.png

In addition to the three SMD components (C1, C2, and R5) attached earlier, the AV output also requires soldering the black 3.5mm jack onto the PCB.

The AV Cable featuring a 3.5mm on one end and three RCA connectors on the other end can be used to connect the AV output from the PCB to a television or monitor having a composite input.

In the Arduino IDE, use Tools > Manage Libraries to search for and install the ESP_8_BIT Color Composite Video Library.

Find the Arduino/libraries folder on your PC. Under that, go into the ESP_8_BIT Color Composite Video Library folder and open up the file named "ESP_8_bit_composite.cpp" for editing.

In that file, find the string "DAC_CHANNEL_1" in two different places and change that to "DAC_CHANNEL_2".

Under File > Examples > ESP_8_BIT Color Composite Video Library, select an example sketch to test the composite video generation. For example, the sketches GFX_HelloWorld and AnimatedGIF work very nicely.

For a quick test of Audio generation on the AV Output, visit this tutorial and test out the DAC sine wave generation sketch.

Audio/Video Conversion

AV2HDMI.png

Televisions and Monitors with Composite AV inputs are becoming less common. Thrift shops can help, but here are a couple of other options...

Audio/Video to HDMI Conversion: The AV2HDMI conversion box included in this HackerBox features the Macro Silicon MS1858E chip. The MS1858E is a single-chip CVBS/S-Video to HDMI converter that integrates 9-bit video ADC, 24-bit audio ADC, and an advanced HDMI 1.3 transmitter. The video converter chip is configured by an internal micro controller core.

Audio/Video to PC (via USB): Check out the USB Audio/Video Capture device in HackerBox 0061 and the associated Box Guide.


Happy 75th

outro.png

We hope you are enjoying the "Diamond Anniversary" HackerBox marking over 75 monthly adventures into electronics, computer technology, and hacker culture. Reach out and share your success in the comments below or other social media. Also, remember that you can email support@hackerboxes.com anytime if you have a question or need some help.

What's Next? Join the party... Live the HackLife! Get a cool box of hackable gear delivered right to your mailbox each month and enjoy a generous member discount. Surf over to HackerBoxes.com right now and sign up for your monthly HackerBox subscription.