Pages

24.8.13

I2C LED Display From Hacked Voltmeter

LED voltmeters are a cheap source of 7 segment displays and can easily be repurposed. Using the I2C protocol, a master microcontroller such as an Arduino Uno can govern multiple displays with just 2 I/O pins.



Hello, Pleased to Meter You


The Adafruit 4-digit 7-segment LED backpack is a handy little board, and Ladyada's tutorial and Arduino library make it a snap to use. It's as easy to connect 8 displays as a single one: just set them to have different slave addresses and hook them all up to your Arduino's I2C pins. The trouble is that 8 displays will set you back around $80 (or a little more if you like the colour blue).

Looking around for an alternative, I discovered an internet retailer selling cheap LED voltmeters with slightly smaller displays. The listing titles mentioned "Stm8s003", the name of a series of small microcontrollers. For around $30 I bought myself 8 of the voltmeters and the STM8S discovery development board to reprogram them with. Similar voltmeters are available elsewhere, including eBay.

Then I had the most amazing stroke of luck. While I was waiting for the voltmeters to ship from the Far East, I came across an excellent blog post documenting a very similar project. The author had done an amazing job of writing firmware that would emulate the Adafruit board so that the hacked voltmeter would be compatible with the existing Arduino libraries. The hard work had all been done for me. All that remained to adapt the firmware to the slightly different voltmeter that I would be using.



Hardware


The voltmeters accepted between 3.5V to 30V on the red (V+) and black (V-) wires. On the reverse of I identified a voltage regulator that provided 3.3V to the STM8S003F3P6 MCU which drives the LEDs.



One or two of the voltmeters looked slightly different with a trimmer resistor for R3 and and extra capacitor C1:



With soldering iron and tweezers in hand, I sacrificed one of the voltmeters to recreate the schematic as best I could. The hardware I2C pins on the MCU were both in use, but it was apparent that pins 19 and 20 on the MCU could be reassigned to bit bang the I2C protocol.



Next up, a step-by-step surgery guide to repurposing the voltmeters.

Step 1. Orient the voltmeter face down with the chip on the left hand side. Desolder resistors R3 and RX. Solder a wire in hole 1 (marked with a square), trim and strip the loose end, and solder to the left hand pad under resistor RX. Solder two more wires into holes 4 and 5 of header HV. These connect to pins 4 (NRST) and 18 (SWIM) and are used in programming the STM8S chip.



Step 2. Solder a wire to the pad marked "IN" next to the red wire that carries the positive voltage. The next part is slightly tricky. Apply flux to the very bottom pin on the left hand side the chip and very carefully solder to a length of solid core hookup wire. These two wires connect to pins 19 and 20 and carry the I2C SCL and SDA signals, respectively.



Step 3. Add shrink wrap and hot glue for strain relief. Solder pin headers to the loose ends of the wires.  Bada bing!



The hacked hardware should now have a layout something like this:




Firmware


The firmware is archived in a github repositoryAs explained by the firmware's author, the majority of the source code is devoted to recreating the I2C slave protocol in software. The code is optimized to allow transfer speeds of up to 50kHz. An additional layer has been implemented to emulate the Adafruit Backpack. Because of the different pin assignments I made a few changes here and there.

The source code should be compiled using IAR Embedded Workbench for STMicroelectronics STM8. The “KickStarter” edition is usable free with registration. The STM8S/A Standard Peripherals Library (STM8S_StdPeriph_Driver V2.1.0) is required and can be downloaded as stsw-stm8069.zip from the http://www.st.com STM8 firmware page.
.
For one of the voltmeters, I had difficulty programming the MCU because it had Read-out Protection activated. I couldn't figure out how to disable this option using IAR Embedded Workbench, but it was straightforward to do from the "option bytes" menu in the STVD visual development IDE, which I also downloaded from http://www.st.com.

The STM8S discovery development board (see picture below) can be used to program the chip using the SWIM protocol. First remove the solder bridges connecting the emulator to the evaluation board, then connect the pins on the SWIM header to the correct terminals on the hacked voltmeter: VDD to V+, VSS to V-, NRST and SWIM to holes 4 and 5 of header HV, respectively.



Because the firmware emulates the Adafruit Backpack, the original Adafruit demo sketch can be used for testing. Just be aware that the Arduino I2C clock must first be reduced to 50 kHz by editing the TWI_FREQ variable in the Arduino /libraries/Wire/utility/twi.h file. To enable communication at the correct voltage the Arduino SCL and SDA pins, respectively, should be connected via a logic level converter to the wires joined to pins 19 and 20 on the display's MCU.


Resources




Linkbacks


14 comments:

Anonymous said...

Very good hack!
I must have a go at this one.

Tom said...

Thanks - all the credit goes to ba0sh1 for this one!

baoshi said...

Thanks for linking my article. Good to know the code actually works with other GPIO pins :D

spiralbrain said...

Excellent !

Just found a seller on ebay selling this very board, Thought this would save peopel time rushing to buy one: http://www.ebay.com/itm/1x-Red-LED-DC-4-5-30V-0-36-4-Digit-Digital-Voltmeter-2-wire-STM8S003-Panel-/200931084401

Unknown said...

Any comment for using the mention internet seller? like speed of delivery etc.

Tom said...

I got the voltmeters from www.buyincoins.com. The price was cheap and I used a discount coupon. Delivery to the USA was slow, about 4 weeks.

osddisplays said...

Good post. Much helpful article. I really appreciate the way you have written entire blog. Thanks for discussing with us!

Mary said...

Very useful and helpful article. Thank you!

Harold said...

Very nice post. Thank you for sharing...

Unknown said...

Good post, Thank you for sharing. But i have a problem when i make a new PCB with your design. My PCB working when uncomment code test at led.c (line 260-265) " // Test
led_set_digit( 1, 0x0 );
led_set_digit( 2, 0x1 );
led_set_digit( 3, 0x2 );
led_set_digit( 4, 0x3 );
led_on();"
but not working when using arduino by i2c connection. I think i have a mistake when connect from arduino to stm8s003f3p6. Please help me!!
I has a picture, detail at https://drive.google.com/open?id=0B2_U8h8kmujkVjQwQ3lKbFhvNW8

and https://drive.google.com/open?id=0B2_U8h8kmujkWXJ6MzlNWjNTOW8

t

Unknown said...

This is connection diagram https://drive.google.com/file/d/0B2_U8h8kmujkZWN3WWFZbmNoWWs/view

Please help me! Thank you verymuch!

ZoomVisual said...

Thanks for sharing such an amazing article, really informative

Visit here : LED Digital Signage

Ashwinkumar said...

This ingenious project showcases the versatility of repurposing LED voltmeters for a cost-effective 7-segment display solution using the I2C protocol. The detailed hardware modification guide, complete with clear images and step-by-step instructions, allows enthusiasts to adapt these voltmeters for a new purpose. Leveraging an existing firmware that emulates the Adafruit board simplifies the process, making it accessible for Arduino users. The inclusion of resources, such as the GitHub repository and additional links, enhances the project's transparency and encourages others to explore this creative approach to LED displays. To discuss more about visit Signboard company in Dubai





togearmarketing said...

This is useful and informative blog
Keep it up and visit us
led signs red deer

Post a Comment