John Shovic's Google Plus Switch: BM017 / TCS34725 Color Sensor I2C Python driver

Friday, February 14, 2014

BM017 / TCS34725 Color Sensor I2C Python driver

We have made one more addition to the hardware on Project Curacao.  We have added a BM017 / TCS34725 RGBC color sensor to the device.  Here is the device attached to the back of the top of the box and then a picture of it peeking through (with the LED turned on for emphasis - it normally operates with the LED off).





This device was purchased from solutions-cubed.com (excellent service and documentation).  Another version (compatible) can be had from Adafruit.

We wrote a Python driver for the BM017 / TCS34725 as we could not find one on the net that met our needs.

It has been posted on github under https://github.com/projectcuracao/PC_BM017CS for anyone who needs such a driver.

We connected the INT line to the LEDON pin (and the VDD_LED to VDD) and now we can switch the interrupt on and off and turn the white LED on and off without burning another GPIO pin.


The example code to test the library and the TCS34725 is below:


#!/usr/bin/python
# example driver for BM017 and TCS34725
import time
import smbus
from Adafruit_I2C import Adafruit_I2C
from PC_BM017CS import BM017
bm017 = BM017(True)
bm017.debug = True
bm017.readStatus()
bm017.isBM017There()
bm017.getColors()
bm017.readStatus()
bm017.disableDevice()
bm017.setIntegrationTimeAndGain(0x00, 0x03)
bm017.getColors()
bm017.readStatus()
bm017.readStatus()
# this will turn on the LED if LEDON is connected to INT and LEDVDD is connected to VDD_LED
bm017.setInterrupt(True)
time.sleep(5.0)
bm017.setInterrupt(False)
And the results:
pi@projectCur ~/PC_BM107CS $ sudo python example.py
BM017 initialized
('BM017 Status=', 17)
BM017 / TCS34725 is present
('ColorList = ', [2, 0, 1, 0, 1, 0, 0, 0])
('clear_color= ', 2)
('red_color= ', 1)
('green_color= ', 1)
('blue_color= ', 0)
('BM017 Status=', 17)
('IT set to:', 0)
('Gain set to:', 3)
('ColorList = ', [8, 15, 157, 7, 105, 5, 151, 3])
('clear_color= ', 3848)
('red_color= ', 1949)
('green_color= ', 1385)
('blue_color= ', 919)
('BM017 Status=', 17)
('BM017 Status=', 17)
Interrupt On
Interrupt Off
We pointed the sensor at a spool of red wire.  That's why the "red_color" is higher than the green and blue.

No comments:

Post a Comment