i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a
microcontroller
is31 = adafruit_is31fl3741.IS31FL3741(i2c)
is31.set_led_scaling(0xFF) # turn on LEDs all the way
is31.global_current = 0xFF # set current to max
is31.enable = True # enable!
# light up every LED, one at a time
while True:
for pixel in range(351):
is31[pixel] = 255
time.sleep(0.01)
is31[pixel] = 0
The LEDs light up one at a time, various colors, and in an arbitrary order!
First you import the necessary modules and library. Then you create the IS31FL3741
object, provide it the board.I2C() object, and save it to is31 .
Next, you do the basic setup needed to control the LEDs. You set all the LEDs to
maximum brightness with set_led_scaling() , set the current to max with global_
current , and enable them by setting enable to True .
Then, inside your loop, you have a for loop iterating over the entire set of pixels
(351 total!), and turning on each one individually for 0.01 seconds before turning it off
and moving on to the next one.
Rainbow Example Code:
To run this example, you need to update your code.py file.
Click the Download Project Bundle button below to download the code.py file (and
the libraries, though you don't need to update them again) in a zip file. Extract the
contents of the zip file, and copy the code.py file to your CIRCUITPY drive.
Your CIRCUITPY drive should resemble the image below.
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import board
from rainbowio import colorwheel
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
import adafruit_is31fl3741
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a
microcontroller
is31 = Adafruit_RGBMatrixQT(i2c, allocate=adafruit_is31fl3741.PREFER_BUFFER)
is31.set_led_scaling(0xFF)
is31.global_current = 0xFF
# print("Global current is: ", is31.global_current)
is31.enable = True
# print("Enabled? ", is31.enable)
wheeloffset = 0
while True:
for y in range(9):
for x in range(13):
is31.pixel(x, y, colorwheel((y * 13 + x) * 2 + wheeloffset))
wheeloffset += 1
is31.show()
The matrix lights up in a slow-moving rainbow pattern!
That's all there is to using the IS31FL3741 LED matrix driver with CircuitPython!
Python Docs
Python Docs()
Arduino
Using the IS31FL3741 with Arduino involves wiring up the matrix to your Arduino-
compatible microcontroller, installing the Adafruit IS31FL3741() library, and running the
Click theManage Libraries ... menu item, search for IS31FL3741 , and select the Adafru
it IS31FL3741 library, and install the latest version:
If asked about dependencies, click "Install all".
Load Rainbow Example
Open upFile -> Examples -> Adafruit IS31FL3741 Library -> qtmatrix-rgbswirl
// Rainbow swirl example for the Adafruit IS31FL3741 13x9 PWM RGB LED
// Matrix Driver w/STEMMA QT / Qwiic connector. This is the simplest
// version and should fit on small microcontrollers like Arduino Uno.
// Tradeoff is that animation isn't always as smooth as seen in the
// buffered example. Each LED changes state immediately when accessed,
// there is no show() or display() function as with NeoPixels or some
// OLED screens.
#include <Adafruit_IS31FL3741.h>
Adafruit_IS31FL3741_QT ledmatrix;
// If colors appear wrong on matrix, try invoking constructor like so:
// Adafruit_IS31FL3741_QT ledmatrix(IS3741_RBG);
// Some boards have just one I2C interface, but some have more...
TwoWire *i2c = &Wire; // e.g. change this to &Wire1 for QT Py RP2040
// Set brightness to max and bring controller out of shutdown state
ledmatrix.setLEDscaling(0xFF);
ledmatrix.setGlobalCurrent(0xFF);
Serial.print("Global current set to: ");
Serial.println(ledmatrix.getGlobalCurrent());
ledmatrix.enable(true); // bring out of shutdown
}
uint16_t hue_offset = 0;
void loop() {
uint32_t i = 0;
for (int y=0; y<ledmatrix.height(); y++) {
for (int x=0; x<ledmatrix.width(); x++) {
uint32_t color888 = ledmatrix.ColorHSV(i * 65536 / 117 + hue_offset);
uint16_t color565 = ledmatrix.color565(color888);
ledmatrix.drawPixel(x, y, color565);
i++;
}
}
hue_offset += 256;
ledmatrix.setGlobalCurrent(hue_offset / 256); // Demonstrate global current
}
After opening the demo file, upload to your Arduino wired up to the matrix. Once you
upload the code, you'll see the matrix light up in a rainbow pattern!
This demo does a simple example showing how to set the color of each pixel using
ledmatrix.drawPixel(x, y, color565) - where x and y are the 0-12 and 0-8
indexed location indicator, and color565 is the 16-bit packed color. We use ledmatr
ix. ColorHSV to get a rainbow color across the spectrum.
Load GFX Example
Open upFile -> Examples -> Adafruit IS31FL3741 Library -> qtmatrix-text
// Scrolling text example for the Adafruit IS31FL3741 13x9 PWM RGB LED
// Matrix Driver w/STEMMA QT / Qwiic connector. This is the simplest
// version and should fit on small microcontrollers like Arduino Uno.
// Tradeoff is that animation isn't always as smooth as seen in the
// buffered example. Each LED changes state immediately when accessed,
// there is no show() or display() function as with NeoPixels or some
// OLED screens.
#include <Adafruit_IS31FL3741.h>
Adafruit_IS31FL3741_QT matrix;
// If colors appear wrong on matrix, try invoking constructor like so:
// Adafruit_IS31FL3741_QT matrix(IS3741_RBG);
// Some boards have just one I2C interface, but some have more...
TwoWire *i2c = &Wire; // e.g. change this to &Wire1 for QT Py RP2040
char text[] = "ADAFRUIT!"; // A message to scroll
int text_x = matrix.width(); // Initial text position = off right edge
if (! matrix.begin(IS3741_ADDR_DEFAULT, i2c)) {
Serial.println("IS41 not found");
while (1);
}
Serial.println("IS41 found!");
// By default the LED controller communicates over I2C at 400 KHz.
// Arduino Uno can usually do 800 KHz, and 32-bit microcontrollers 1 MHz.
i2c->setClock(800000);
// Set brightness to max and bring controller out of shutdown state
matrix.setLEDscaling(0xFF);
matrix.setGlobalCurrent(0xFF);
Serial.print("Global current set to: ");
Serial.println(matrix.getGlobalCurrent());
matrix.fill(0);
matrix.enable(true); // bring out of shutdown
matrix.setRotation(0);
matrix.setTextWrap(false);
// Get text dimensions to determine X coord where scrolling resets
uint16_t w, h;
int16_t ignore;
matrix.getTextBounds(text, 0, 0, &ignore, &ignore, &w, &h);
text_min = -w; // Off left edge this many pixels
}
void loop() {
matrix.setCursor(text_x, text_y);
for (int i = 0; i < (int)strlen(text); i++) {
// set the color thru the rainbow
uint32_t color888 = matrix.ColorHSV(65536 * i / strlen(text));
uint16_t color565 = matrix.color565(color888);
matrix.setTextColor(color565, 0); // backound is '0' to erase previous text!
matrix.print(text[i]); // write the letter
}
if (--text_x < text_min) {
text_x = matrix.width();
}
delay(25);
}
After opening the demo file, upload to your Arduino wired up to the matrix. Once you
upload the code, a scrolling rainbow ADAFRUIT! will show up on your matrix!
This demo uses more of the Adafruit_GFX library to draw text, check out the guide for
Adafruit GFX to learn how to draw circles, lines, triangles, etc!()