AS7343 tinkering

What is the source of illumination? I ask because my Plasma RGB LED Strip will give uneven results even when set to white. 515 and 600 nm hardly move at all, while 475, 550 and 555 track the intensity nicely. I also get weird results from the LED Lights in my overhead ceiling fan.

My eyes / brain see white, but the sensor knows better. ;)

It’s 9:PM and dark outside. I’m an early bird so I’ll plug mine into a battery tomorrow morning and watch what happens as the sun comes up. I’m usually up before sunrise. And take my dog for an early morning walk after the sun comes up. On battery it’s portable and not tethered to my PC desk. I’ll position it so its in direct unfiltered sunlight.

Hi

I was using the on board led. It doesn’t matter what it reflects off, or direct light - always same - low or fixed small reading for those 3 channels.

Tony

Ok, I think I’m seeing simile results? I’ll know in an hour or so. It’s 4:40 AM here and the sun comes up a little after 5 AM. I have the onboard LED’s turned off. It’s just my personal preference. I have another thread on that subject here.
LEDs on Light Sensor Breakouts, what are they for? - Support - Pimoroni Buccaneers

I’m seeing the same thing, 515, 600, and 690nm are all very low compared to the others, even in bright sunlight. Might be time to post this on github or e-mail tech support.
I’m thinking its maybe a library issue? I’m going to try and test it in Python on a Pi. I have a 3A+ with a Breakout Garden Hat attached that I use to test breakouts when I get them. No surprises later on if they sit on the shelf for a month or more before I actually use them. I’ll post my results after I get it all setup with a Monitor keyboard and mouse.

1 Like

My lack of skill with Python Virtual Environments is a hindrance to say the least. Software install was easy peasy, it sets it all up for you.
Trying to run an example, not so much. I have to sit down and figure out the correct path to enter from command line, etc.
Not feeling well, blue glucose low alarm just went off on my blood glucose monitor. Now I know why I wasn’t feeling well. May noy get back to this tonight. :(

Hi Kerry

The raw value returned from enumerate(readings) for the three dodgy channels is 11.0 for low light and 139.0 for high. A typical good channel returns values in the 1000’s.
I’ve sent in an issue at the github repository.

Tony

1 Like

I think you may have posted that issue in the wrong place.
Pico / Micro Python issues go here, as far I know anyway.
pimoroni/pimoroni-pico: Libraries and examples to support Pimoroni Pico add-ons in C++ and MicroPython. (github.com)

I’m not feeling very well today, but I am going to try and get back to checking it in Python on a Pi. Just laying low for now to see if my back and neck pain ease up any. I did some yard work yesterday and I’m paying for it today. I suffer from Chronic neck and lower back pain. Some days worse than others.

Both repositories seem to be run by Gadgetoid, but I’ll repost to the one you have linked to.

Get well soon. I’ve been suffering from back pain as well - excruciating trapped nerve. I’ve been using electro-therapy pads which seems to have cured it. for now

Me marking this thread as Solved likely stopped others from looking at it. So I’ve unmarked it. I’m also going to ping a few Pimoroni staff.
@gadgetoid @hel

Finally feeling better, and have some free time.
I ran spectrum.py which shows Violet: 18. That is way low compared to the others.

Red: is F7
Orange: is FXL
Yellow: is F5
Green: is F4
Blue: is F3
Violet: is F1

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Aug 21 16:24:13 2024
kyrie@Pi400:~ $ source ~/.virtualenvs/pimoroni/bin/activate
(pimoroni) kyrie@Pi400:~ $ cd as7343-python
(pimoroni) kyrie@Pi400:~/as7343-python $ cd examples
(pimoroni) kyrie@Pi400:~/as7343-python/examples $ python3 spectrum.py

Red:    234
Orange: 295
Yellow: 134
Green:  316
Blue:   247
Violet: 18

Red:    222
Orange: 286
Yellow: 120
Green:  303
Blue:   233
Violet: 18

And I ran test.py. I haven’t interpreted that one just yet.

   Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Aug 21 19:21:27 2024 from 192.168.2.11
kyrie@Pi400:~ $ cd as7343-python
kyrie@Pi400:~/as7343-python $ cd examples
kyrie@Pi400:~/as7343-python/examples $ python3 test.py
Traceback (most recent call last):
  File "/home/kyrie/as7343-python/examples/test.py", line 3, in <module>
    from as7343 import AS7343
ModuleNotFoundError: No module named 'as7343'
kyrie@Pi400:~/as7343-python/examples $ source ~/.virtualenvs/pimoroni/bin/activate
(pimoroni) kyrie@Pi400:~/as7343-python/examples $ python3 test.py
    FZ (B)    53 | FY (G)    11 | FXL (O/R)    17 | NIR        6 | VIS(TL)    42 | VIS(BR)    28 | SAT False | GAIN 00x
    F2 (V)    66 | F3 (B)    27 | F4  (C)      30 | F6 (O)    34 | VIS(TL)     3 | VIS(BR)    27 | SAT False | GAIN 00x
    F1 (V)    20 | F5 (Y)    20 | F7  (R)      21 | F8 (R)   110 | VIS(TL)     3 | VIS(BR)    26 | SAT False | GAIN 00x

    FZ (B)    53 | FY (G)    11 | FXL (O/R)    17 | NIR        6 | VIS(TL)    39 | VIS(BR)    27 | SAT False | GAIN 00x
    F2 (V)    66 | F3 (B)    27 | F4  (C)      30 | F6 (O)    34 | VIS(TL)     3 | VIS(BR)    26 | SAT False | GAIN 00x
    F1 (V)    20 | F5 (Y)    20 | F7  (R)      21 | F8 (R)   110 | VIS(TL)     3 | VIS(BR)    27 | SAT False | GAIN 00x

    FZ (B)    53 | FY (G)     8 | FXL (O/R)    17 | NIR        6 | VIS(TL)    38 | VIS(BR)    29 | SAT False | GAIN 00x
    F2 (V)    66 | F3 (B)    27 | F4  (C)      33 | F6 (O)    38 | VIS(TL)     3 | VIS(BR)    29 | SAT False | GAIN 00x
    F1 (V)    20 | F5 (Y)    26 | F7  (R)      25 | F8 (R)   122 | VIS(TL)     4 | VIS(BR)    31 | SAT False | GAIN 01x

^CTraceback (most recent call last):
  File "/home/kyrie/as7343-python/examples/test.py", line 18, in <module>
    time.sleep(1.5)
KeyboardInterrupt

(pimoroni) kyrie@Pi400:~/as7343-python/examples $

EDIT: Had time to have a look
The three problem channels are I believe FXL, F4 and F7? Which to me look OK in test.py.
FXL (O/R) 17
F4 (C) 30
F7 (R) 21

Hi Kerry

Using demo from here:

Slight mod because the breakout garden command is wrong, but this gives the same two state values 11.0 and 139.0 for the three channels F1, F2 and FZ.

Readings at a lowish light level with the LEDs off are:
FZ: 139.0, FY: 172.0, FXL: 312.0, NIR: 293.0, F2: 139.0, F3: 92.0, F4: 195.0, F6: 258.0, F1: 139.0, F5: 40.0, F7: 374.0, F8: 273.0
And at a very low level:
FZ: 11.0, FY: 5.0, FXL: 8.0, NIR: 8.0, F2: 11.0, F3: 2.0, F4: 7.0, F6: 7.0, F1: 11.0, F5: 1.0, F7: 6.0, F8: 4.0

Tony

You can simplify the i2c code.
For my Pico Explorer W it’s as follows.

from pimoroni_i2c import PimoroniI2C
i2c = PimoroniI2C(sda=20, scl=21)

It’s just a matter of knowing what pins said device your coding for is using. ;)

Edit: I have been conversing with Hel Gibbons about this. She doesn’t think its a sensor issue, per say. But she is hoping Phil Howard can find some time to look at it. He is currently bogged down with the Pico 2 release stuff. IMHO, they need more staff.

Problem solved by @gadgetoid on github.
[-breakout-] AS7343 · Issue #989 · pimoroni/pimoroni-pico (github.com)

1 Like

I’ve added to the new code, by using the Y button to swap between channel names and nanometres. There’s a slight anomaly in the 555, 550 order - I’m not sure whether gadgetoid has them correct.
Tony

from AS7343 import AS7343
from pimoroni_i2c import PimoroniI2C
from picographics import PicoGraphics, DISPLAY_PICO_W_EXPLORER, PEN_P4
from pimoroni import Button
import time

i2c = PimoroniI2C(sda=20, scl=21)
as7343 = AS7343(i2c)

button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)

display = PicoGraphics(display=DISPLAY_PICO_W_EXPLORER, pen_type=PEN_P4, rotate=270)
display.set_font("bitmap8")
display.set_backlight(0.5)

WIDTH, HEIGHT = display.get_bounds()

BLACK = display.create_pen(0, 0, 0)

F1 = display.create_pen(130, 0, 200)
F2 = display.create_pen(84, 0, 255)
FZ = display.create_pen(0, 70, 255)
F3 = display.create_pen(0, 192, 255)
F4 = display.create_pen(31, 255, 0)
FY = display.create_pen(179, 255, 0)
F5 = display.create_pen(163, 255, 0)
FXL = display.create_pen(255, 190, 0)
F6 = display.create_pen(255, 33, 0)
F7 = display.create_pen(255, 0, 0)
F8 = display.create_pen(171, 0, 0)
NIR = display.create_pen(97, 0, 0)

WHITE = display.create_pen(255, 255, 255)

# Starting max values for auto-ranging
MAX_VALUES = [
    7186,
    2196,
    2711,
    962,
    3926,
    4684,
    1967,
    5970,
    4170,
    6774,
    1080,
    13226
]

# List order for values
ORDER = [
    "F1",
    "F2",
    "FZ",
    "F3",
    "F4",
    "FY",
    "F5",
    "FXL",
    "F6",
    "F7",
    "F8",
    "NIR"
]
ORDER2 = [
    "405",
    "425",
    "450",
    "475",
    "515",
    "555",
    "550",
    "600",
    "640",
    "690",
    "745",
    "855"
]

MARGIN = max([display.measure_text(l) for l in ORDER]) + 2

BAR_WIDTH = 16
BAR_SPACING = 4
BAR_HEIGHT = WIDTH - MARGIN

OFFSET_LEFT = int((HEIGHT - 110 - ((BAR_WIDTH + BAR_SPACING) * 12)) / 2)

WHICH_LABEL = 0

while True:
    display.set_pen(0)
    display.clear()
    readings = as7343.read()
        
    for i , label in enumerate(ORDER):
        reading = readings[label]
 #           print (i,label,reading)
 #           print (i,ORDER2[i], reading)
        MAX_VALUES[i] = max(reading, MAX_VALUES[i])
        scaled = int(reading / MAX_VALUES[i] * BAR_HEIGHT)
    
        y = (i + 1) * (BAR_WIDTH + BAR_SPACING)
        y += OFFSET_LEFT

        display.set_pen(i + 1)
        display.rectangle(MARGIN, y, scaled, BAR_WIDTH)

        display.set_pen(WHITE)
        if WHICH_LABEL == 0:
            display.text(label, 0, y + 1)
        else:
            display.text(ORDER2[i], 0, y + 1)
            
    display.update()

    if button_b.is_pressed:
        as7343.set_illumination_led(False)

    elif button_a.is_pressed:       
        as7343.set_illumination_current(4)
        as7343.set_illumination_led(True)

    elif button_x.is_pressed:
        as7343.set_illumination_current(10)
        as7343.set_illumination_led(True)
        
    elif button_y.is_pressed:
        WHICH_LABEL = not WHICH_LABEL
        time.sleep(0.5)

    time.sleep(0.01)

Yeah, I swapped those two back around. They are also swapped on the data sheet. So that may be why?

The problem is to know where FY and F5 are swapped.
There are other problems as well. The AGC action by increasing the scaling factor is not quite correct. When the sensor has high even illumination - ie white paper with the LEDs on, the MAX_VALUES get increased to scale back the bar length, but it seems the channels are not linear, because lower illumination then shows that F5 now has too little gain WRT the adjacent ones.

Aha - I understand the last point - a channel like F5 has less gain, but does eventually saturate at 10000 like the other channels, which results in the MAX_VALUES array being populated with 10000. So when the illumination is reduced, the low responsivity is not corrected.

The data sheet lists the channels as
F1, F2, FZ, F3, F4, FY, F5, FXL, F6, F7, F8, NIR.
FY is 555 and F5 is 550, the rest all go in order from lowest to highest.
Maybe they don’t need to be swapped?
Page 6 Optical Characteristics.
AS7352: Datasheet (English) (shopify.com)

Unless you have a very narrowband spectrometer, it’s very difficult to differentiate between Fy and F5. Clearly the nm are in the wrong order, but is that the sensor or the code?

I’m getting some nice real data from the channels, as well as the bar graphs now. I’ve more or less tweaked the MAX_VALUES to get an even looking spectrum with reflection off white paper.

2 Likes

I’ve moved mine over to a different setup. Pico Omnibase, Display Pack v2, Pico (RP2040) and PiCowbell Proto. The Proto has a QWICC port and reset button.
I left the channel order alone and just swapped the 555 and 550 labels.

1 Like