Page 1 of 1

TSL2561 and bash

Posted: Fri Apr 18, 2014 9:31 am
by lifebeginsatsixty
Hello,
Well I got the i2c working (wiringPi installed) to the point where my TSL2561 light sensor convertor shows up as 29 from i2cd. (This sensor board is from Grove and I don't expect anything funny.) Now I'd like to actually test and use the thing from the shell and haven't found the slightest clue on how to proceed.

I got some good help on the little 1-wire DS18B20 temperature sensor so I'm moving (slowly) to using it to control my sous vide pot using the shell.

A little bash guidance from the old hands maybe? I'm hunting and searching diligently and not coming up with what I think I should.

Thanks,
lifebeginsatsixty

Re: TSL2561 and bash

Posted: Fri Apr 18, 2014 12:28 pm
by DougieLawson
Why does it have to be bash? Why not learn a new trick and write something in python3.

Re: TSL2561 and bash

Posted: Fri Apr 18, 2014 9:48 pm
by lifebeginsatsixty
Hi, just trying to learn a bit about bash at this stage, that's all. Nothing against Python and I'm sure I'll be asking questions about it before too long.

lifebeginsatsixty

Re: TSL2561 and bash

Posted: Sat Apr 19, 2014 10:54 am
by DougieLawson

Re: TSL2561 and bash

Posted: Sat Apr 19, 2014 11:55 am
by lifebeginsatsixty
I2C part not done yet on the page you referred to.

Would it be better to ask, how can I check out my TSL2561 light sensor in a simple way? I'm not working in Python or C at this point.

Shows up at 29 from i2cd command so I think my i2c setup is OK..

Thanks,
lifebeginsatsixty

Re: TSL2561 and bash

Posted: Sat Apr 19, 2014 12:03 pm
by joan
Is it detected by i2cdetect?

You may be able to use i2cget/i2cset to send commands via the command line.

Re: TSL2561 and bash

Posted: Sat Apr 19, 2014 6:24 pm
by lifebeginsatsixty
Hi Joan!

'Tis indeed detected and I believe i2cd and i2cdetect -y 1 are the same commands; gave me the same output anyway. 2 AM here now and tomorrow's a busy day; see if I can find time before Monday. So I need to look up the i2cget and i2cset commands, that's a good lead.

Thanks,
lifebeginsatsixty

Re: TSL2561 and bash

Posted: Mon Apr 21, 2014 9:30 am
by lifebeginsatsixty
I feel like I've been bashed, as in knocked around. Between the TSL2561 data sheet and the info on the i2c commands, I came to this: Data sheet p. 13 gives the address of the control register as 0h. (Sounded funny to me but I'm an ignorant beginner) Then p. 18 tells me to access this register and write the value 03h to it to power up the device. Back to p. 13 it tells me that should I do this, I can read back that 03h value to "verify that the device is communicating properly."

So for the i2cset command I write, i2cset -r 1 0x29 0x0h 0x03h following (I think) the requirements; -r option to read it back, 1 is the i2c bus, 0x29 is the chip address on the bus, 0x0h is the register address the data sheet gives me, and 0x03h is the value I want to write to that register.

Result is Error: data address invalid! Wants something between 0x03 and 0x77.

Hex is supposed to be within the range of 0-f, isn't it? So I'm missing something really basic.

Thanks,
lifebeginsatsixty

Re: TSL2561 and bash

Posted: Mon Apr 21, 2014 9:37 am
by joan
It's confused by the erroneous h's in the addresses.

Re: TSL2561 and bash

Posted: Mon Apr 21, 2014 10:25 am
by DougieLawson
It appears to be a notational problem.

The data sheet is using ##h for hex, we're using the more normal 0x## to denote hex numbers.

Re: TSL2561 and bash

Posted: Tue Apr 22, 2014 2:33 am
by lifebeginsatsixty
Ah the depths of my ignorance. Baby steps.

A peek at the Python code divides this into three commands, (1) to select the command register, (2) to tell it we're going to talk to the control register, and (3) to tell the control register we want to turn the little rascal on. I think.

(1) seems OK with i2cset -r 1 0x29 0x80 0x01
and reads back same value as set. (Did it do what I wanted? Basically copied from the Python code)

Two has me at this point. I'm supposed to write a 0x00 value to bits 0-3 (from Table 3) of the command register (which lists no address in the data sheet but since 0x80 was used in the Python code I used that). The 0h address for the control register is from the data sheet Table 2 on p. 12.

(3) Seems easier to understand since I'm given addresses for that write. But I have to shoot the second one before I can shoot the third one.

I'm searching for info, a tutorial, something to explain the basics of what's going on, what I need to do; guess I haven't hit the right search terms as I'm not turning up anything helpful.

muddling through,
lifebeginsatsixty

Re: TSL2561 and bash

Posted: Tue Apr 22, 2014 8:23 am
by joan
http://www.adafruit.com/datasheets/TSL2561.pdf
...
Each Send and Write protocol is, essentially, a series of bytes.

A byte sent to the TSL256x with the most significant bit (MSB) equal to 1 will be interpreted as a COMMAND byte.

The lower four bits of the COMMAND byte form the register select address (see Table 2), which is used to select the destination for the subsequent byte(s) received.

The TSL256x responds to any Receive Byte requests with the contents of the register specified by the stored register select address
...
My formatting.

Re: TSL2561 and bash

Posted: Fri Apr 25, 2014 9:54 pm
by lifebeginsatsixty
Hi Joan,

I seem to have a problem communicating the depth of my ignorance. I'll keep working on this and see if I can get the missing background knowledge. Haven't located it yet.

Thanks,
lifebeginsatsixty