Skip to content

Instantly share code, notes, and snippets.

@Drizzt321
Last active October 4, 2017 06:25
Show Gist options
  • Save Drizzt321/d9ae3ca0046c20e058d2c90ba668f8f0 to your computer and use it in GitHub Desktop.
Save Drizzt321/d9ae3ca0046c20e058d2c90ba668f8f0 to your computer and use it in GitHub Desktop.
Adafruit 1.2" 7-segment LED i2c hex configuration
The Adafruit 1.2" 4 digit 7-segment LED display with backpack (https://www.adafruit.com/product/1270) is connexted via the i2c bus interface. Adafruit has a quite good soldering & setup tutorial at https://learn.adafruit.com/adafruit-led-backpack/1-2-inch-7-segment-backpack, however they do a terrible job of describing in easy detail the necessary i2c writes to control the display from a language other than their provided libraries for Arduino or Python. So I've assembled a pretty comprehensive address and data to write in order to fully control the display. Please see attached images for some details.
digit segment numbered.jpg - shows an image of the display, along with numbers/letters along with a bitmask to use to control each segment.
seven segment bitmask chart.jpg - shows which bits control which segments for the digits
dots segment bitmask chart.jpg - shows which bits control which segments for the dots
Examples of writing are using the Linux i2c-tools. For example this write:
i2cset 1 0x70 0x00 0x7F
i2c bus 1 (default for Raspberry Pi)
bus address 0x70 (default for the backpack)
register address 0x00 (first digit from the left)
data 0x7F (turn on all 7 segments for the digit)
On startup or when power is first applied, you need to startup the oscillator. You do this by writing to 0x21 to turn it on, 0x20 to turn it off. I haven't measured the power usages with all segments off but the oscillator on/off, but if you want to save every mA or uA I'd guess turning the oscillator off would save a bit of power, even over turning the segments off (see Brightness section below).
Here are the addresses which control which segments you are writing to:
0x00 - 0 digit
0x02 - 1 digit
0x04 - dots
0x06 - 3 digit
0x08 - 4 digit
For the data payload, please see the 2 bitmask charts.
The Brightness controls the oscillator across all segments that are on. You can't individually control the brightness on individually segments unfortunately. In this case, you write without any bytes (or 0x00) to the address. The first hex digit indicates you are controlling brightness, the 2nd hex digit is the level (0 to 15).
0xE0 - Brightness 0
0xE1 - Brightness 1
...
0xEE - Brightness 14
0xEF - Brightness 15
Example write for brightness 5:
i2cset 1 0x70 0xE5
The Blink controls if any segments are on, solid on, or blinking at 3 different levels of speed. This is like the brightness, a simple write to an address with no data payload (or 0x00).
0x80 - All Off
0x81 - On Solid
0x83 - Blink 1 (fast) 0.5 Hz
0x85 - Blink 2 (medium) 1 Hz
0x87 - Blink 3 (slow) 2 Hz
So for the 2nd digit of the address, the lowest bit indicates on/off, then various blink speeds is the middle 2 bits:
BITS - EFFECT
0000 - Off
0001 - On
0011 - On-Blink Fast
0101 - On-Blink Medium
0111 - On-Blink Slow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment