Skip to content

USB HID Ambient Light Sensor (ALS) implementation using Digispark Attiny85-based microcontroller development board

License

Notifications You must be signed in to change notification settings

MatejKocourek/spark-als

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spark-als

This project contains open-source firmware for an USB HID Ambient Light Sensor (ALS) implementation using Digispark Attiny85-based microcontroller development board and BH1750FVI I2C light sensor module.

Fork

This repository is a fork of 3cky/tiny-hid-als. Their work inspired my project, which aims to improve on:

Functionality

My project extends the functionality of the ALS sensor, for example introducing support for absolute and relative thresholding and reporting more information about the sensor to the driver.

Adhering to standard

The original project did not follow Microsoft's requirements for ALS sensors, meaning there wasn't any guarantee that functionality such as automatic brightness will work. I tried to change that to the best of my understanding of the official sensor implementation guide (here, here, here and here). Theoretically, the project should now pass WHQL certification.

Resolution

My project increases the sampling resolution to about 0.15 lux. This increases the usability of the sensor in dark conditions, while also making it possible to detect very small fluctuations of light across the whole spectrum. It is possible to drive down the resolution to 0.11 lux, but this limits the dynamic range under the required 10,000 lux for auto brightness control in Windows.

Code size and RAM usage

My project reduces the code size (it is around 17% smaller), while at the same time incorporating significantly more code logic. This is largely due to creating my own extremely lightweight library for communication with the sensor from the ground up, making use of felias-fogg/SoftI2CMaster more efficient I2C implementation instead of widely used Wire.h, and using zero-overhead constexpr functions for pre-calculating parts of formulas for conversion of values in compile time. The code size could potentially be reduced even further, for example by using fixed-point decimal library instead of floats, or focusing on rewriting main logic for code size, but there shouldn't be a need as it fits onto Attine85 with ease.

Documentation

I tried to explain the functionality of the project in the code through comments. Extra attention is added to the new sensor library, making it easy to change parameters, if necessary.

Issues

Please feel free to create an issue if you discover a bug, or discuss if you think I misinterpreted the standard. I tried to debug with all tools available to me, but this is my first bigger project implementing HID device and mistakes could have been made.

Schematic

Digispark connected to BH1750

OS support

USB HID sensors framework is supported out of the box since Linux 3.7 and Windows 8.

Compiling and installing

First, please install PlatformIO open source ecosystem for IoT development compatible with Arduino code and its command line tools (Windows, MacOs and Linux). Also, you may need to install git in your system.

Note: with platformIO you don't need the Arduino IDE and install libraries, this will do it for you.

Compiling and installing:

pio run --target upload

Note: you need connect your Digispark after each compiling for upload the new firmware or reset it. More info here.

License

This project is distributed with GPL license, see LICENSE file for more informations.

About

USB HID Ambient Light Sensor (ALS) implementation using Digispark Attiny85-based microcontroller development board

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 73.9%
  • Assembly 14.9%
  • C++ 11.2%