Adafruit As7341 10 Channel Light Color Sensor Breakout
Adafruit As7341 10 Channel Light Color Sensor Breakout
Sensor Breakout
Created by Bryan Siepert
https://learn.adafruit.com/adafruit-as7341-10-channel-light-color-sensor-breakout
Overview 3
Pinouts 5
• Power Pins
Arduino 6
• I2C Wiring
• Library Installation
• Load Example
• Example Code
Arduino Docs 9
Python Docs 14
Downloads 14
• Files
• Schematic
• Fab Print
• 3D Model
11 readable individual sensor elements ( 10 light channels plus flicker detection) don’t
exactly fit through a 6-channel ADC all at once, so the chip includes a so-called Super
MUX (SMUX) that allows you to route the signal from any sensor to any ADC channel.
Now that’s some super multiplexing! The sensor also has GPIO and interrupt pins that
can allow it to communicate directly with other sensors, or the microcontroller itself.
All of this capability is made accessible by mounting the sensor on a Stemma QT form
factor breakout board, complete with level shifting circuitry and SparkFun
Qwiic (https://adafru.it/Fpw) compatible Stemma QT (https://adafru.it/Ft4) connectors.
This means that you can, without needing to solder, connect our AS7341 breakout into
your 3.3V or 5V microcontroller of choice be it an Arduino Uno, Raspberry Pi, or one
Pinouts
Power Pins
• VIN - this is the power pin. Since the sensor chip uses 1.8 VDC, we have
included a voltage regulator on board that will take 3-5VDC and safely convert it
down. To power the board, give it the same power as the logic level of your
microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
• SCL - I2C clock pin, connect to your microcontroller I2C clock line. This pin is
level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.
• SDA - I2C data pin, connect to your microcontroller I2C data line. This pin is
level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.
• STEMMA QT (https://adafru.it/Ft4) - These connectors allow you to connectors to
dev boards with STEMMA QT connectors or to other things with various
associated accessories (https://adafru.it/Ft6)
Other Pins
• INT-This is the interrupt pin. You can setup the AS7341 to pull this low when
certain conditions are met such as new measurement data being available.
Consult the datasheet (https://adafru.it/MFH) for usage
• GPIO - This is a General Purpose Input Output pin that can be controlled via the
AS7341 and can be used to trigger measurements. Consult the datasheet (https:/
/adafru.it/MFH) for usage
Arduino
Using the AS7341 with Arduino is a simple matter of wiring up the sensor to your
Arduino-compatible microcontroller, installing the Adafruit AS7341 (https://adafru.it/
MFI) library we've written, and running the provided example code.
I2C Wiring
Use this wiring if you want to connect via I2C interface. The I2C address for the
AS7341 is 0x39
Here is how to wire up the sensor using one of the STEMMA QT (https://adafru.it/Ft4)
connectors. The examples show a Metro but wiring will work the same for an Arduino
or other compatible board.
Library Installation
You can install the Adafruit AS7341 library for Arduino using the Library Manager in
the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit AS7341, and select the A
dafruit AS7341 library:
Load Example
Open up File -> Examples -> Adafruit AS7341 -> get_channel
After opening the demo file, upload to your Arduino wired up to the sensor. Once you
upload the code, you will see the raw readings for each light frequency band being
printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud,
similar to this:
Example Code
/* This example will read all channels from the AS7341 and print out reported
values */
#include <Adafruit_AS7341.h>
Adafruit_AS7341 as7341;
void setup() {
Serial.begin(115200);
as7341.setATIME(100);
as7341.setASTEP(999);
as7341.setGain(AS7341_GAIN_256X);
}
void loop() {
// Read all channels at the same time and store in as7341 object
if (!as7341.readAllChannels()){
Serial.println("Error reading all channels!");
return;
}
Serial.print("Clear : ");
Serial.println(as7341.getChannel(AS7341_CHANNEL_CLEAR));
Serial.print("Near IR : ");
Serial.println(as7341.getChannel(AS7341_CHANNEL_NIR));
Serial.println("");
}
Arduino Docs
Arduino Docs (https://adafru.it/MC3)
You can use this sensor with any CircuitPython microcontroller board or with a
computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-
Python compatibility library (https://adafru.it/BSN).
First wire up a AS7341 to your board exactly as shown below. Here's an example of
wiring a Feather M4 to the sensor with I2C using one of the handy STEMMA QT (https
://adafru.it/Ft4) connectors:
You can also use the standard 0.100" pitch headers to wire it up on a breadboard:
Here's the Raspberry Pi wired to the sensor using I2C and a STEMMA QT (https://
adafru.it/Ft4) connector:
First make sure you are running the latest version of Adafruit CircuitPython (https://
adafru.it/Amd) for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow
the steps to find and install these libraries from Adafruit's CircuitPython library bundle
(https://adafru.it/ENC). Our CircuitPython starter guide has a great page on how to
install the library bundle (https://adafru.it/ABU).
Before continuing make sure your board's lib folder or root filesystem has the adafruit
_AS7341.mpy file as well as the adafruit_bus_device and adafruit_register folders.
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
Run the following code to import the necessary modules and initialize the I2C
connection with the sensor:
i2c = board.I2C()
sensor = AS7341(i2c)
Now you're ready to read values from the sensor using these properties using the
code below
Example Code
def bar_graph(read_value):
scaled = int(read_value / 1000)
return "[%5d] " % read_value + (scaled * "*")
while True:
print("F1 - 415nm/Violet %s" % bar_graph(sensor.channel_415nm))
print("F2 - 445nm//Indigo %s" % bar_graph(sensor.channel_445nm))
print("F3 - 480nm//Blue %s" % bar_graph(sensor.channel_480nm))
print("F4 - 515nm//Cyan %s" % bar_graph(sensor.channel_515nm))
print("F5 - 555nm/Green %s" % bar_graph(sensor.channel_555nm))
print("F6 - 590nm/Yellow %s" % bar_graph(sensor.channel_590nm))
print("F7 - 630nm/Orange %s" % bar_graph(sensor.channel_630nm))
print("F8 - 680nm/Red %s" % bar_graph(sensor.channel_680nm))
print("Clear %s" % bar_graph(sensor.channel_clear))
Python Docs
Python Docs (https://adafru.it/MC4)
Downloads
Files
• AS7341 Datasheet (https://adafru.it/MFH)
• EagleCAD files on GitHub (https://adafru.it/MFK)
• 3D Models on GitHub (https://adafru.it/19EW)
• Fritzing object in the Adafruit Fritzing Library (https://adafru.it/MFL)
Schematic
3D Model