I2c Help please

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

The Datasheet is not really that descriptive, however is says that it has 10k pull ups, so i am guessing that I can take out the ones i connected to the chip..

cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

I took out the resisters but I still get 255, any ideas anybody please ?

cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

Looks like all the pullups are on the level shifter.
Edit: Guess I'm too slow on the keyboard!
Last edited by GTF on Sat Dec 28, 2013 8:35 pm, edited 1 time in total.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: I2c Help please

Post by kersing »

Have you connected pin 2 of the sensor? If so to what is it connected? Also, do you have a 3.3v supply connected? Are the grounds and voltage supplies of 5v and 3.3v both connected to the level shifter?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi Kersing,GTF

yes I have a 5v rail and a 3.3v rail, the level shifter has 3.3v + gnd connected with the clock and data lines, and on the high side I have 5v + gnd clock and data, on the sensor there is no pin 2, just 3.3 gnd and the data and clock lines as per pic enclosed...I have also checked my rails and they are fine...
ADA-LIGHT-SENSOR.png
(209.45 KiB) Downloaded 6397 times
cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

What about the pullups that are on the sensor board? Or are these what you removed?

With no connection/jumper for pin 2 (address select), is it NC to any traces?

Also, it appears you can use the sensor board as is without the level shifter if you have no 5V I2c devices on the bus.
http://learn.adafruit.com/tsl2561/wiring

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

I have 2 push buttons now, one for powering up the sensor and one to power it down, both print the results on screen, I also read the register first before anything and print the results in the middle of the lcd, however everything has the value 255, I am enclosing the new chart........
TSL2561_MK3.fcfx
(12.33 KiB) Downloaded 273 times

thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi GTF,

I am working off the Datasheet for the TSL2561, however the sensor that I have is the one pictured above from Adafruit and there is no proper datasheet for it, it looks like the TSL2561 is the sensor in the middle of the board, so I am trying to find out now what the address pin is connected to etc......

cheers
Acestu


EDIT: it may be worth just trying the other 2 addresses and seeing what happens, or I could connect it to a i2c address scanner !
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi GTF,

That is the wrong board on your link, this is the sensor:

http://www.adafruit.com/products/1246


cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

I have just taken the sensor off and connected it to an i2c line scanner, it says that it is present on 39 as per pic,
scanner.png
(2.8 KiB) Downloaded 6388 times
cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

I have just ordered a 5 volt i2c compass, I think there is a problem with the level shifter somewhere and I don't think the i2c communication is working, I will post again when the item arrives, thanks everybody for all your help so far ...........

cheers
Acestu


EDIT: I have come to this conclusion because when connected to an arduino without a level shifter and run the demo program, the sensor works fine..
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

acestu wrote:Hi GTF,

That is the wrong board on your link, this is the sensor:

http://www.adafruit.com/products/1246


cheers
Acestu
They are the same the same other than the fixed address on the one you have.
acestu wrote:Hi,

I have just taken the sensor off and connected it to an i2c line scanner, it says that it is present on 39 as per pic,
scanner.png
cheers
Acestu
Then pin 2 is NC.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi GTF,

Yes according to the Datasheet the addresses are 29h , 39h and 49h 39h when address pin is floating, but I have been trying all sorts all day to get it going, that's why I am going to wait till I get the other sensor in the post now........

Cheers for your help
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

I think we also have not had the chart quite right yet. Take a look at the I2C component help in V5 for a little more information.
Attachments
TSL2561_MK3b.fcfx
(16.31 KiB) Downloaded 168 times

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi,

I have been having another mess today and I think you are right, the chart wasn't right, here is my updated chart, I have programmed the chip but it is very erratic when pushing the switches I get values of 255, 0, 51, and eventually I get 3, so something is still a miss......
TSL2561_MK5.fcfx
(14.36 KiB) Downloaded 170 times
cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

Does the TSL2561_MK3b chart in my last post do anything?

Grant

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi Grant,

So sorry, my head was spinning yesterday and I missed that post, however I have just downloaded your chart and loaded it, OMG you have cracked it, occasionally I get the value 51 could this be due to pull ups ?


cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi Grant,

Could the 51 message mean that you are sending a Write ON message to a register that is already ON ?

Because that seems to be the logic of how the buttons are working, ie if you press on then off, then on then off all is well but if you press on then on again you get the 51....

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

Hmm....... It appears that after 2 successive ON commands you are reading back 0011<<4|0011 (3<<4|3)
Which is 51 decimal. 4 bits are being written to the Control register on each write, pushing whatever is in there left 4 bits.

Does the attached code work to ensure that the upper 4 bits of the Control register are cleared before 03h is written?

Edit: updated attached chart
Attachments
TSL2561_MK3d.fcfx
(16.45 KiB) Downloaded 166 times
Last edited by GTF on Sun Dec 29, 2013 11:02 pm, edited 1 time in total.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi GTF,

That seems to of cured things, it's working perfectly now thanks, can I just ask you though, how do yo get 80 for the control register when its address is 0x0 ?


thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

acestu wrote:Hi GTF,
That seems to of cured things, it's working perfectly now thanks, can I just ask you though, how do yo get 80 for the control register when its address is 0x0 ?
thanks
Stuart
0x80 = 10000000 Which is written to the Command register. The command byte must always start with "1" according to the datasheet. The next 3 bits are set according to the options in the datasheet. The lower 4 bits are the address of the register you want to write to in the following byte. In the case of the Control register the address is 0000.

I have edited and re-posted the last chart. I removed an extra Command byte (0x80) that may not be necessary. Not sure which version you tested?

Grant

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi GTF,

That's great thanks, I did try the first chart before your edit but I will try the second one now and let you know.....

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi Grant,

The edited chart works fine also thanks...in the next few days I hope to expand on this project now and maybe get a lux value on the screen, thanks for all your help again......... :D

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: I2c Help please

Post by acestu »

Hi Grant,

If you don't mind I am going to update the chart with explanation remarks so that others can understand it...

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: I2c Help please

Post by GTF »

Good to hear you have communication! What is the readback value from the OFF macro after an ON>OFF cycle?

Post Reply