Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test out AS7341 sensor in liquid color matching #87

Open
Neil-YL opened this issue Oct 23, 2024 · 3 comments
Open

Test out AS7341 sensor in liquid color matching #87

Neil-YL opened this issue Oct 23, 2024 · 3 comments
Assignees

Comments

@Neil-YL
Copy link
Contributor

Neil-YL commented Oct 23, 2024

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 Neil-YL self-assigned this Oct 23, 2024
@Neil-YL
Copy link
Contributor Author

Neil-YL commented Oct 23, 2024

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 #87 (comment) 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
Copy link
Member

sgbaird commented Oct 23, 2024

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
Copy link
Contributor Author

Neil-YL commented Oct 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants