adafruit / Adafruit_AS7341

Other
29 stars 18 forks source link

getChannel assumes the wrong data layout for buffer _channel_readings #14

Closed christakahashi closed 1 year ago

christakahashi commented 3 years ago
as7341.readAllChannels();
uint16_t f5dat = as7341.getChannel(AS7341_CHANNEL_415nm_F5);

should store data for f5 in f5dat but stores clear channel data instead.

NOTE: It should be more explicit in the documentation for readAllChannels what the ordering is. It should also say it requires a buffer size of 12 not 10.

j9brown commented 3 years ago

I just encountered the same issue. It's easy to observe this effect in the provided examples.

mermerico commented 2 years ago

Thanks for pointing this out! I was pulling my hair out trying to figure out what I was doing wrong. Your suggested fix (#16) worked for me!

caternuson commented 2 years ago

Just adding more info.

The AMS7341 has 6 channel ADC. To read all the channels, two readings must done, changing SMUX settings between. The app note (AN_AS7341_SMUX_configuration_1V1.pdf) on how to setup the SMUX is buried in the demo code zips that can be downloaded from: https://ams.com/as7341#tab/tools

In this Arduino library code, the following functions configure the SMUX.

setup_F1F4_Clear_NIR() configures the SMUX to be:

ADC  CHAN
---  ----
 0    F1
 1    F2
 2    F3
 3    F4
 4    CLR
 5    NIR

setup_F5F8_Clear_NIR() configures the SMUX to be:

ADC  CHAN
---  ----
 0    F5
 1    F6
 2    F7
 3    F8
 4    CLR
 5    NIR

These are each called from readAllChannels() and the end result is that the internal data buffer _channel_readings has the following layout:

F1
F2
F3
F4
CLR
NIR
F5
F6
F7
F8
CLR
NIR

It's the redundant CLR and NIR values from the first reading that throw off the as7341_color_channel_t enum.

caternuson commented 2 years ago

Please try the 1.3.2 release when it becomes available: https://github.com/adafruit/Adafruit_AS7341/releases/tag/1.3.2

caternuson commented 1 year ago

Closing. Should be fixed by #16.