Separate Segment Cntrl of 4-Dgt 7-Sgmnt Display w/I2C Bckpck

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cjjreed
 
Posts: 2
Joined: Fri Aug 08, 2014 10:08 am

Separate Segment Cntrl of 4-Dgt 7-Sgmnt Display w/I2C Bckpck

Post by cjjreed »

Good morning / afternoon everyone,

After reading the following post,
I2C Control of 4-Digit 7-Segment Display w/I2C Backpack

I was curious to know if individual segments can be controlled using the following setup:
Raspberry Pi B+, Python, very novice programming skills
I have set up the display and backpack as needed and have been able to test using the library test scripts. I opted to use the original 26PIN Pi Cobbler with a 40-26PIN "down-grade" cable. This was basically so that I didn't have to wait for the B+ Pi Cobbler to be available and get right into the action.

WOOHOO! I made my own digital clock!

So now I want to program the display and create custom digitry (not an actual word). Is this possible with the backpack installed or can this only be done if the backpack was not installed? Does the Python language and libraries allow for individual segment control? Looking at the schematics for the backpack and HT16K33 IC, it appears to show a possibility of individual control but I just don't know where to start... oh and I did the usual forum search and "Googled it" but couldn't find anything that stood out.

I appreciate your patience and understanding as I learn my way around the RasPi. I'm just proud of myself for being able to figure out how a breadboard works!

Regards,
Chris

User avatar
cjjreed
 
Posts: 2
Joined: Fri Aug 08, 2014 10:08 am

Re: Separate Segment Cntrl of 4-Dgt 7-Sgmnt Display w/I2C Bc

Post by cjjreed »

After messing around (I guess that's how you learn Python programming...) I was able to determine what needed to be done in order to set individual segments as either being on or off.

At first I was trying to control each segment of each digit individually but upon doing further research, I discovered that the segments are tied together over a series of hexadecimal addresses. After *alot* of writing and rewriting my Python script, I not only got the display to read what I wanted, but also was able to get it to scroll. Here is the code, sorry it is long (if anyone has any ideas on how to shorten it, that would be nice):

import time
from Adafruit_7Segment import SevenSegment
# from random import randrange (from a previous attempt of scripting)
segment = SevenSegment(address=0x70)
value = 1
print "Press CTRL + C to stop the script."

while (value > 0):
segment.disp.setBufferRow(4,0x76) #H in fourth digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x79) #E in fourth digit
segment.disp.setBufferRow(3,0x76) #H in third digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x38) #L in fourth digit
segment.disp.setBufferRow(3,0x79) #E in third digit
segment.disp.setBufferRow(1,0x76) #H in second digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x38) #L in fourth digit
segment.disp.setBufferRow(3,0x38) #L in third digit
segment.disp.setBufferRow(1,0x79) #E in second digit
segment.disp.setBufferRow(0,0x76) #H in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x3F) #O in fourth digit
segment.disp.setBufferRow(3,0x38) #L in third digit
segment.disp.setBufferRow(1,0x38) #L in second digit
segment.disp.setBufferRow(0,0x79) #E in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(3,0x3F) #O in the third digit
segment.disp.setBufferRow(1,0x38) #L in the second digit
segment.disp.setBufferRow(0,0x38) #L in the first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x39) #C in the fourth digit
segment.disp.setBufferRow(1,0x3F) #O in the second digit
segment.disp.setBufferRow(0,0x38) #L in the first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x76) #H in the fourth digit
segment.disp.setBufferRow(3,0x39) #C in the third digit
segment.disp.setBufferRow(0,0x3F) #O in the first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x50) #r in the fourth digit
segment.disp.setBufferRow(3,0x76) #H in the third digit
segment.disp.setBufferRow(1,0x39) #C in the second digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x30) #I in fourth digit
segment.disp.setBufferRow(3,0x50) #r in third digit
segment.disp.setBufferRow(1,0x76) #H in second digit
segment.disp.setBufferRow(0,0x39) #C in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(4,0x6D) #S in fourth digit
segment.disp.setBufferRow(3,0x30) #I in third digit
segment.disp.setBufferRow(1,0x50) #r in second digit
segment.disp.setBufferRow(0,0x76) #H in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(3,0x6D) #S in third digit
segment.disp.setBufferRow(1,0x30) #I in second digit
segment.disp.setBufferRow(0,0x50) #r in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(1,0x6D) #S in second digit
segment.disp.setBufferRow(0,0x30) #I in first digit
time.sleep(.5)
segment.disp.clear()
segment.disp.setBufferRow(0,0x6D) #S in first digit
time.sleep(.5)
segment.disp.clear()
time.sleep(.5)

It scrolls "HELLO CHrIS" continuously until CTRL + C is pressed. If only I had gotten the Alphanumeric display, that "R" would be capitalized. So each segment is given a decimal number and, once you figure out which segments you want illuminated, you add up the corresponding numbers, convert it to hexadecimal and insert it into your code.

Top Segment = 1
Top Right Segment = 2
Bottom Right Segment = 4
Bottom Segment = 8
Bottom Left Segment = 16
Top Left Segment = 32
Center Segment = 64
Decimal Point = ?? (couldn't figure it out)

Add up the segment decimal numbers and convert to hexadecimal to give you your address when writing the segment.disp.setBufferRow value as seen above in my code.

Anyway, I'm sure this information is elsewhere, but I thought I would compile it again here. Sorry for any duplication and I hope others find this useful.

-Chris

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”