I've been working on a little fluorescence/light sensor project in my university's lab, testing the TCS34725 color sensor with the Arduino Uno and the Raspberry Pi Pico. I've got a decent background in programming (mainly Matlab and Python) but I'm fairly new to embedded coding and Micropython. While its generally been a lot of fun and the Uno hasn't had any difficulty, I've been running into a lot of issues trying to get the TCS34725 running on the Pico. I've been trying to troubleshoot this for a bit, so I've laid out what's turned up below in the hopes that someone can help me sort out how this is going wrong. Searching through the forums here indicated that the Pico/TCS34725 interface has had some issues but I got the impression they'd been resolved.
To start, I'm running MicroPython v1.17 on 2021-09-02; Raspberry Pi Pico with RP2040, and interfacing to the Pico using Thonny. I've saved the adafruit_blinka, adafuit_busdevice, adafruit_platform_detect and adafruit_tcs34725 libraries to the board. I tried using the basic example from the sensor's webpage: https://learn.adafruit.com/adafruit-col ... cuitpython
Code: Select all
import board
import adafruit_tcs34725
i2c = board.I2C()
sensor = adafruit_tcs34725.TCS34725(i2c)
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
AttributeError: 'module' object has no attribute 'I2C'
Code: Select all
i2c = board.I2C()
sensor = adafruit_tcs34725.TCS34725(i2c)
print('Color: ({0}, {1}, {2})'.format(*sensor.color_rgb_bytes))
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 30, in <module>
File "/lib/adafruit_tcs34725.py", line 136, in color_rgb_bytes
File "/lib/adafruit_tcs34725.py", line 249, in color_raw
File "/lib/adafruit_tcs34725.py", line 181, in active
File "/lib/adafruit_tcs34725.py", line 383, in _read_u8
File "/lib/adafruit_bus_device/i2c_device.py", line 125, in write_then_readinto
File "/lib/busio.py", line 176, in writeto_then_readfrom
File "/lib/adafruit_blinka/microcontroller/rp2040/i2c.py", line 55, in writeto_then_readfrom
File "/lib/adafruit_blinka/microcontroller/rp2040/i2c.py", line 33, in writeto
OSError: [Errno 5] EIO
Code: Select all
def writeto(self, address, buffer, *, stop=True):
"Write data to the address from the buffer"
return self._i2c.writeto(address, buffer, stop)
Running this code:
Code: Select all
import bitbangio, board, adafruit_tcs34725
i2c = bitbangio.I2C(board.GP1, board.GP0)
sensor = adafruit_tcs34725.TCS34725(i2c)
print('Color: ({0}, {1}, {2})'.format(*sensor.color_rgb_bytes))
Code: Select all
File "<stdin>", line 2, in <module>
File "/lib/bitbangio.py", line 28, in __init__
File "/lib/bitbangio.py", line 40, in init
TypeError: can't convert Pin to int
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 14, in <module>
File "/lib/bitbangio.py", line 28, in __init__
File "/lib/bitbangio.py", line 40, in init
ValueError: I2C(-1) doesn't exist
At this point I've reached the edge of what I can figure out and don't know what to do next. It looks like the TCS34725's I2C errors were considered resolved back in April based on the thread here: https://github.com/adafruit/circuitpython/issues/4082 but as this post shows I'm still trying to get it working and finding different issues along the way. I should note that I also tried the SoftI2C method suggested at https://forum.micropython.org/viewtopic.php?t=9673 and didnt have success there either (incompatibility issues with the adafruit_bus_device.i2c_device library). Trying a dirty workaround for that (commenting out the try_lock checks in that library) did let me initialize the sensor, but I still found myself facing an "OSError: [Errno 5] EIO" when trying to use any of the sensor functions.
Anyways, thanks in advance for whatever advice you can give as to what I should try next or potential solutions that I'm missed in my search. I know this was a bit of a long post but hopefully the details will help someone else if they go searching with these same errors. Again I've had no problem running this with the Arduino Uno, so I'm hopeful that I can get this running eventually on the Pico.