Monday, October 31, 2016

Battery level indicator

This weekend I designed a light bar that can be used as an indicator for the battery level of the vehicle. The LED strip uses 8 DotStar RGB LEDs from Adafruit that can each be assigned their own color and brightness.

The board uses a 5 wire interface to connect with the Raspberry Pi:

  • Red wire: 5v
  • Black wire: GND
  • Orange wire: 3.3v
  • Yellow wire: Data (pin 23)
  • Green wire: Clock (pin 24)
The code to run this is incredibly simple. Granted, if you want to do fancy fades and color sweeps you will have to do some research, but turning on a specific LED to a certain color is very straightforward. You will be using the Adafruit library found here: https://github.com/adafruit/Adafruit_DotStar_Pi
It can be cloned to your Pi by navigating to the directory you want to store the files in and typing the command: git clone https://github.com/adafruit/Adafruit_DotStar_Pi

The picture above is a result of me running the following code:

First you have the library/module import. Then you define how many LEDs you have hooked up. Then you set up which RPi pins are to be used for your data and clock signal. Be careful to choose only standard/plain GPIO pins, otherwise you will run into errors. Then you initialize the LED strip with the parameters you've defined. The setBrightness() method takes in an integer from 0-255. I find that the best colors come around the 15-25 range, 255 is just blinding. You're making a battery level indicator, not a pair of high beams for your headlights. The next block of code sets the color of individual LEDs. The parameters of the setPixelColor() method are as follows: (LED#, Green, Red, Blue) Each color can have values from 0-255. All zeroes = no light, all 255 = full blast. Playing around with the RGB combinations for each LED should yield some good colors. Lastly, the show() method writes all of this data to the LEDs and forces the strip to update. Without this, you wouldn't see any of your changes in the lights.

If you have any questions, feel free to ask here or email me. I will be in class on Thursday and will have the indicator strip on hand so you can test it. I expect you guys to have some sort of working code by then, along with a plan on how you're going to map battery voltages to the colors/status of the LEDs.

FYI, You can hook up massive amounts of these to a Pi. You don't need any extra boards or PiHats. If any other groups are interested in using a similar light bar as an indicator, please let me know ASAP. 

No comments:

Post a Comment