Coder Social home page Coder Social logo

adafruit / adafruit_circuitpython_si1145 Goto Github PK

View Code? Open in Web Editor NEW
0.0 16.0 5.0 64 KB

CircuitPython helper library for the SI1145 Digital UV Index IR Visible Light Sensor

License: MIT License

Python 100.00%
circuitpython circuitpython-library python hacktoberfest

adafruit_circuitpython_si1145's People

Contributors

caternuson avatar deadsix27 avatar evaherrada avatar foamyguy avatar sokratisvas avatar tannewt avatar tcfranks avatar tekktrik avatar

Watchers

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

adafruit_circuitpython_si1145's Issues

Adafruit SI1145 library throws error when exceeding UINT16 readings

I have an Adafruit SI1145 sensor. I have tested it on an Arduino Uno and it works great. I am shining a red laser on it for testing. The readings for infrared are in the 0-100,000 ballpark.

However, I switched over to CircuitPython on both a Pi Pico and FeatherS2. In both cases, when the reading exceeds 65,535, I get the following error (the first value is the IR reading from the sensor):

(305, 0, 100000)
(304, 0, 100000)
(303, 0, 100000)
(301, 0, 100000)
(304, 0, 100000)
(306, 0, 100000)
(303, 0, 100000)
(302, 0, 100000)
(300, 0, 100000)
(65535, 0, 100000)  <------ shine red laser on it
Traceback (most recent call last):
  File "code.py", line 16, in <module>
  File "/lib/adafruit_si1145.py", line 109, in als
  File "/lib/adafruit_si1145.py", line 165, in _send_command
RuntimeError: SI1145 Error: 0x80

Code done running.

Is this a programming problem where the value is stored in a UINT16 instead of something higher or some limitation in the Pico and ESP32 chips?

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.

Error code getting masked out

This is a minor big. The mask here should be removed:

raise RuntimeError("SI1145 Error: 0x{:02x}".format(response & 0xF0))

Masking the upper 4 bits is useful to detect if there is an error. But the actual error is then coded into the lower 4 bits. So the print should just not mask anything and print the whole response value.
image

Register setting issue

With code from #8, which has been merged, so opening new issue:

Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit QT Py M0 with samd21e18
>>> import board, adafruit_si1145
>>> si1145 = adafruit_si1145.SI1145(board.I2C())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_si1145.py", line 84, in __init__
  File "adafruit_si1145.py", line 127, in uv_index_enabled
  File "adafruit_register/i2c_struct.py", line 43, in __set__
TypeError: 'int' object is not iterable
>>> 

I think these need to be tuples?

self._ucoeff_0 = 0x00
self._ucoeff_1 = 0x02
self._ucoeff_2 = 0x89
self._ucoeff_3 = 0x29

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.