Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Using TSL2591 with FT232H
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using TSL2591 with FT232H

by houshun on Wed Mar 25, 2020 2:07 am

Hi all,

I am trying to use the TSL2591 high dynamic range digital light sensor with the FT232H breakout, USB to SPI, I2C, so that I can access the sensor via a usb interface.

I have tested the TSL2591 on an Arduino and it read fine. Now I have it hooked up to a FT232H (old versionwith micro usb) with D1 and D2 shorted for I2C operation. I followed the instruction here: https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h for installation of the CircuitPython, and the necessary libraries on Ubuntu 18.04.
I have verifed that pyftdi was installed properly and that the FT232H can be identified.

After setting the enviorment variable BLINKA_FT232H=1 before running tsl2591_simpletest.py. However I am recieving the following error message -

Traceback (most recent call last):
File "tsl2591_simpletest.py", line 14, in <module>
sensor = adafruit_tsl2591.TSL2591(i2c)
File "/usr/local/lib/python3.6/dist-packages/adafruit_tsl2591.py", line 115, in __init__
if self._read_u8(_TSL2591_REGISTER_DEVICE_ID) != 0x29:
File "/usr/local/lib/python3.6/dist-packages/adafruit_tsl2591.py", line 128, in _read_u8
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
File "/usr/local/lib/python3.6/dist-packages/adafruit_bus_device/i2c_device.py", line 156, in write_then_readinto
in_end=in_end,
File "/home/seth_poh/.local/lib/python3.6/site-packages/busio.py", line 92, in writeto_then_readfrom
in_start=in_start, in_end=in_end, stop=stop)
File "/home/seth_poh/.local/lib/python3.6/site-packages/adafruit_blinka/microcontroller/ft232h/i2c.py", line 35, in writeto_then_readfrom
relax=True)
File "/home/seth_poh/.local/lib/python3.6/site-packages/pyftdi/i2c.py", line 181, in exchange
readlen, relax=relax)
File "/home/seth_poh/.local/lib/python3.6/site-packages/pyftdi/i2c.py", line 766, in exchange
self._do_prolog(i2caddress | self.BIT0)
File "/home/seth_poh/.local/lib/python3.6/site-packages/pyftdi/i2c.py", line 1014, in _do_prolog
self._send_check_ack(cmd)
File "/home/seth_poh/.local/lib/python3.6/site-packages/pyftdi/i2c.py", line 1046, in _send_check_ack
raise I2cNackError('NACK from slave')
pyftdi.i2c.I2cNackError: NACK from slave

I tried lowing the frequency all the way to 100 but the issue remains. Have anyone here worked with the same setup and saw the same issue but have solved it?

Thank you for you help.

houshun
 
Posts: 5
Joined: Wed Mar 25, 2020 1:41 am

Re: Using TSL2591 with FT232H

by adafruit_support_carter on Wed Mar 25, 2020 2:49 pm

It might be connection related. Can you post a photo of your setup showing how everything is wired together.

Just to make sure this combo would work, I set one up and tried it out. I used the old style FT232H and ran the same simpletest. I'm also on Ubuntu. It ran OK here:
Code: Select all | TOGGLE FULL SIZE
$ python3 tsl2591_simpletest.py
Total light: 0.0lux
Infrared light: 0
Visible light: 0
Full spectrum (IR + visible) light: 46599683
Total light: 395.100672lux
Infrared light: 711
Visible light: 46598972
Full spectrum (IR + visible) light: 46861852

so it doesn't seem software related.

adafruit_support_carter
 
Posts: 16413
Joined: Tue Nov 29, 2016 2:45 pm

Re: Using TSL2591 with FT232H

by houshun on Wed Mar 25, 2020 4:04 pm

Hi there,

Here's a picture of the connection to the FT232H -

IMG_20200326_034526.jpg
IMG_20200326_034526.jpg (376.38 KiB) Viewed 81 times


where the wires are connected to

Red - Vin
Black - Gnd
Brown - SCL
Green - SDA

of the TSL2519. I can't take a photo of the other end unfortunately, the TSL2519 is already install in a housing. But I would imagine the wiring is correct, since it worked on an Arduino. It also output an error saying no I2C device found at 0x29 address if I swap the brown and green wire.

The only extra thing I did was, the FT232H came with a blank eeprom. I flashed the eeprom with the steps described here https://forums.adafruit.com/viewtopic.php?f=19&t=160809

Thank you.

houshun
 
Posts: 5
Joined: Wed Mar 25, 2020 1:41 am

Re: Using TSL2591 with FT232H

by adafruit_support_carter on Wed Mar 25, 2020 4:25 pm

Thanks for the photo. Looks like you bridged D1/D2 using solder?

Do you have any other I2C devices that could be used to troubleshoot?

adafruit_support_carter
 
Posts: 16413
Joined: Tue Nov 29, 2016 2:45 pm

Re: Using TSL2591 with FT232H

by houshun on Wed Mar 25, 2020 4:42 pm

Yes, D1 and D2 are bridged with solder for I2C operation.

I have a few SRF02 ultrasonic sensors lying around. Just need to find them first,

houshun
 
Posts: 5
Joined: Wed Mar 25, 2020 1:41 am

Re: Using TSL2591 with FT232H

by adafruit_support_carter on Thu Mar 26, 2020 10:42 am

OK, let's use one of those, assuming they are I2C. Some of those are just basic digital pulse in / out, so please double check that. The idea is to sanity check the basic I2C functionality of the FT232H. Since it sounds like your TSL2519 is already installed into a larger assembly, we want to rule out it being anything related to that. So we just want FT232H -> some I2C sensor, with nothing else going on. And the ability to see and check all wiring between the two.

adafruit_support_carter
 
Posts: 16413
Joined: Tue Nov 29, 2016 2:45 pm

Re: Using TSL2591 with FT232H

by houshun on Tue Mar 31, 2020 5:57 am

Unfortunately I have yet to have the chance to test it on any other I2C devices. Some additional quick checks I have done are -

1. The TSL2591 works with an arduino using the same cable.
2. Testing with another FT232H yielded the same NACK error.
3. Tested the setup with circuitpython on Raspbian Buster yielded the same NACK error
4. Using i2cscan.py that came with the pyftdi library, the TSL2591 is located at address 0x28
5. I am able to get a port to the device using get_port() in pyftdi
6. Any attempt to write to device fail the _send_check_ack in pyftdi

May I know were you using the latest version of pyftdi and blinka when you ran your test?

Thank you.

houshun
 
Posts: 5
Joined: Wed Mar 25, 2020 1:41 am

Re: Using TSL2591 with FT232H

by adafruit_support_carter on Tue Mar 31, 2020 12:48 pm

Unknown what it might be, but the fact that this is installed and inaccessible adds lots of uncertainties. It would really help if you could access the TSL2591 more directly for troubleshooting. Here's my test setup:
tsl_test.jpg
tsl_test.jpg (448.33 KiB) Viewed 26 times


Versions being used:
Adafruit-Blinka (4.2.0)
adafruit-circuitpython-tsl2591 (1.2.0)
pyftdi (0.48.3)


And simple test:
Code: Select all | TOGGLE FULL SIZE
blinka:~$ export BLINKA_FT232H=1
blinka:~$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import adafruit_tsl2591
>>> tsl = adafruit_tsl2591.TSL2591(board.I2C())
>>> tsl.lux
255.00326399999997
>>>

adafruit_support_carter
 
Posts: 16413
Joined: Tue Nov 29, 2016 2:45 pm

Re: Using TSL2591 with FT232H

by houshun on Wed Apr 01, 2020 11:42 pm

Hi there,

I managed to identify the issue. I believe it was just down to the cable length between the TSL2591 and the FT232H. Here are some observations -

1. Look at the trace of the SDA and SCL reviewed that the SCL voltage levels are not consistent/corrupted and sometimes below the logic high threshold.
2. Putting the TSL2591 right on the same breadboard as the FT232H solves the problem
3. I was running about 50 cm of cat 4 between them, shortening it by 10 to 15cm solves the problem.
4. The FT232H is connected to an USB hub. that somehow also produces the NACK error. A direct connection to the Raspberry Pi I am running the script from solves the problem

A remaining question I have is, previously even with the longer cable, it is working with an Arduino. Before this I also tried lowering the FT232H frequency but that did not solve the issue. I wonder what are the plausible explanation for this?

Thank you for your help in diagnosing the issue.

houshun
 
Posts: 5
Joined: Wed Mar 25, 2020 1:41 am

Re: Using TSL2591 with FT232H

by adafruit_support_carter on Thu Apr 02, 2020 11:43 am

The Arduino may be driving the pins at higher voltage allowing for longer cable run. But in general, any long cable runs with I2C can be a potential issue. I2C was mainly designed for short runs among chips on the same PCB. It's still possible to have it work over a fair distance, even several feet, but it all depends on cable quality, value of pull resistors, etc. You just have to experiment with your specific setup and see what you can get away with.

adafruit_support_carter
 
Posts: 16413
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.