Giter VIP home page Giter VIP logo

adafruit_circuitpython_tcs34725's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

CircuitPython module for the TCS34725 color sensor.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-tcs34725

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-tcs34725

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-tcs34725

Usage Example

See examples/tcs34725_simpletest.py for an example of the module's usage.

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_tcs34725's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_tcs34725's Issues

DisplayIO Example Wanted

Add a Basic DisplayIO Based Example

We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.

The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.

The new example should follow the naming convention examples/libraryname_displayio_simpletest.py with "libraryname" being replaced by the actual name of this library.

You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72

We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_tcs34725.py:110
  • adafruit_tcs34725.py:176
  • adafruit_tcs34725.py:195
  • adafruit_tcs34725.py:220
  • adafruit_tcs34725.py:235
  • adafruit_tcs34725.py:272
  • adafruit_tcs34725.py:292
  • adafruit_tcs34725.py:303
  • adafruit_tcs34725.py:370
  • adafruit_tcs34725.py:379
  • adafruit_tcs34725.py:386
  • adafruit_tcs34725.py:393
  • adafruit_tcs34725.py:400

Division by Zero

Both sensor.color_temperature and sensor.lux throw division by zero errors:

Traceback (most recent call last):
File "code.py", line 7, in
File "adafruit_tcs34725.py", line 113, in color_temperature
File "adafruit_tcs34725.py", line 314, in _temperature_and_lux_dn40
ZeroDivisionError: division by zero

Here is my code:

from board import SCL, SDA
from busio import I2C
from adafruit_tcs34725 import TCS34725
i2c = I2C(SCL, SDA)
sensor = TCS34725(i2c)
print('Color: ({0}, {1}, {2})'.format(*sensor.color_rgb_bytes))
print('Temperature: {0}K'.format(sensor.color_temperature))
print('Lux: {0}'.format(sensor.lux))

I think it may be caused when the color source is too bright.

Also there is a typo on the Adafruit tutorial. The property temperature should be color_temperature. It is incorrect in the docs and the example: https://learn.adafruit.com/adafruit-color-sensors/python-circuitpython#circuitpython-and-python-usage-3-7

Can get values greater than 255 from color_rgb_bytes.

Doc string claims the return should be 3-tuple with range 0-255. But it's possible to get values greater than this.

Adafruit CircuitPython 3.0.0 on 2018-07-09; Adafruit CircuitPlayground Express with Crickit libraries with samd21g18
>>> import board, busio
>>> import adafruit_tcs34725
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> sensor = adafruit_tcs34725.TCS34725(i2c)
>>> sensor.integration_time
2.4
>>> sensor.gain
1
>>> sensor.color_rgb_bytes
(18, 25, 9)
>>> sensor.integration_time = 50
>>> sensor.integration_time
48.0
>>> sensor.color_rgb_bytes
(2, 554, 570)
>>> 

Problems with jumping values between two levels

I am using the RGB sensor in a project. There I have made the experience that the sensor shows really strange behaviour for larger value. So at small value the sensor shows the behaviour that is excpected but for large value, so for exemple then the roomlight is on, the sensor starts to jump around 2 different levels. I have ploted the values in the two plots below. What could be the problem ? I am using a gain of 4 and an integration time of 50ms. I have tried to change the integration time but it didn't help.

RGB
RGB_brightness_problem

The experimental setup is:

RGB_experiment_setup

ZeroDivisionError: division by zero on adafruit_tcs34725.py

On /usr/local/lib/python3.5/dist-packages/adafruit_tcs34725.py the function def color_rgb_bytes(self) should check if rgb values are greater than zero to avoid the division by zero exception

File "/usr/local/lib/python3.5/dist-packages/adafruit_tcs34725.py", line 240, in color_rgb_bytes
red = int(pow((int((r/clear) * 256) / 255), 2.5) * 255)
ZeroDivisionError: division by zero

Is the active property actually doing anything?

The sensor returns values regardless of setting of active. What is it really doing?

Adafruit CircuitPython 3.0.0 on 2018-07-09; Adafruit CircuitPlayground Express with Crickit libraries with samd21g18
>>> import board, busio
>>> import adafruit_tcs34725
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> sensor = adafruit_tcs34725.TCS34725(i2c)
>>> sensor.active
False
>>> sensor.color_rgb_bytes
(17, 25, 9)
>>> sensor.active
False
>>> sensor.active = True
>>> sensor.color_rgb_bytes
(17, 25, 9)
>>> sensor.active
True
>>> 

Integration time and response time

When acquiring data sometimes the response time is twice as long as expected. For integration times >90ms it takes ~95ms for the TCS34725 to respond, and expected. For <90ms it takes twice as long (say, 186ms for integration time of 80ms).

This affects situations in a continuous loop, since for integration times < 90ms will have ~50% "sensing" rate. I've wrestled with the problem for a while. It seems to be less of an issue in M4 and in the latest TCS34725 driver (v3.3.3). In M0 and older drivers the issue persisted through all of integration times.

I used the code below for testing

import time
import board
import adafruit_tcs34725
sensorRGB = adafruit_tcs34725.TCS34725(board.I2C())
sensorRGB.integration_time = 90#for integration time 2.4 - 614.4 ms
while True:
tic = time.monotonic()
print(sensorRGB.color_raw)
print(time.monotonic()-tic)

Divide by zero error when LED is off

When the LED is turned off and a white paper is placed very close to the sensor, the color is pure white so it causes a divide by zero error. I have a kind-of fix to this that makes it not have an error when the color is white but doesn't give a very accurate color temperature.

Add a color property

Add a color property that complies with design guide.

Property name Python type Units
color int RGB, eight bits per channel (0xff0000 is red)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.