TCS34725 (colour sensor) can't creat object.

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
smssms
Posts: 12
Joined: Tue Feb 14, 2017 8:37 am

TCS34725 (colour sensor) can't creat object.

Post by smssms » Tue Feb 14, 2017 8:50 am

I'm using the Adafruit/tdicola TCS34725 micropython library https://github.com/adafruit/micropython ... cs34725.py and have had it working fine with my Pyboard.

But now (for some unknown reason) I am totally stuck; I can import the library but when I go to create the sensor objecti.e. "sensor = tcs34725.TCS34725(i2c)"

I get the following error message

>>> sensor = tcs34725.TCS34725(i2c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tcs34725.py", line 44, in __init__
File "tcs34725.py", line 90, in integration_time
File "tcs34725.py", line 54, in _register8
TypeError: can't convert bytes to int

The lines which throw the errors are:
self.integration_time(2.4)
self.i2c.mem_write(self.address, register, data)
return self._register8(_REGISTER_ATIME, 256 - cycles)

I'm very new to all this and have been fumbling around for days to try and find these bytes that cannot be converted to int with 0 success :x

Can anybody shed any light on this error or help me at all please?

EDIT: I've managed to create the object now by adjusting the library to work with pyb.I2C rather than machine.I2C. But now I just get a load of OSError: [Errno 5] EIO when I try to read the sensor.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: TCS34725 (colour sensor) can't creat object.

Post by pythoncoder » Wed Feb 15, 2017 6:51 am

A few thoughts: given that it has worked in the past I'd try to figure out what you changed before it stopped working. Have you installed a new build of firmware?

The line numbers in your listings are out by two compared to the GitHub listing: this suggests you might have an out of date version of the library.

Looking at the code it assumes an I2C object created from the machine module rather than from pyb: line 52 has

Code: Select all

self.i2c.writeto_mem(self.address, register, data)
The writeto_mem method is supported only by machine. So trying to use pyb is probably a mistake.

Doubtless @Deshipu (the driver's author) will be along soon to set you right ;)
Peter Hinch
Index to my micropython libraries.

smssms
Posts: 12
Joined: Tue Feb 14, 2017 8:37 am

Re: TCS34725 (colour sensor) can't create object.

Post by smssms » Wed Feb 15, 2017 8:05 am

Thank you for the reply.

The only reason the line numbering is out is because I added a couple of comments in my project copy for my own reference.

I have adjusted the library to the best of my ability to work with pyb.I2C ( https://github.com/smssmssms/micropytho ... f29d78c879 ).

I've stuck with pyb.I2C until now basically because I can get i2c.send(data,address) to do what I want, but have not had much success with whatever the machine.I2C equivalent is :? . I guess I need to concentrate on getting machine.I2C to work in my code so that I can use the library as is....

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: TCS34725 (colour sensor) can't creat object.

Post by deshipu » Wed Feb 15, 2017 9:27 am

I don't know where you got that code, but the code I wrote uses ``self.i2c.writeto_mem(self.address, register, data)`` and not ``self.i2c.mem_write(self.address, register, data)``. Perhaps you should ask the author of the code you are using, because ``mem_write`` takes different parameters.

smssms
Posts: 12
Joined: Tue Feb 14, 2017 8:37 am

Re: TCS34725 (colour sensor) can't creat object.

Post by smssms » Wed Feb 15, 2017 10:02 am

I've been trying with your original code (using machine.I2C) and my adjusted code (with pyb.I2C):
https://github.com/smssmssms/micropytho ... f29d78c879

Both can 'see' the sensor with i2c.scan(), sensor.active(), sensor.gain(), etc. But both fail to actually read the sensor with sensor.read().

>>> sensor.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tcs34725.py", line 102, in read
File "tcs34725.py", line 69, in active
File "tcs34725.py", line 50, in _register8
OSError: [Errno 19] ENODEV

smssms
Posts: 12
Joined: Tue Feb 14, 2017 8:37 am

Re: TCS34725 (colour sensor) can't creat object.

Post by smssms » Wed Feb 15, 2017 11:29 am

Partially solved :D

The change that broke it - moving from Pyboard V1.0 to V1.1

No idea why, but I can get the TCS34725 sensor/library to work on a V1.0 board, but it does not seem to work (for me) on a V1.1.

smssms
Posts: 12
Joined: Tue Feb 14, 2017 8:37 am

Re: TCS34725 (colour sensor) can't creat object.

Post by smssms » Mon Mar 20, 2017 8:09 pm

Bit of an update:

When I moved the project onto a WiPy, I had to change "sensor = tcs34725.TCS34725(i2c)" to . "sensor = TCS34725.TCS34725(i2c)" for it to work.

Post Reply