Examples
Arduino/C++ Examples
The following examples demonstrate various features of this development board.
β‘ light_sensor
#include <Arduino.h>
const int SENSOR_PIN = 12; // GPIO12 connected to the moduleβs digital output
void setup() {
// Initialize Serial at 115200 baud
Serial.begin(115200);
while (!Serial) { } // Wait for Serial (on some boards)
// Configure GPIO12 as digital input with internal pull-down
pinMode(SENSOR_PIN, INPUT_PULLDOWN);
Serial.println("Reading Qwiic module in digital mode (GPIO12)...");
}
void loop() {
int state = digitalRead(SENSOR_PIN); // Read 0 (LOW) or 1 (HIGH)
if (state == HIGH) {
Serial.println("π Light detected (HIGH)");
π See complete code on GitHub
MicroPython Examples
The following MicroPython examples demonstrate usage with microcontrollers.
π light_sensor_adc
from machine import Pin, ADC
import time
# Configure GPIO6 as ADC input (ESP32C6)
light_sensor = ADC(Pin(6))
# Depending on your board, you may need to set attenuation for higher voltage range
# For ESP32: attenuation can be 0db (0β1V), 2.5db (0β1.34V), 6db (0β2V), 11db (0β3.6V)
try:
light_sensor.atten(ADC.ATTN_11DB) # Full range ~3.6V
except:
pass # Some ports (like RP2040) don't need this
# Optionally set resolution (ESP32 defaults to 12 bits β values 0β4095)
try:
light_sensor.width(ADC.WIDTH_12BIT)
except:
pass
while True:
π See complete code on GitHub
π light_sensor
from machine import Pin
import time
# --- DIGITAL INPUT CONFIGURATION ---
# Use GPIO12 as a digital input with internal pull-down
sensor_digital = Pin(12, Pin.IN, Pin.PULL_DOWN)
print("Reading Qwiic module in digital mode (GPIO12)...")
while True:
state = sensor_digital.value() # 0 = LOW, 1 = HIGH
if state:
print("π Light detected (HIGH)")
else:
print("π No light (LOW)")
time.sleep(0.5)