HackerBox 0065: Realtime
by HackerBoxes in Circuits > Electronics
9679 Views, 19 Favorites, 0 Comments
HackerBox 0065: Realtime
Greetings to HackerBox Hackers around the world.
Working with HackerBox 0065, we will configure an ESP32 development board for use with the Arduino IDE. Explore Realtime system design and implementation leveraging FreeRTOS and a dual-core embedded processor. Assemble the HUB75 Blaster for interfacing with high density LED Matrix Panels. Implement a high-accuracy digital clock system using a 64x32 LED matrix assembly. Experiment with embedded real-time clocks, network time protocol, and microSD flash memory storage.
HackerBoxes is the monthly subscription box for enthusiasts of electronics and computer technology - Hardware Hackers - The Dreamers of Dreams.
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 0065. The full box contents are listed on the product page for HackerBox 0065 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 revolution!
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 Deluxe Starter Workshop for a set of basic tools and a wide array of introductory activities and experiments.
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.
Small Object Warning
Be careful when opening the parts bag in HackerBox 0065. There is one small 10uF SMD capacitor hiding in there and it may just disperse like dust in the wind if you don't keep an eye out for it.
The capacitor is actually a 1206 size component, which is pretty huge in the SMD world, but it's a lot smaller than the other items in the bag. Luckily, this capacitor is not vital to operation, so don't worry if it's already blown away. We'll learn more about that later.
"You're killin' me Smalls."
ESP-WROOM-32 Development Kit and the Arduino IDE
The ESP32 is a single chip computer. It is highly integrated featuring 2.4 GHz Wi-Fi and Bluetooth. The ESP32 integrates the antenna switch, RF balun, power amplifier, low noise receive amplifier, filters, and power management modules. As such, the entire solution occupies minimal Printed Circuit Board (PCB) area.
There are a few types of ESP32 Development Boards. The one used here is a variation on the "DOIT ESP32 DevKit". It is one of our favorites and has been widely tested in various maker/hacker applications. Most of the SoC's I/O pins are run out to the pin headers on both sides for easy interfacing. A USB interface chip and voltage regulator are integrated into the module. The ESP32 is supported within the Arduino ecosystem and IDE, which is a very quick and easy way to work with the ESP32.
PROGRAMMING THE DEVELOPMENT BOARD
Make these initial tests of the ESP32 board BEFORE connecting anything to any of the pins. You'll only need a microUSB cable to interface the board to your computer.
If necessary, download the Arduino IDE software and set up the ESP32 support package in the Arduino IDE.
Under tools>board in the Arduino IDE, select the "DOIT ESP32 DEVKIT V1" which is the same board used in the link above.
As an initial test, you can try the WiFiScan sketch as shown in the link, or stick with the traditional LED "blink" sketch. Either way, make sure you can compile, flash, and run a sketch on the ESP32 before connecting the module to anything else.
TIMEOUT TROUBLESHOOTING
You may get a timeout error while attempting to program the ESP32 as if it just never makes a connection with your computer. This timeout problem can be mitigated as explained in the link above. On that page, scroll down to the "Troubleshooting" heading and read about how to use the BOOT and ENABLE buttons during the flashing process. We will get a more permanent fix for this later thanks to a 10uF capacitor on the HUB75 Blaster Board that we'll be assembling in a bit.
Realtime Operating Systems
A Realtime Operating Systems (RTOS) is often a lightweight operating system (OS) designed to run on microcontrollers. Much like general purpose operating systems, they offer a scheduler to run multiple threads or tasks, resource management (such as file I/O), and device drivers. An RTOS is necessary when embedded engineers need to run several threads at the same time on a processor.
The “real-time” part of an RTOS means that such software can meet real-time deadlines. Note that this does not mean “fast,” but rather, it can guarantee that task execution time can be calculated prior to runtime.
FreeRTOS is an RTOS for microcontrollers and small microprocessors. It was developed in partnership with the world’s leading chip companies over a 18 year period. Distributed freely under the MIT open source license, FreeRTOS includes a kernel and a growing set of libraries suitable for use across all industry sectors. With one download every 170 seconds, FreeRTOS is built with an emphasis on reliability, accessibility, and ease of use.
Digi-Key produced this series of videos to cover various RTOS concepts and provide demonstrations on the ESP32 using Arduino. After each videos, a challenge exercise is issued. The challenge's solution can be found in a Maker.IO link provided in the video’s description. We encourage you to try the challenge without looking at the solution.
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)?
Introduction to RTOS Part 2 - Getting Started with FreeRTOS
Introduction to RTOS Part 3 - Task Scheduling
Introduction to RTOS Part 4 - Memory Management
Introduction to RTOS Part 5 - Queue
Introduction to RTOS Part 6 - Mutex
Introduction to RTOS Part 7 - Semaphore
Introduction to RTOS Part 8 - Software Timer
Introduction to RTOS Part 9 - Hardware Interrupts
Introduction to RTOS Part 10 - Deadlock and Starvation
Introduction to RTOS Part 11 - Priority Inversion
Digi-Key will be putting out additional parts to this RTOS series, so keep an eye peeled on their YouTube channel or other social media.
If you've never shopped with Digi-Key before, they're a great resource for finding countless electronic components, which they can usually get delivered to us very quickly. There are so many components on the Digi-Key site that it can often be overwhelming to find exactly what you need. Ladyada, the founder of Adafruit, has made some videos tagged with "the great search" where she shares her expertise in finding a part she needs from Digi-Key. Here is a search for an inductor. Here's a search for a screw terminal block just like the one we'll be using in this very box guide.
HUB75 Blaster
The HUB75 Blaster is a PCB that supports interfacing the ESP-WROOM-32 Development Board and the Data Logger Shield onto the backside of various HUB75 RGB LED Panels. It was inspired by previous work by Rorosaurus.
Assemble the HUB75 Blaster
You'll have a number of options while assembling the HUB75 Blaster. Read through the discussion for each component carefully so that you can choose your adventure wisely.
The HUB75 Connector
Only one component goes on the bottom side of the PCB. That is the 2x8 female header. Start assembly by soldering that header into place. It is definitely not optional. If you happen to have the keyed version of this header (most do not bother with this), be sure to orient the 2x8 female header such that the keying-block faces the notch in the silkscreen outline. Note that we're soldering this header on first, but we are not connecting it into the LED Matrix yet. That comes in a later step.
All of the other components go on the top side of the PCB...
SMD Capacitor
Remember the troubleshooting note, a few steps back, about using the buttons on the ESP32 board to fix the timeout problem during the flashing process? This 10uF SMD Ceramic Capacitor is here to help out with that. It is totally optional, so if you hate soldering SMD parts or lost it when you opened the parts bag, don't give it another thought. If you do want to place the SMD cap, remember that ceramic caps are not polarized, so you can place it in either direction. With the 10uF cap in place, you shouldn't have to press the BOOT and/or ENABLE buttons on the ESP32 board when you flash its program memory. [read more here]
Twin-Terminal Screw Blocks
The two screw terminal blocks are for connecting 5V Power and Ground. They should be soldered so that the ports for inserting power leads face out away from the Blaster. If you want a thinner finished product (for example, if you want to mount it onto a wall or panel) you can leave these screw blocks off and just solder the power lead(s) directly onto the PCB.
Electrolytic Capacitor
The 1000uF cap is for power smoothing on the 5V rail. There are a good number of similar decoupling capacitors already on the LED Matrix, so this one should be entirely unnecessary. However, there it is if you need it. Electrolytic capacitors are polarized so be sure to note the negative terminal "-" marking on the capacitor, the longer "+" lead, and the polarity makings on the PCB silkscreen. As always, do the right thing.
ESP32 Development Board
The ESP32 module can be soldered directly to the HUB75 Blaster (if you want a thinner finished product) or the supplied 15 pin female headers can be used to make the ESP32 removable. Even if you opt to not make it removable, it can still be reprogrammed in place. The Blaster PCB silkscreen shows two of the corner pin labels from the ESP32 Board. Match these two pins up to properly orient the module onto the Blaster.
RTC Data Logger Shield
Start by soldering the two supplied 8 pin male headers onto the RTC module. Insert the "short end" of the header in from the board side with the battery clip so that the short side of the pins barely protrude from the board side with the SD slot. The black plastic strip of the header should remains on the board side with the battery clip and the longer pins should extend therefrom.
Next, the RTC module can be soldered directly to the HUB75 Blaster (if you want a thinner finished product) or the supplied 8 pin female headers can be used to make the RTC module removable. Socketing the RTC module so that it is removeable will make it a bit easier to access the coin cell and the microSD card. However, if both the ESP32 and the RTC module are soldered flush to the Blaster, the microSD can still be wiggled in and out (tweezers may help) and the coin cell can be accessed from the edge of the Blaster.
The Blaster PCB silkscreen shows two of the corner pin labels from the RTC module. Match these two pins up to properly orient the module onto the Blaster.
Data Logger Shield - Real Time Clock (RTC)
This Data Logger Shield includes both a Real Time Clock (RTC) and a MicroSD Card Slot.
The RTC portion of the module features a DS1307 RTC chip (datasheet). The DS1307 manages all timekeeping functions. It uses a simple two-wire I2C interface and incorporates a battery input to maintain accurate timekeeping even when power is switched off.
The I2C bus interface between the ESP32 and the DS1307 uses only two signal wire (along with 3.3V and GND). The two lines are CLOCK (SCL) which is wired to ESP32 pin D13 and DATA (SDA) which is wired to ESP32 pin D14.
To access the DS1307 from an Arduino sketch, set up RTClib in the Arduino IDE.
Menu to Tools > Manage Libraries
Search for RTClib by Adafruit and install the library.
After installation, go to the library folder and open the file RTClib.cpp
Find the function
boolean RTC_DS1307::begin(void)
Change Wire.begin() to Wire.begin(14, 13)
This will force the I2C bus functions to operate on pins D14 and D13 as presented above.
For a demonstration of accessing the RTC chip, run File > Examples > RTClib > ds1307
Data Logger Shield - MicroSD Card
The MicroSD card Interface connects to the ESP32 using four pins...
- CS connects to pin D23 of the ESP32
- CLK connects to pin D32 of the ESP32
- DI connects to pin D33 of the ESP32
- DO connects to pin D34 of the ESP32
The test_sd.ino sketch (file attached here) uses these pin assignments to demonstrate writing and reading back various sized files from a microSD flash card.
Downloads
RGB LED Matrix
The LED Matrix features 2,048 full-color RGB LEDs arranged in a 64x32 matrix. These panels are the same type of panels used in jumbo LED displays as you can probably tell from the industrial strength power harness and threaded mounting holes. The RGB LEDs are arranged on a 2.5mm pitch grid (note the P2.5 designation) and the interface supports the HUB75 standard.
POWER SUPPLY
Do not power the LED Matrix through the ESP32 board's MicroUSB port. OK, now that you've heard that rule, there is one possible exception. It may be possible to run the clock demo below through the MicroUSB supply because it only uses less than 10% of the LEDs, and the brightness is coded to 35%. In contrast, if you set all 2,048 LEDs to white and turn the brightness up to 100%, the LED matrix panel will draw several Amps on the 5V rail and the ESP32 module (and probably whatever it is being powered by) will weep salty, salty tears.
A power supply like this one might be a good choice. It can provide 5A on 5VDC and offers a screw terminal connection option. Another nice solution if you have an extra PC power supply sitting around is to use the 5V rail from that supply. You could even grab a Power Up themed HackerBox 0039 to use the ATX power breakout board.
The nice fat wiring harness provided for power can carry quite a bit of current and it has two nice connection styles. There are many options for how to supply power that depend upon what connectors are on your power supply, what you want the final product to look like, and how easily you want it all to be disassembled. Don't be afraid to cut the power harness in half (or otherwise) to use the fat power wires however you like. Basically you need to construct a mini power grid with three points:
- The screw terminals on the HUB75 Blaster
- The 4-Pin Power Header on the LED Matrix
- The Power Supply
You need to get at least one red and one black fat wire to each of those points. The screw terminals can serve as a junction point since there are two ports for each 5V and Ground. The spade lugs or bare (preferably tinned) wires can be tightened into the screw terminals. Here are a few example solutions:
Example 1: Probably the quickest solution is to plug the power harness into the four-pin power header on the LED Matrix, and then tighten the spade lugs into the screw terminals along with two other (thick) wires that continue onto your (beefy) 5VDC power supply.
Example 2: Probably the best example if your power supply has screw terminals. Plug the power harness into the four-pin power header on the LED Matrix, cut the harness about four inches from the white four pin connector, tighten the spade lugs onto your (beefy) 5VDC power supply, strip and tin all the cut ends (from both the LED Matrix and the Power Supply), and then tighten them together into the screw blocks of the HUB75 Blaster.
Example 3: Some "low profile" solutions: Follow either example 1 or 2 but cut off (and discard) the white four-pin power connector and solder the cut end of those wires to the LED Matrix PCB right at the base of its Power Header.
For any of these solutions, it is probably safe to only use one pair of fat wire (one red and one black) for each "leg" of the mini power grid and then reuse the other pair for the second leg. Thus the three points can be interconnected using only the wire in the provided harness. If you are going to drop a leg down from two parallel wires to only one wire, try to make the connections as short as possible. Remember that the resistance of a conductors goes up like L/A (length over cross-sectional area) and resistance equals heat and waste.
CONNECTING THE HUB75 BLASTER
The HUB75 Blaster can be coupled to the "input" 2x8 pin header on the LED Matrix. There are two 2x8 headers on the LED Matrix. The input header is the one with a white arrow pointing towards the power connector. Orient the Blaster PCB such that the notch in the silkscreen rectangle around the female 2x8 pin header matches up to the notch in the male 2x8 pin header shroud. This should place the ESP32 closest to the power connector on the LED Matrix. Look at the mated headers under the HUB75 Blaster from each side to make sure that you cannot see any unmated pins. This will confirm that the male and female headers are correctly aligned between the top and bottom of the LED matrix.
ARDUINO LIBRARY AND CLOCK DEMO SKETCH
Set up the SmartMatrix Library using the Arduino Library Manager and then try out the HB0065_Clock.ino sketch attached here. There are also some nice example sketches that come with SmartMatrix under:
Files > Examples > SmartMatrix
To use those, just uncomment the include statement for ESP32 and change MatrixWidth from 32 to 64.
Downloads
Network Time Protocol
Do you want even more accurate time?
The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks. In operation since before 1985, NTP is one of the oldest Internet protocols in current use. NTP is intended to synchronize all participating computers to within a few milliseconds of Coordinated Universal Time (UTC). It uses the intersection algorithm to select accurate time servers and is designed to mitigate the effects of variable network latency. NTP can usually maintain time to within tens of milliseconds over the public Internet, and can achieve better than one millisecond accuracy in local area networks under ideal conditions.
Here's a nice example project demonstrating NTP for ESP32 projects.
NFTs, Pop-Tarts, Nyan Cats, and Blockchain - OH MY
By now, we all know that transactions of cryptocurrencies (Bitcoin, Ethereum, Monero, Dogecoin, etc.) are recorded and protected by a cryptographic blockchain.
Sidebar: The 10 Most Important Cryptocurrencies Other Than Bitcoin
Like traditional currency, units of cryptocurrencies are fungible. One dollar is worth the same as any other dollar, and one bitcoin is worth the same and any other bitcoin. In contrast, singular objects like the Mona Lisa, sports memorabilia, an antique, internet domains, or (most) houses are non-fungible because there are either no other objects exactly like them and/or they are not easily interchangeable with other objects.
Just as the transaction of some bitcoins (fungible) is recorded in a blockchain, so too the transfer of title to a piece of real estate or artwork (non-fungible) can be recorded in a blockchain. Great idea. Blockchain is a nice decentralized, public, non-repudiation mechanism. Why not? (Well it does consume a lot of electricity, but we'll save that story for another day.)
So how about recording creation and transactions of digital artifacts (e.g. animated Pop-Tart cats) in the blockchain? OK sure, but what does it mean to own a token tied to a digital object than anyone can view or download all over the web? Welcome to the wild world of the non-fungible token (NFT).
With notable example of the recent $69 Million sale of a Beeple JPG, NFTs are the crypto-craze du jour. Trust your technolust and learn more about them. Make some of your own. Or don't. "If you choose not to decide, you still have made a choice." Regardless, you do now posses an exclusive HackerBox Embroidered Nyan Cat Keychain, which is sure to skyrocket in value. (not actually sure)
Cryptoilluminati
>> forged in the chain - with all of my gang - decentralized and elite <<
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 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.