Ht16k33Multi
Ht16k33Multi is a library for controlling one or more Ht16k33 microchips,
which are commonly used to drive 7-segment displays, such as these shown below:
The docs can be found at https://hexdocs.pm/ht16k33_multi.
Features
The main features of Ht16k33Multi include:
- Displaying numbers on a 7-segment display
- Displaying words using a special 7-segment font
-
Supporting multiple displays (hence the "multi" in the library name).
You can easily chain multiple
Ht16k33devices to display full sentences or other content across them. -
Utilizing the built-in blinking and dimming features of the
Ht16k33microchip
Usage
A typical setup involves using the Ht16k33 with a 7-segment display and a Raspberry Pi — such as the Raspberry Pi Zero.
You can use the Nerves Project to build firmware for the Raspberry Pi and other embedded systems like the BeagleBone. See the list of supported targets (Nerves Project) for more information.
Installation
Connect the
Ht16k33to your embedded system. See the Connect the device to the I²C bus and power section for details.Add the library to your dependencies
# mix.exs defp deps do [ {:ht16k33_multi, "~> 0.2.2"} ] endFetch the dependencies
mix deps.getStart the
Ht16k33MultiGenServerYou can start it manually in
iex:iex> Ht16k33Multi.start_link()Or supervise it within your application:
children = [ # Single device with default I²C bus ("i2c-1") and address (0x70) Ht16k33Multi, # OR with explicit options {Ht16k33Multi, i2c_bus: "i2c-1", address: 0x70} ]If you're using multiple devices (all on the default I²C bus
"i2c-1"), assign each a name and address:children = [ {Ht16k33Multi, name: :red_leds, address: 0x70}, {Ht16k33Multi, name: :blue_leds, address: 0x71}, {Ht16k33Multi, name: :yellow_leds, address: 0x72} ]Detect I2C Bus and Device Address
See the Device Address section to learn how to detect your I²C bus and device address.
Write to the display
Display a message:
iex> Ht16k33Multi.write("Hola")Enable blinking:
iex> Ht16k33Multi.blinking_on()Dim the display:
iex> Ht16k33Multi.dimming(6)
Connect the Device to the I2C Bus and Power
Using Qwiic with a Raspberry Pi Zero (rpi0)
You can easily chain multiple Ht16k33 devices using Qwiic cables. This allows you to have multiple displays showing full sentences or other content.
Wiring Overview:
| Wire Color | Function | Raspberry Pi Zero Pin | GPIO Pin |
|---|---|---|---|
| Black | GND | 6 | GND |
| Red | 3.3V | 4 | 5V |
| Blue | SDA (Serial Data) | 3 | GPIO2 |
| Yellow | SCL (Serial Clock) | 5 | GPIO3 |
Device Address
You can detect the I²C bus and device addresses using Circuits.I2C:
iex> Circuits.I2C.bus_names()
["i2c-1"]
iex> Circuits.I2C.detect_devices()
Devices on I2C bus "i2c-1":
* 112 (0x70)
1 devices detected on 1 I²C busesThe device address is configurable in hardware. You can set it by soldering the address pins (shown at the bottom right in the image below).
See the HT16K33 datasheet for more details.
Testing
This library has been tested with the Adafruit 7-Segment LED HT16K33 Backpack.
Documentation
The docs can be found at https://hexdocs.pm/ht16k33_multi.