austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

saa1064, i2c, and python module

Thu May 09, 2013 2:20 pm

Hello,

I'm very new to i2c programming so I'm a little confused about the issue I'm having right now and hoping someone could shed some light on this.

I have a saa1064 chip wired up to my pi (rev 2) and using i2cdetect -y 1 it finds it. However it reports its address as 0x3b. All documentation I can find says that the chip's first address is 0x70...It's odd I thought but shrugged it off because it was detected.

Anyways I installed SMBus for python and found this example: http://s31108.blogspot.com/2012/11/simp ... n-and.html

The example code below works but does not turn on the segments I would expect.

import smbus
import time
import datetime
bus = smbus.SMBus(1)

addr = 0x3b
cmd = 0x00
val = 0x27

bus.write_byte_data(addr,cmd,0x00)
bus.write_byte_data(addr,cmd,val)

time.sleep(2)

bus.write_byte_data(addr,cmd,0x00)

This turns on the c and d segment for two seconds and then successfully turns them off.

I've written a loop to go from 1 to 100 and depending on the value either only the c & d segments turn on OR all segments and DP turn on. I'm a bit stumped.

Any advice on how to properly send a value to the saa1064 to control specific segments would be very helpful.

TIA

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Sat May 11, 2013 1:04 pm

I feel stupid. I figured it out though...

0x00 is the subaddress for the control bits so when you send anything to 0x3b, 0x00 your next byte is for the control bits. I kind of figured this but had issues because any time I tried the subaddress 0x01 to do anything with digit 1 nothing happened.

Well, the reason was that I didn't have digit 1 working properly is because I never set my control bits correctly before writing to the 0x01 subaddress.

From the command line I'd run i2cset -y 1 0x3b 0x00 0x00 thinking I was just clearing the display (which is true.)

Then I'd run i2cset -y 1 0x3b 0x01 0x01 expecting a segment on the 7-segment to turn on and it never did.

Oh! I have to set the amp control bits so the chip knows how bright I want the seven segment!

So instead of i2cset -y 1 0x3b 0x00 0x00 it is rather i2cset -y 1 0x3b 0x00 0x10

(0x10 for setting the 5th bit to 1 in order to give the segment 3 mA)
THEN

i2cset -y 1 0x3b 0x01 0x01


Hopefully this information is useful to others who are completely new to this and possibly run into the same stupid self-inflicted problem as I did with this saa1064 chip.

User avatar
mike632t
Posts: 83
Joined: Sat May 19, 2012 7:56 pm
Location: UK
Contact: Website

Re: saa1064, i2c, and python module

Sun May 12, 2013 2:55 pm

Which segment lights also depends on which output of the SAA1064 it is connected to. Any output can drive any segment as the device itself does not do anything to decode the output (It does help to be consistent though!). I've managed to use the SAA1064 to display a very limited range of alpha characters this way.

Did you layout the components on a breadboard or use a factory built module?

Mike T.

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Sun May 12, 2013 3:29 pm

I put them on a bread board. I have the pi cobbler so it was pretty easy.

My final python code is as such:

Code: Select all

import smbus
import time

bus = smbus.SMBus(1)
addr = 0x3b

bus.write_byte_data(addr,0x00,0x10)

segments = {'dp': 0x01, 'a': 0x02, 'b': 0x04, 'c': 0x08, 'd': 0x80, 'e': 0x20, 'f': 0x10, 'g': 0x40}
numbers = {
	0: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'],
	1: segments['a'] + segments['b'],
	2: segments['c'] + segments['b'] + segments['g'] + segments['e'] + segments['f'],
	3: segments['a'] + segments['b'] + segments['c'] + segments['f'] + segments['g'],
	4: segments['a'] + segments['b'] + segments['d'] + segments['g'],
	5: segments['c'] + segments['d'] + segments['g'] + segments['a'] + segments['f'],
	6: segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'] + segments['a'],
	7: segments['c'] + segments['b'] + segments['a'],
	8: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'],
	9: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['g']
}

for i in range(0, 10):
	print i	
	bus.write_byte_data(addr,0x01,numbers[i])
	time.sleep(1)
	bus.write_byte_data(addr,0x01,0x00)
I labeled the segments via letters going from the bottom right segment, up and around to the bottom middle segment and then finally the middle, middle segment. Although it seems like maybe there is a standard labeling of the segments that I didn't follow?

I determined their output values and which values turned on which segments by just going through each bit in the byte via ic2set - e.g.

ic2set -y 1 0x3b 0x01 0x01
ic2set -y 1 0x3b 0x01 0x02
ic2set -y 1 0x3b 0x01 0x04
ic2set -y 1 0x3b 0x01 0x08
ic2set -y 1 0x3b 0x01 0x10
ic2set -y 1 0x3b 0x01 0x20
ic2set -y 1 0x3b 0x01 0x40
ic2set -y 1 0x3b 0x01 0x80

tifilus
Posts: 14
Joined: Thu Aug 07, 2014 10:47 am

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 11:31 am

austinp wrote:I put them on a bread board. I have the pi cobbler so it was pretty easy.

My final python code is as such:

Code: Select all

import smbus
import time

bus = smbus.SMBus(1)
addr = 0x3b

bus.write_byte_data(addr,0x00,0x10)

segments = {'dp': 0x01, 'a': 0x02, 'b': 0x04, 'c': 0x08, 'd': 0x80, 'e': 0x20, 'f': 0x10, 'g': 0x40}
numbers = {
	0: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'],
	1: segments['a'] + segments['b'],
	2: segments['c'] + segments['b'] + segments['g'] + segments['e'] + segments['f'],
	3: segments['a'] + segments['b'] + segments['c'] + segments['f'] + segments['g'],
	4: segments['a'] + segments['b'] + segments['d'] + segments['g'],
	5: segments['c'] + segments['d'] + segments['g'] + segments['a'] + segments['f'],
	6: segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'] + segments['a'],
	7: segments['c'] + segments['b'] + segments['a'],
	8: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'],
	9: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['g']
}

for i in range(0, 10):
	print i	
	bus.write_byte_data(addr,0x01,numbers[i])
	time.sleep(1)
	bus.write_byte_data(addr,0x01,0x00)
I labeled the segments via letters going from the bottom right segment, up and around to the bottom middle segment and then finally the middle, middle segment. Although it seems like maybe there is a standard labeling of the segments that I didn't follow?

I determined their output values and which values turned on which segments by just going through each bit in the byte via ic2set - e.g.

ic2set -y 1 0x3b 0x01 0x01
ic2set -y 1 0x3b 0x01 0x02
ic2set -y 1 0x3b 0x01 0x04
ic2set -y 1 0x3b 0x01 0x08
ic2set -y 1 0x3b 0x01 0x10
ic2set -y 1 0x3b 0x01 0x20
ic2set -y 1 0x3b 0x01 0x40
ic2set -y 1 0x3b 0x01 0x80

Hi!

I know it's late because the last post was one year ago...

I made some changes in the code:

Code: Select all

segments = {'dp': 0x01, 'a': 0x02, 'b': 0x04, 'c': 0x08, 'd': 0x10, 'e': 0x20, 'f': 0x40, 'g': 0x80} #now they're in the correct order
numbers = {
	0: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'],
	1: segments['a'] + segments['b'],
	2: segments['a'] + segments['b'] + segments['g'] + segments['e'] + segments['d'],
	3: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['g'],
	4: segments['a'] + segments['b'] + segments['f'] + segments['g'],
	5: segments['c'] + segments['d'] + segments['g'] + segments['a'] + segments['f'],
	6: segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'] + segments['a'],
	7: segments['c'] + segments['b'] + segments['a'],
	8: segments['a'] + segments['b'] + segments['c'] + segments['d'] + segments['e'] + segments['f'] + segments['g'],
	9: segments['a'] + segments['b'] + segments['c'] + segments['f'] + segments['g']
} # now you can see all the correct numbers from 0 to 9
OK. with i2cset -y 1 I can manage the Digits 1 and 3 doing this:

for digit 1: i2cset -y 1 0x03b 0x01 0xXX (these 'X' are the direction of each segment, for example 0xce to print a '9')
for digit 3: i2cset -y 1 0x03b 0x02 0xXX

But no more... I can´t manage digits 2 and 4. And more, I look in the datasheet (http://www.fortito.mx/wp-content/upload ... AA1064.pdf) and for the Digit2, the sub-address is 0x02, but I am managing the Digit3.. :!: :!: :?:
Probably I am missing something and I don't know what it is... anyone could help me, please?
Thank you!!

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 12:07 pm

Sounds like an issue with possibly your wiring... Can you upload a photo or a circuit diagram for how you have this done?

Do you have the necessary transistor in your wiring to make use of all four addresses?

tifilus
Posts: 14
Joined: Thu Aug 07, 2014 10:47 am

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 12:33 pm

Hi austinp!
Thank you for fast reply!

As you can see, it's a mounted PCB. I use 4 pins: VCC (I've got it with an external power supply of 5V), GND (the same from the power suplly to RaspberryPi and to this pin), SDA and SCL, no more. The rest of pins are for controlling 3 switches and 3 leds that I don't need, so I haven't wired them. Yes, the transistors are mounted.

I supose that my problem is in the firmware, what commands should I write to see lit the other two digits..

Thank you again!
Attachments
20140807_140716.jpg
20140807_140716.jpg (55.21 KiB) Viewed 2529 times

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 12:40 pm

Yup, I'd say with it being mounted the idea of this being a wiring issue is probably no longer the case, heh.

I'll see if I can find my old code where I had four segments hooked up. The examples I had here in this post only ever dealt with one.

What make & model is that PCB or is it your own?

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 12:43 pm

Maybe my eyes are deceiving me, but are there two decimals on each 7 segment in that picture?

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 12:53 pm

I think that possibly the key is in the C0 control bit. This bit needs to be set to 1 in order to have all four segments displayed.

If it is set to 0, then only the 1 & 2 segments are displayed.

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 1:06 pm

Try this in order:

set control bits (do a reset at first):
i2cset -y 1 0x03b 0x00 0x00

set control bits (for 3ma, 10. For specifying control bit 0 to alternate displays, 1):
i2cset -y 1 0x03b 0x00 0x11

for digit 1: i2cset -y 1 0x03b 0x01 0xXX (these 'X' are the direction of each segment, for example 0xce to print a '9')
for digit 2: i2cset -y 1 0x03b 0x02 0xXX
for digit 3: i2cset -y 1 0x03b 0x03 0xXX
for digit 4: i2cset -y 1 0x03b 0x04 0xXX

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Thu Aug 07, 2014 1:08 pm

Another quick test just to make sure the 7 segments are good you can send a single command...

i2cset -y 1 0x03b 0x00 0x08

That should turn on every segment in every 7 segment display.

i2cset -y 1 0x03b 0x00 0x00 will turn them all off.

tifilus
Posts: 14
Joined: Thu Aug 07, 2014 10:47 am

Re: saa1064, i2c, and python module

Fri Aug 08, 2014 8:17 am

Hi austinp!
Is not mine, but there is a place near us where they do this kind of things, mounting PCBs of commonly used chips like this and others like LCDs or any kind of PCB you need. We use this PCB for measure the temperature in an oven.

I have been playing with the 0x3b 0x00 0xXX and finally I see that I have to do:

i2cset -y 1 0x3b 0x00 0x97 for displaying all digits and now I can manage all of them individually, being 0x01 the first one, 0x02 the second, etc...

Thank you very much for your help!

And yes!! there are 2 dp in these displays, so your eyes are not deceiving you! So, I supose it's a 9-segment display?? :P
anyway, one of them is not connected so it's like a normal one!

Thanks again!!

austinp
Posts: 15
Joined: Thu May 09, 2013 1:35 pm

Re: saa1064, i2c, and python module

Fri Aug 08, 2014 11:29 am

No problem at all! Glad I could help :)

Return to “Interfacing (DSI, CSI, I2C, etc.)”