Author Archives: R-B

MAX7219 LED display driver for ESP8266

Here is an Instructable on writing a MAX7219 driver for interfacing an 8-digit seven segment LED to ESP8266 platform.

ESP8266 drives MAX7219 based seven segment display

ESP8266 drives MAX7219 based seven segment display

The MAX7219 are compact, serial input/output common-cathode
display drivers that interface microprocessors (µPs) to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers, and an 8×8 static RAM that stores each digit. Only one external resistor is required to set the segment current for all LEDs.

A convenient 4-wire serial interface connects to all common µPs. Individual digits may be addressed and updated without rewriting the entire display. The MAX7219 also allow the user to select code-B decoding or no-decode for each digit.

The devices include a 150µA low-power shutdown mode, analog and digital brightness control, a scan-limit register that allows the user to display from 1 to 8 digits, and a test mode that forces all LEDs on.

555 Timer as power usage sensor

Electricity meters usually have blinking LED lights whose flashing rate is associated with the amount of energy usage. This example shows how to use a 555 timer chip acting as Schmitt trigger combined with a phototransistor or LDR to sense the flashing LED on the electricity meter for monitoring electricity usage.

555 timer as power meter

555 timer as power meter

The output of the 555 timer chip is connected to one of the GPIO pins on the Raspberry Pi. A Python script (executing in the background) recording 555 events is calculating actual energy usage [e.g. Watt] every time the 555 is signaling and stores epochs in an SQLite3 database. From this, another Python script (executed from e.g. cron) generates all kinds of energy usage information (e.g. kWh or kWday or whatever). Using Node.js (running on the same Pi) all data is ‘RESTified’ enabling spreading out to the W3. To maintain privacy JSON web tokens are required every time the service is queried. Oh, and there is also a Pimatic plugin available (here)

ESP8266 MP3 decoder

This Github upload shows an example of how to use the I2S module inside the ESP8266 to output sound.

In this case, it is used to output decoded MP3 data (actually, more accurately: MPEG2 layer III data): the code described here basically is a webradio streamer which can connect to an Icecast server, take the MP3 data the server sends out, decode it and output it over the I2S bus to a DAC. The MP3 decoder has been tested for bitrates up to 320KBit/s and sample rates of up to 48KHz.

The biggest part of this code consists of a modified version of libmad, a fixed-point mp3 decoder. The specific version we use here has already been modified by NXP to use less memory (source:www.nxp.com/documents/application_note/AN10583.pdf) and has been massaged by Espressif to store as much constants in flash as possible in order to decrease RAM use even more. The MP3 decoder is fed from a FIFO realized in the external 23LC1024 SPI RAM. This RAM is filled from a network socket in a separate thread.

On the output side, the MP3 samples are fed into the I2S subsystem using DMA. The I2S DMA basically consists of a circular buffer consisting of a number of smaller buffers. As soon as the DMA is done emptying one of the smaller buffers into the I2S subsystem, it will fire an interrupt. This interrupt will put the buffer address in a queue.

When the MP3 decoder has a bunch of samples ready, it will pop a buffer off this queue and put the samples in it until it is full, then take the next buffer etc. The MP3 decoder generally is faster than the I2S output, so at a certain moment there will be no free buffers left. The queue system of FreeRTOS will suspend the mp3 decoding task when that happens, allowing the ESP8266 to attend to other tasks.

Hacking a bathroom weighscale for cloud connectivity

Hardware hacker Darrel Tan has a great write-up about his experience with hacking a Chinese-made bathroom scale for cloud connectivity using a Raspberry Pi. His bathroom weighscale has a separate display part that receves the weight measurements from the scale through an infrared link. Darrel hooked up an 38kHz IR receiver to the logic analyzer and placed it near the scale as he was standing on it, so that he could decode the IR bursts. He found that the device used pulse distance coding to encode the data with ~75ms spacing between the consecutive bursts. With further analysis, he was able to figure out how ones and zeros are transmitted and how the weight data is represented in the transmitted stream between the scale and display. After the most difficult part of the hack done, he then hooked up a Vishay TSOP4138 IR receiver to one of the Raspberry Pi’s I/O pins to send the data to the Google Spreadsheet for recording and future plotting.

hh

Hacking a bathroom weighing scale for cloud connectivity

ATtiny85 based mini weather station

This Instructable describes a mini weather station using ATtiny85 and DHT11 sensor. It consists of TX and RX units with a 433MHz RF link to connect them. The TX unit sends temperature and humidity measurements to RF module, which then displays the data on an LCD.

Mini weather station

Mini weather station

In a recent instructable Indigod0g described a mini weather station that works pretty well, using two Arduinos. Maybe not everyone wants to sacrifice 2 Arduinos to get humidity and temperature readings and I commented that it should be possible to do a similar function with two Attiny85’s. I guess talk is easy, so I better put my money where my mouth is.

In fact, if I combine two earlier instructables I wrote:

2-Wire LCD interface for Arduino or Attiny
and
Receiving and sending data between Attiny85 (Arduino IDE 1.06)
then most of the work is already done. Only need to adapt the software a bit.

I chose for a two wire lcd solution with a shift register, rather than an I2C LCD because on the Attiny the shift register is easier to implement than the I2C bus.

« Older Entries Recent Entries »