It's easy to use the AS7262 with Python or CircuitPython and the Adafruit CircuitPython AS726x module.  This module allows you to easily write Python code that reads color data and temperature from the sensor.


CircuitPython Microcontroller Wiring - I2C

You can easily wire this breakout to a microcontroller running CircuitPython. We will be using a Metro M0 Express.

  • Connect GND to common power/data ground
  • Connect the SCL pin to the I2C clock SCL pin on your Feather or Metro M0 (on a Gemma M0 this would be Pad #2/ A1)
  • Connect the SDA pin to the I2C data SDA pin on your Feather or Metro M0 (on a Gemma M0 this would be Pad #0/A2)

CircuitPython Microcontroller Wiring - UART

Here's the wiring to use for UART:

  • Feather 3V to board VIN
  • Feather GND to board GND
  • Feather RX to board RX*
  • Feather TX to board TX*

* Yep, TX to TX and RX to RX, that appears to be the way the AS726x has named things.

Don't forget to solder the UART SELECT jumper to enable UART mode.

Python Computer Wiring - I2C


Here's the Raspberry Pi wired with I2C:

  • Pi 3V3 to sensor VIN
  • Pi GND to sensor GND
  • Pi SDA to sensor SDA
  • Pi SCL to sensor SCL

This sensor uses I2C address 0x49.

CircuitPython Installation of AS726x Library

You'll need to install the Adafruit_CircuitPython_AS726x library library on your CircuitPython board.  



Remember for non-express boards you'll need to manually install the necessary libraries from the bundle:

  • adafruit_as726x.mpy
  • adafruit_bus_device
  • adafruit_register

You can also download the adafruit_as726x.mpy from it's release page on Github.

Before continuing make sure your board's lib folder or root filesystem has the adafruit_as726x.mpy,  adafruit_register, and adafruit_bus_device files and folders copied over.


Python Installation of AS726x Library



  • sudo pip3 install adafruit-circuitpython-as726x


CircuitPython & Python Usage

To demonstrate usage we will initialize the sensor and read it's onboard temperature sensor from the board's Python REPL.


I2C Initialization

For I2C, use the following to create your sensor object:

import board
from adafruit_as726x import AS726x_I2C

i2c = board.I2C()
sensor = Adafruit_AS726x_I2C(i2c)

UART Initialization - CircuitPython

For UART usage on a board (like a Feather) running CircuitPython, use the following to create your sensor object:

import board
from adafruit_as726x import AS726x_UART

uart = board.UART()
sensor = Adafruit_AS726x_UART(uart)


Now you can read the temperature property from the sensor:

print('Temperature: {0}C'.format(sensor.temperature))

As long as you get a reasonable temperature (usually around 28 degrees C) you know your sensor is wired up correctly and working!

Below is a complete example that reads all color channels and prints them out as a graph in the REPL. Save this as on your board and open the REPL to see the output.

# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board

# for I2C use:
from adafruit_as726x import AS726x_I2C

# for UART use:
# from adafruit_as726x import AS726x_UART

# maximum value for sensor reading
max_val = 16000

# max number of characters in each graph
max_graph = 80

def graph_map(x):
    return min(int(x * max_graph / max_val), max_graph)

# for I2C use:
i2c = board.I2C()
sensor = AS726x_I2C(i2c)

# for UART use:
# uart = board.UART()
# sensor = AS726x_UART(uart)

sensor.conversion_mode = sensor.MODE_2

while True:
    # Wait for data to be ready
    while not sensor.data_ready:

    # plot plot the data
    print("V: " + graph_map(sensor.violet) * "=")
    print("B: " + graph_map( * "=")
    print("G: " + graph_map( * "=")
    print("Y: " + graph_map(sensor.yellow) * "=")
    print("O: " + graph_map( * "=")
    print("R: " + graph_map( * "=")


Running the above code should something like this in your REPL:


This page (Python & CircuitPython) was last updated on May 17, 2021.

Text editor powered by tinymce.