Git Product home page Git Product logo

adafruit_circuitpython_as7341's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython library for use with the Adafruit AS7341 breakout. NOTE: Due to the size of this library, it may not work on M0 (ex: Trinket M0) and other low memory boards.

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-as7341

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

sudo pip3 install adafruit-circuitpython-as7341

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-as7341

Usage Example

from time import sleep
import board
from adafruit_as7341 import AS7341

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = AS7341(i2c)


def bar_graph(read_value):
    scaled = int(read_value / 1000)
    return "[%5d] " % read_value + (scaled * "*")


while True:

    print("F1 - 415nm/Violet  %s" % bar_graph(sensor.channel_415nm))
    print("F2 - 445nm//Indigo %s" % bar_graph(sensor.channel_445nm))
    print("F3 - 480nm//Blue   %s" % bar_graph(sensor.channel_480nm))
    print("F4 - 515nm//Cyan   %s" % bar_graph(sensor.channel_515nm))
    print("F5 - 555nm/Green   %s" % bar_graph(sensor.channel_555nm))
    print("F6 - 590nm/Yellow  %s" % bar_graph(sensor.channel_590nm))
    print("F7 - 630nm/Orange  %s" % bar_graph(sensor.channel_630nm))
    print("F8 - 680nm/Red     %s" % bar_graph(sensor.channel_680nm))
    print("Clear              %s" % bar_graph(sensor.channel_clear))
    print("Near-IR (NIR)      %s" % bar_graph(sensor.channel_nir))
    print("\n------------------------------------------------")
    sleep(1)

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_as7341's People

Contributors

afaghm avatar anecdata avatar askpatrickw avatar bjones14 avatar caternuson avatar dhalbert avatar evaherrada avatar foamyguy avatar garyk10 avatar jposada202020 avatar kattni avatar ladyada avatar mcauser avatar neradoc avatar siddacious avatar tammymakesthings avatar tannewt avatar tekktrik avatar

Stargazers

 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

adafruit_circuitpython_as7341's Issues

Clear and NIR Accessors

Is there a way to get a reading from the Clear and NIR channels on the AS7341? On line 379 of 'adafruit_as7341.py' it is still listed as a TODO. Is this still something that is planning on being added? Thanks so much!

Fix documentation typing for astep and atime

The documentation now says types astep and atime correctly for linters, but not so well for library usage (since the __get__() and __set__() methods mean the actual return values are different. Not sure the correct fix, but wanted to document it for now at least.

Is there a defined "band" for each channel?

image

I assumed 415 meant the measurement was centered at 415nm, though I'm wondering now based on the description of "415nm band" etc. Do you mind clarifying? Where it's centered? What kind of width it has?

F5 - F8 Readings inconsistent with other platforms

Hello,
I am using this code with the AS7341 and a Raspberrypi. I am trying to calibrate the sensor readings with a Spectrometer and I have faced an issue. It seems that the F5-F8 channel readings are incorrect. To verify that it is not a sensor limitation issue, I compared the readings with the readings of the same sensor connected to an Arduino using c++ code (https://github.com/adafruit/Adafruit_AS7341/blob/master/Adafruit_AS7341.cpp). The ATIME, AGAIN, and ASTEP parameters are kept the same in both platforms. The values for the F5-F8 are completely different and those that are obtained with the c++ code are consistent with the actual spectrometer. I cannot day I fully understand the code, but I am guessing something is going wrong in the SMUX config in "_f5f8_clear_nir()". Would anyone please be able to provide some insight into this?

AS7341.reset() does nothing

The docstring says: """Resets the internal registers and restores the default settings""", but the function is empty.

Apologies if this is on the todo list already.

I tried toggling self._power_enabled as a quick workaround, but previous values persisted.

Getting error at line 195 during import - object 'str" is not a tuple or a list

_SmuxOut = namedtuple("_SmuxOut", "DISABLED ADC0 ADC1 ADC2 ADC3 ADC4 ADC5")

Maybe instead formalize second parameter on request to namedtuple as a square bracketed list of string items or as a string containing items delimited by comma space? Maybe CircuitPython can't handle the necessary string to list conversion.

Am attempting to implement software based spectroscope for educational demonstrations using Adafruit # 3500 Trinket M0 connected to Adafruit # 4698 AS7341 breakout.

First time submitting regarding Adafruit offerings. Please let me know if my style and content are conformant to expectations.

Wrong Default for Gain

According to the datasheet the default should be 9 or 256x:

image

I could see this being an issue for someone coming from Arduino or looking at the datasheet graphs.

Setting LED current

Setting the LED current to 0, with sensor.led_current=0 gives the unexpected result of actually setting the current to the maximum value possible, due to wrap around in the calculation.

Suggest modifying line 620 of file to:

    new_current = max(0, min(127,int((led_curent - 4) / 1)))

to coerce current being set to valid range.

regards
dave Langstaff

namedtuple usage doesn't work on all boards.

The syntax here:

_SmuxOut = namedtuple("_SmuxOut", "DISABLED ADC0 ADC1 ADC2 ADC3 ADC4 ADC5")

does not work for all boards. The feature is left out for "small" boards, like:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit QT Py M0 with samd21e18
>>> from collections import namedtuple
>>> foo = namedtuple("foo", "x y z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object 'str' is not a tuple or list
>>> foo = namedtuple("foo", ("x","y","z"))
>>>  

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_as7341.py:106
  • adafruit_as7341.py:108
  • adafruit_as7341.py:121
  • adafruit_as7341.py:133
  • adafruit_as7341.py:297
  • adafruit_as7341.py:391
  • adafruit_as7341.py:399
  • adafruit_as7341.py:478
  • adafruit_as7341.py:635
  • adafruit_as7341.py:648
  • adafruit_as7341.py:658
  • adafruit_as7341.py:675
  • adafruit_as7341.py:687
  • adafruit_as7341.py:697

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.