AccelerationConsortium / ac-training-lab

Codebase for controlling and managing the Acceleration Consortium (AC) Training Lab.
https://ac-training-lab.readthedocs.io/
MIT License
8 stars 2 forks source link

Test out AS7341 sensor in liquid color matching #87

Open Neil-YL opened 1 day ago

Neil-YL commented 1 day ago

Currently, we have the charging port and sensor package assembled for the liquid color matching demo. It is necessary to test the performance of the AS7341 color sensor for detecting liquid dye in a well plate within the packaging.

I will start by using the code from the micro-course LED color sensor demo for testing.

Neil-YL commented 1 day ago

Schematic of Picowbell: https://learn.adafruit.com/adafruit-proto-under-plate-picowbell/downloads

Raspberry Pi Pico W Pinout:

image

Update: Following setting is wrong, check https://github.com/AccelerationConsortium/ac-training-lab/issues/87#issuecomment-2433458291 for correct setting SCL - GPIO5 - Pin(7) -Pin(5) SDA - GPIO4 - Pin(6)-Pin(4)

By charging the i2c to scl=Pin(7),sda=Pin(6), it should be able to set up the connection of AS7341.

I used a script to see if I can obtain data from the sensor (along with the as7341.py and as7341_sensor.py from the micro-course demo)

from machine import I2C, Pin
from as7341_sensor import Sensor  

def test_as7341():
    try:

        i2c = I2C(1, scl=Pin(7), sda=Pin(6))  # Use GPIO 5 for SCL and GPIO 4 for SDA

        # Pass the i2c object to the Sensor class
        sensor = Sensor(atime=100, astep=999, gain=128, i2c=i2c)

        # Retrieve and print all channel data
        channel_data = sensor.all_channels
        print("Spectral Data (F1 to F8):", channel_data)

        # Retrieve and print all channels along with CLR and NIR data
        channel_clr_nir_data = sensor.all_channels_clr_nir
        print("Spectral Data (F1 to F8, CLR, NIR):", channel_clr_nir_data)

        # Optionally disable the sensor at the end of the test
        sensor.disable()
        print("Sensor disabled.")

    except Exception as e:
        print(f"An error occurred: {e}")

# Run the test
test_as7341()

However it returned:

Detected devices at I2C-addresses: I2C read_byte at 0xA9, error [Errno 5] EIO I2C write_byte at 0xA9, error [Errno 5] EIO I2C write_byte at 0x70, error [Errno 5] EIO I2C read_byte at 0xA9, error [Errno 5] EIO I2C write_byte at 0xA9, error [Errno 5] EIO I2C write_byte at 0x80, error [Errno 5] EIO I2C write_byte at 0x80, error [Errno 5] EIO I2C read_byte at 0x92, error [Errno 5] EIO Failed to contact AS7341 at I2C address 0x39 An error occurred: Failed to contact AS7341, terminating

It seems the controller is not able to communicate with the AS7341 sensor over the I2C setting.

I run the same test code with my micro-course demo(changing the pin back to 27 and 26) it did set up the connection and obtained data from the sensor.

sgbaird commented 1 day ago

Are you using the stemma qt port on the picowbell?

EDIT: Sorry, realizing answer is yes from context

Let's try interchanging some components as a first debugging step.

Neil-YL commented 1 day ago

i2c = I2C(0, scl=Pin(5), sda=Pin(4)) # Use GPIO 5 for SCL and GPIO 4 for SDA

This is the correct i2c to use the stemma qt port on the Picowbell:

MPY: soft reboot Detected devices at I2C-addresses: 0x39 Spectral Data (F1 to F8): [238, 655, 943, 1148, 1953, 2038, 2559, 1464] Spectral Data (F1 to F8, CLR, NIR): [238, 654, 941, 1145, 1962, 2049, 2571, 1474, 4143, 371] Sensor disabled.