HackerBox 0092: Inline

by HackerBoxes in Circuits > Arduino

4205 Views, 12 Favorites, 0 Comments

HackerBox 0092: Inline

HB0092 Whole Box.png

Welcome to HackerBox 0092. Explore inline hardware insertion for man-in-the-middle manipulation of both USB devices and composite video streams. Configure both the RP2040-One Development Board and an Arduino UNO Development Board for use with the Arduino IDE programming environment. Exploit Programmable Input Output (PIO) hardware blocks of the Raspberry Pi RP2040 microcontroller to bit-bang a USB host interface. Leverage the USB host interface to capture and alter USB keyboard signals. Assemble a video experimenter system capable of overlaying text and graphics onto composite video signals, capturing video frames for image processing and machine vision, and decoding closed captions and other data embedded within television signals. Understand and apply video signal conversion technologies.

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 0092. The full box contents are listed on the product page for HackerBox 0092 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. Subscribers save at least $15 every month and get each new HackerBox shipped immediately off of 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.

Arduino UNO-R3 ATmega328P

UNO.png

The Arduino UNO is a classic. Designed with easy of use in mind, the USB interface has even been upgraded to a Type-C port for this model.

Specifications:

  • Microcontroller: ATmega328P
  • USB Serial Bridge: CH340
  • Operating voltage: 5V
  • Input voltage (recommended): 7-12V
  • Input voltage (limits): 6-20V
  • Digital I/O pins: 14 (of which 6 provide PWM output)
  • Analog input pins: 6
  • DC current per I/O Pin: 40 mA
  • DC current for 3.3V Pin: 50 mA
  • Flash memory: 32 KB of which 0.5 KB used by bootloader
  • SRAM: 2 KB
  • EEPROM: 1 KB
  • Clock speed: 16 MHz

When the Arduino UNO is first plugged into a USB port of a computer, the red power indicator ("ON" LED) will light up. Almost immediately after that, a second red indicator ("L" LED) will start blinking. This blinking happens because the processor is pre-loaded with the BLINK program, which we will discuss further below.

If you do not yet have the Arduino IDE installed, you can download it from Arduino.cc and if you would like additional introductory information for working in the Arduino ecosystem, we suggest checking out the online documentation for the HackerBox Basics Workshop.

Plug the UNO to your computer using a USB-C cable. Launch the Arduino IDE software.

In the IDE menu, select:

Tools > Board > Arduino ADR Boards > Arduino UNO

and select appropriate USB interface under Tools > port

Finally, open the example sketch:

File->Examples->Basics->Blink

This is actually the code that was preloaded onto the UNO and should be running right now to blink the red user LED. 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?

Program the modified BLINK code into the UNO by clicking the UPLOAD button (the arrow icon) just above the displayed code. Watch below the code for the status info: "compiling" and then "uploading". Eventually, the IDE should indicate "Uploading Complete" and your LED should start blinking again, but much faster.

HEADER PINS

Set aside the header pins that come with the Arduino UNO. We'll definitely need six of the header pins for assembling the RP2040 Inline USB Kit and three of the pins for assembling the Video Experimenter Shield. Optionally, 28 of the header pins can be used for connecting the Video Experimenter Shield to the Arduino UNO as discussed below.

RP2040-One Development Board

RP2040-One.png

The RP2040-One Development Board is based on the Raspberry Pi RP2040 microcontroller (specifications). The RP2040-One also features 4MB of Flash storage, a WS2812 RGB LED, and an onboard USB-A Plug.

INITIAL HARDWARE STARTUP

Before soldering, or otherwise connecting, anything to the RP2040-One Development Board, perform the following startup tests and confirm programing something onto the microcontroller.

When the RP2040-One Development Board is initially plugged into a USB port, it will power on and the WS2812 RGB LED will cycle Red -> Green -> Blue.

After giving that a shot, put the RP2040-One into bootstrapping mode which can be done either of two ways:

Unplug the board, hold the BOOT button down while plugging the board back in.

OR

Hold the BOOT button down while hitting the RESET button.

In either case, a new storage device (drive) should appear on the computer with the name RPI-RP2.

CONFIGURE THE ARDUINO IDE

Setup the Raspberry Pi Pico Arduino core (for all RP2040 boards) as outlined here.

In the Arduino IDE, select: Tools > Board > Raspberry Pi RP2040 Boards > Waveshare RP2040 One

RGB LED MADNESS

In the IDE, use Tools > Manage Libraries to search for and install the Adadruit NeoPixel Library.

Load the example code strandtest.ino that comes with the library.

In the code, change LED_PIN to 16 and LED_COUNT to 1.

Upload and run the modified code, which should perform quite the show on the RP2040-One's onboard RGB LED.

HackerBox RP2040 Inline USB Kit

RP2040 USB Kit.png

The RP2040 Inline USB Kit is based on a small PCB that piggybacks onto the RP2040-One and provides a female USB-A socket. The USB-A socket is generally used as a USB host port that a USB HID (human interface device) such as a keyboard, mouse, or game controller can be plugged into.

The USB port on an RP2040 Inline USB assembly can be used to receive USB HID input as a typical host port. By extension, the RP2040 Inline USB assembly may be installed between a HID and a PC to operate as a man in the middle to capture, alter, or insert USB HID traffic.

PCB DESIGN

The PCB couples to six pins of the RP2040-One:

The 5V and GND pins of the RP2040-One are wired to the 5V and GND pins of the USB Socket.

I/O pins 10 and 11 of the RP2040-One are wired to the D+ and D- pins of the USB socket respectively.

I/O pins 0 and 1 of the RP2040-One are only connected to the PCB to increase mechanical stability.

KIT ASSEMBLY

  • Insert the USB connector onto the PCB where indicated. The HackerBox text logo should remain visible.
  • Bend the two strain-relief tabs of the USB connector toward the center of the PCB.
  • Trim the 4 pins of the USB connector flush to the PCB surface.
  • Solder both tabs and all 4 pins of the USB connector.
  • Place the RP2040-One onto the PCB to form a stack.
  • Place the RP2040-One on the same side of the PCB as the USB connector.
  • Be sure that the RP2040 chip is inside the PCB opening and the pin numbers align.
  • Remove six header pins from the Arduino UNO packaging.
  • Place one header pin (without the plastic insulator) into the 5V hole of the stack.
  • Solder the header pin on both sides.
  • Trim the excess header from both sides.
  • Repeat the last three steps for all six header pins.

Once assembly is complete, power the RP2040 Inline USB assembly by inserting the male USB end. The NeoPixel strandtest.ino code should still be operational.

USB HOST CODE

In the IDE, use Tools > Manage Libraries to search for and install the Pico PIO USB Library from sekigon-gonnoc.

In the IDE, use Tools > Manage Libraries to search for and install the Adafruit TinyUSB Library.

Configure the following IDE settings:

  • Tools > Board > Raspberry Pi RP2040 Boards > Waveshare RP2040 One
  • Tools > CPU Speed > 120MHz
  • Tools > USB Stack > Adafruit TinyUSB

Open the example sketch:

File > Examples > Adafruit TinyUSB Library > DualRole > HID > hid_remapper

Change the define value PIN_USB_HOST_DP from 16 to 10

In the setup() function, uncomment the line that starts with "while ( !Serial )"

Upload the modified code to the RP2040-One

Unplug the RP2040 Inline USB assembly and insert it between a USB keyboard and a PC. Any keys pressed on the keyboard will be intercepted and relayed to the PC with the case flipped. This demonstrates an active "Man in the Middle" operation of the RP2040 Inline USB assembly.

Note that TinyUSB Host Mode USB for RP2040 performs bit-banged USB via PIO as a bit of a firmware hack. It isn't always perfect, but it is quite impressive and works pretty well most of the time.

LOGGING USB OPERATIONS

This excellent discussion on storing data into the Flash memory of a RP2040 microcontroller might be of interest.

Video Experimenter Shield Kit

Video Experimenter.png

The Video Experimenter Shield was originally designed by nootropic design to plug onto the Arduino UNO. The shield supports various composite video experiments. The shield can be used to overlay text and graphics onto a video signal from another composite video source, such as a VCR, camera, or DVD player. It can also be used to capture video frames for image or vision processing, such as object detection. The Video Experimenter Shield can even decode closed captioning or other data embedded within television signals.

The Video Experimenter Shield is based on the LM1881 Video Sync Separator Chip (datasheet). The LM1881 Video Sync Separator is capable of extracting timing information from a video signal including composite and vertical sync, burst, or back porch timing. The LM1881 works with NTSC (Americas and Japan), SECAM (Russia, France, and West Africa), and PAL (most of the rest of the world) television standards.

ASSEMBLING THE SHIELD KIT

Start with the seven axial lead components since they are the "shortest" to the PCB. Note that the resistors in HackerBox 0092 have different colors and bands than those shown on the build notes from nootropic design, but if we check the marking against the color code calculator, we can verify that the values are actually equivalent.

  • R1: 680K = beige with bands: blue, gray, yellow, gold
  • R2:  330R = beige with bands: orange, orange, brown, gold
  • R3: 1K = beige with bands: brown, black, red, gold
  • R5: 20K = beige with bands: red, black, orange, gold
  • R6: 75R = blue with bands: violet, green, black, gold, brown
  • D1, D2: orient the black band on each diode with the marking on the PCB

Tantalum Capacitors (C1, C2, C3) are polarized. We suggest using the orientations shown in the image above by placing the positive (long) lead of each capacitor into the through hole marked with a "+" in the diagram.

Output Select Switch and Reset Button: These can be inserted in either orientation.

Two potentiometers: These only fit correctly in one direction.

Sync Select: This "switch" is make from three header pins and a jumper block. The three header pins should be obtained from the Arduino UNO packaging.

LM1881 Chip and DIP Socket: 8-pin DIP socket should be oriented such that the notch on one end matches the notch in the silkscreen marking. Later, the LM1881 chip can be inserted into the socket observing the same notch orientation.

Two RCA Sockets: The rear post of each connector is a little wide for the mounting hole. The post can be deformed or carefully trimmed to ease the fit. Once the connector is fully seated, bend the post tabs flat against the PCB for solid mechanical retention and then solder the tabs in place.

UNO-Shield Coupling Headers: The yellow stacking headers can be used here. Optionally, 28 of the plain male header pins in the Arduino UNO packaging can be soldered onto the bottom of the shield. If you do not plan to stack onto the Video Experimenter Shield, using the plain headers gives a tighter finish and the stacking headers can be saved for a future project.

VIDEO EXPERIMENTER CODE

Basic video generation and overlay can be performed using the traditional TVOut Arduino Library.

Advanced features of the Video Experimenter Shield benefit from use of the enhanced TVout Library as described here (bottom of the nootropic Video Experimenter page). Note that this enhanced library repo includes three different folders that need to be placed into the Arduino Libraries folder.

The enhanced library comes with some interesting examples as outlined on the Video Experimenter Projects Page.

HDMI-to-AV Video Converter

HDVI2AV.png

HDMI to Audio/Video Conversion: The HDMI2AV conversion box included in this HackerBox features the Macro Silicon MS1836S chip. The MS1836S is a single-chip HDMI to CVBS/S-Video converter configured by an internal micro controller core.

This converter is useful for exploring the Video Experimenter Shield since most modern video devices output HDMI video signals instead of composite video signals. When no HDMI signal is being input to the converter box, it will generate a color bar screen on the composite video output. This can serve as a composite video source all by itself for initial video experiments.

Other video conversion solutions found in previous HackerBoxes include:

Audio/Video to HDMI Conversion: Check out the AV2HDMI conversion box in HackerBox 0075 and the associated Box Guide. The AV2HDMI conversion box features the Macro Silicon MS1858E chip.

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

Technology Is Man Amplified

Clock DVA - Man Amplified (1992)

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 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 and 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 to sign up for your monthly HackerBox subscription.

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!