You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Qwiic Breakout for the 14-channel Multi-Spectral Sensor AS7343 from AMS.
1
+
SparkFun Spectral Sensor - AS7343 (Qwiic)
2
+
=========================================
3
+
[](https://www.sparkfun.com/sparkfun-spectral-sensor-as7343-qwiic.html)
4
+
5
+
6
+
The SparkFun Spectral Sensor Breakout - AS7343 (Qwiic) offers a highly accurate but compact spectral analysis tool for both the visible spectrum and near-infrared. The AS7343 senses light between ~380mn to 1000mn over 14 channels with 11 color bands across the visible spectrum, one near-infrared channel, one clear channel (full sensing spectrum) along with flicker detection. The AS7343 also has an interrupt pin to trigger events based on specific measurements from the sensor as well as a programmable GPIO pin to help synchronize measurements with external devices. This breakout comes standard with a bright white LED for taking measurements but also includes connection points for users who wish to use their own LED if needed.
7
+
8
+
Repository Contents
9
+
-------------------
10
+
11
+
***/Documentation** - Data sheets, additional product information
12
+
***/Hardware** - Eagle design files (.brd, .sch)
13
+
***/Production** - Production panel files (.brd)
14
+
***/docs** - Documentation files for the Spectral UV Sensor
15
+
***/overrides** - Overrides for GitHub pages content
16
+
17
+
Documentation
18
+
--------------
19
+
***[Arduino Library](https://github.com/sparkfun/SparkFun_AS7343_Arduino_Library/tree/main)** - Arduino library for the Spectral Sensor - AS7343 (Qwiic).
20
+
***[Python Package](https://github.com/sparkfun/qwiic_as7343_py)** - Python package for the Spectral Sensor - AS7343 (Qwiic)
21
+
***[Hookup Guide](https://docs.sparkfun.com/SparkFun_Spectral_Sensor_Breakout_AS7343_Qwiic)** - Basic hookup guide for the Spectral Sensor - AS7343 (Qwiic).
Please review the LICENSE.md file for license information.
33
+
34
+
If you have any questions or concerns on licensing, please contact technical support on our [SparkFun forums](https://forum.sparkfun.com/viewforum.php?f=152).
Copy file name to clipboardExpand all lines: docs/arduino_examples.md
+81-7Lines changed: 81 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ Let's take a closer look at the examples included in the SparkFun AS7343 Arduino
2
2
3
3
## Example 1 - Basic Readings
4
4
5
-
The first example sets up the AS7343 to operate with default settings and outputs data from just four channels (Red, Green, Blue and NIR). Open the example in Arduino by navigating to **File** > **Examples** > **SparkFun AS7343 Arduino Library** > **Example_01_BasicReadings**. Next, select your board (RedBoard IoT - ESP32) and Port and click the "Upload" button. After the code finishes compiling and uploading, open the [serial monitor]() with the baud set to **115200** and you should see readings for red, blue, green and NIR print out like the screenshot below shows:
5
+
The first example sets up the AS7343 to operate with default settings and outputs data from just four channels (Red, Green, Blue and NIR). Open the example in Arduino by navigating to **File** > **Examples** > **SparkFun AS7343 Arduino Library** > **Example_01_BasicReadings**. Next, select your board (RedBoard IoT - ESP32) and Port and click the "Upload" button. After the code finishes compiling and uploading, open the [serial monitor](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor/) with the baud set to **115200** and you should see readings for red, blue, green and NIR print out like the screenshot below shows:
6
6
7
7
<figuremarkdown>
8
8
[{ width="600"}](./assets/img/AS7343_Arduino_Example1.jpg"Click to enlarge")
@@ -12,13 +12,36 @@ The first example sets up the AS7343 to operate with default settings and output
12
12
13
13
Example 2 - All Channels shows how to set up the AS7343 with default settings to print out all spectral data from the sensor. This example is nearly identical to the first outside of the serial data printed out. Instead of getting and printing data from four specific channels, this example requests data from all channels and prints it as comma separated values. Open the example in Arduino by navigating to **File** > **Examples** > **SparkFun AS7343 Arduino Library** > **Example_02_AllChannels**.
14
14
15
-
In order to get data from all channels, the AS7343 takes measurements in three cycles with each one stepping through four individual channels combined with readings from the Clear/VIS and Flicker Detect/FD which is then stored in the sensor's data registers. The example prints out spectral data stepping through each channel from 0 to 17 following the format of **value needed**.
15
+
In order to get data from all channels, the AS7343 takes measurements in three cycles with each one stepping through four individual channels combined with readings from the Clear/VIS and Flicker Detect/FD which is then stored in the sensor's data registers. The example prints out spectral data stepping through each channel from 0 to 17 in comma-separated values:
16
+
17
+
```c++
18
+
for (int channel = 0; channel < channelsRead; channel++)
19
+
{
20
+
Serial.print(myData[channel]);
21
+
Serial.print(",");
22
+
}
23
+
24
+
Serial.println();
25
+
```
16
26
17
27
## Example 3 - Gain
18
28
19
29
The third example shows how to set up the AS7343 with specific Spectral Engines Gain Settigns (aka AGAIN) and cycle through the gain settings using serial commands. Open the example in Arduino by navigating to **File** > **Examples** > **SparkFun AS7343 Arduino Library** > **Example_03_Gain**. If necessary, select your board and port and click the "Upload" button. Open the serial terminal with the baud set to **115200** after the code finishes uploading.
20
30
21
-
The example accepts serial inputs of "+" and "-" to step up and down, respectively, through the available gain settings and prints out the value of the gain each time it's updated. The code also prints out spectral readings from all channels every 1 second so'll want to pay close attention to the serial monitor when adjusting the gain value to see the returned serial data like the screenshot below shows:
31
+
The example accepts serial inputs of "+" and "-" to step up and down, respectively, through the available gain settings and prints out the value of the gain each time it's updated:
32
+
33
+
```c++
34
+
if(Serial.available())
35
+
{
36
+
userInput = Serial.read();
37
+
if (userInput == '+' || userInput == '-')
38
+
{
39
+
updateGainSetting(userInput);
40
+
}
41
+
}
42
+
```
43
+
44
+
The code also prints out spectral readings from all channels every 1 second so'll want to pay close attention to the serial monitor when adjusting the gain value to see the returned serial data like the screenshot below shows:
22
45
23
46
<figuremarkdown>
24
47
[{ width="600"}](./assets/img/AS7343_Arduino_Example3.jpg"Click to enlarge")
@@ -36,16 +59,67 @@ Not sure which pins on your development board support the `attachInterrupt()` fu
36
59
37
60
## Example 5 - Flicker Detection
38
61
39
-
Example five shows how to set up and monitor flicker detection readings from the sensor. It sets up the AS7343 with default settings with flicker detection enabled and prints the values over serial.
62
+
Example five shows how to set up and monitor flicker detection readings from the sensor. It sets up the AS7343 with default settings with flicker detection enabled. It then checks to see if flicker detection values are invalid or saturated and prints out for either case:
If the flicker detection value is valid and not saturated, it reads the value and prints it in Hz over serial:
86
+
87
+
```c++
88
+
if(fdValid == true && fdSaturation == false)
89
+
{
90
+
if (fdFrequency == 0) // if getFlickerDetectionFrequency() returns 0, no frequency detected
91
+
Serial.print("No Flicker Detected");
92
+
else
93
+
{
94
+
Serial.print("Flicker Detected at frequency: ");
95
+
Serial.print(fdFrequency);
96
+
Serial.print("Hz");
97
+
}
98
+
Serial.println();
99
+
}
100
+
101
+
delay(1000);
102
+
```
40
103
41
104
## Example 6 - Sleep
42
105
43
-
Example six shows how to put the AS734 in and out of Sleep Mode to take intermittent measurements.
106
+
Example six shows how to put the AS734 in and out of "sleep" to take intermittent measurements. Note, the AS7343 [datasheet](./assets/component_documentation/AS7343_DS001046_6-00.pdf) refers to each mode of operation as Sleep, Idle and Active. There is no direct control of a power mode but we can turn off the Measurement and the Power ON bits in the Enable register to put the AS7343 into a low power state that draws ~350uA. This example creates helper functions to wake the sensor, take a reading and then put the sensor back to sleep once every five seconds in the main loop:
107
+
108
+
```c++
109
+
voidloop()
110
+
{
111
+
takeReading(); // Wake up and take a reading from the sensor
112
+
113
+
sleepSensor(); // Disables measurement (IDLE) and powers off (SLEEP)
114
+
115
+
delay(5000); // Wait 5 seconds to allow reading sleep current if needed.
116
+
}
117
+
```
44
118
45
119
## Example 7 - Web Terminal Bar Graph
46
120
47
-
The seventh example takes data from all of the AS7343's channels (visible spectrum, NIR and clear) and formats it in a way to work with the SparkFun Online Serial Terminal to display the readings in a colorful bar graph. After uploading the code, head to the [SparkFun Web Serial Plotter]() site, select the COM port with the baud set to <b>115200</b> and click connect. You should start to see serial data print out in the top window along with a bar graph matching the channel data in the bottom window:
121
+
The seventh example takes data from all of the AS7343's channels (visible spectrum, NIR and clear) and formats it in a way to work with the SparkFun [Web Serial Plotter](https://docs.sparkfun.com/SparkFun_WebSerialPlotter/) tool to display the readings in a colorful bar graph. After uploading the code, open the [SparkFun Web Serial Plotter](https://docs.sparkfun.com/SparkFun_WebSerialPlotter/) site, select the COM port with the baud set to <b>115200</b> and click connect. You should start to see serial data print out in the top window along with a bar graph matching the channel data in the bottom window:
48
122
49
123
<figuremarkdown>
50
-
[](./assets/img/spectral_bars_v10.gif "Click to enlarge")
124
+
[{ width="600"}](./assets/img/spectral_bars_v10.gif"Click to enlarge")
Copy file name to clipboardExpand all lines: docs/hardware_overview.md
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Let's take a closer look at the AS7343 and other hardware on the SparkFun Spectr
6
6
7
7
## AS7343 Spectral Sensor
8
8
9
-
The AS7343 from AMS<sup>™</sup> measures irradiated, reflected and transmitted light in both the visible spectrum and near-infrared (NIR). The sensor package has 14 channels (12 for visible light, 1 for NIR and 1 for flicker detection).
9
+
The AS7343 from AMS<sup>™</sup> measures irradiated, reflected and transmitted light in both the visible spectrum and near-infrared (NIR). The sensor features 14 channels in a 5x5 photodiode array, enabling the detection of 11 specific color bands across the visible spectrum. Additionally, dedicated photodiodes on the outer edges of this array are designed for near-infrared (845-865 nm) and flicker detection. It has exceptional sensitivity for measuring reflected, emitted and transmitted light even in low-light environments and also behind tinted glass.
10
10
11
11
## Power
12
12
@@ -26,4 +26,8 @@ The board has three solder jumpers labeled <b>I2C</b>, <b>PWR</b> and <b>WLED</b
26
26
27
27
## Board Dimensions
28
28
29
-
The SparkFun Spectral Sensor Breakout - AS7343 matches the Qwiic breakout standard and measures 1" x 1" (22.5mm x 22.5mm) and has four mounting holes that fit a [4-40 screw]().
29
+
The SparkFun Spectral Sensor Breakout - AS7343 matches the Qwiic breakout standard and measures 1" x 1" (22.5mm x 22.5mm) and has four mounting holes that fit a [4-40 screw](https://www.sparkfun.com/screw-phillips-head-1-4-4-40-10-pack.html).
30
+
31
+
<figuremarkdown>
32
+
[{ width="600"}](./assets/board_files/SparkFun_AS7343_Qwiic-Dimensions.jpg"Click to enlarge")
The SparkFun Spectral Sensor Breakout - AS7343 (Qwiic) offers a highly accurate but compact spectral analysis tool for both the visible spectrum and near-infrared. The AS7343 senses light between ~380mn to 1000mn over 14 channels with 11 color bands across the visible spectrum, one near-infrared channel, one clear channel (full sensing spectrum) along with flicker detection. The AS7343 also has an interrupt pin to trigger events based on specific measurements from the sensor as well as a programmable GPIO pin to help synchronize measurements with external devices. This breakout comes standard with a bright white LED for taking measurements but also includes connection points for users who wish to use their own LED if needed.
Let's take a quick look at each example included in the SparkFun AS7343 Python package. Note, the naming of these examples matches the examples in the Arduino library and skips from 3 to 5 as this package does not have an interrupt example (Example 4 in the Arduino library).
2
+
3
+
## Example 1 - Basic Readings
4
+
5
+
This simple example demonstrates how to set up the AS7343 with default settings and though it does set the AS7343 to report data from all 18 channels it only prints data for four channels (Red, Green, Blue and NIR) using this command:
6
+
7
+
```py
8
+
print(myAS7343.get_blue(), end=',')
9
+
print(myAS7343.get_red(), end=',')
10
+
print(myAS7343.get_green(), end=',')
11
+
print(myAS7343.get_nir(), end=',\n')
12
+
```
13
+
14
+
## Example 2 - All Channels
15
+
16
+
Example 2 demonstrates how to set up the AS7343 to output data from all channels on the sensor in comma-separated values by steping through all channels:
17
+
18
+
```py
19
+
for i inrange(0, myAS7343.kNumChannels):
20
+
print(myAS7343.get_data(i), end=',')
21
+
print()
22
+
```
23
+
24
+
## Example 3 - Gain
25
+
26
+
The third example shows how to set the gain for the AS7343. It defaults to set the gain as `512x` but you can adjust it in this line:
27
+
28
+
```py
29
+
ifnot myAS7343.set_a_gain(myAS7343.kAgain64):
30
+
```
31
+
32
+
Refer to the main .py file [here](https://github.com/sparkfun/qwiic_as7343_py/blob/master/qwiic_as7343.py#L102) for all allowed values for gain settings.
33
+
34
+
## Example 5 - Flicker Detection
35
+
36
+
The Flicker Detection example demonstrates how to use the AS7343's flicker detection feature. It initializes the sensor with default settings and then prints out flicker detection vlues in Hz to the serial monitor:
37
+
38
+
```py
39
+
if fdFrequency ==0:
40
+
print("No flicker detected")
41
+
else:
42
+
print("Flicker detected at frequency: {} Hz".format(fdFrequency))
43
+
44
+
time.sleep(1)
45
+
```
46
+
47
+
## Example 6 - Sleep
48
+
49
+
The sixth example shows how to create a `def` to cycle the AS7343 in and out of "sleep" between measurement reports to help conserve power:
50
+
51
+
```py
52
+
defsleep_device(device):
53
+
# Disable spectral measurements
54
+
ifnot device.spectral_measurement_disable():
55
+
print("Failed to disable spectral measurements", file=sys.stderr)
56
+
return
57
+
print("Spectral measurements disabled")
58
+
59
+
# Power off the device
60
+
ifnot device.power_off():
61
+
print("Failed to power off the device", file=sys.stderr)
62
+
return
63
+
print("Device powered off")
64
+
```
65
+
66
+
The main example then initializes the sensor with default settings, takes readings, puts it to sleep for 5 seconds and then loops:
67
+
68
+
```py
69
+
whileTrue:
70
+
# Take a reading
71
+
take_reading(myAS7343)
72
+
73
+
# Put the device to sleep
74
+
sleep_device(myAS7343)
75
+
76
+
# Wait 5 seconds before taking another reading
77
+
time.sleep(5.0)
78
+
```
79
+
80
+
Though there is no direct control of a power mode, the example turns off the measurement and Power ON bits in the Enable register to put the sensor into a low power state so it draws ~350µA.
81
+
82
+
## Example 7 - Web Bar Graph
83
+
84
+
Example 7 shows how to use the Spectral Sensor with the SparkFun [Web Serial Plotter](https://docs.sparkfun.com/SparkFun_WebSerialPlotter/) to display spectral data from all channels in a neat and colorful bar graph. You'll need to run this on a microcontroller like the [IoT RedBoard - ESP32 MicroPython](https://www.sparkfun.com/sparkfun-iot-redboard-esp32-micropython-development-board.html) as the Web Serial Plotter connects over a serial COM port. The code initializes the AS7343 with default settings and then prints out the comma-separated values in a format compatible with the web serial plotter:
After running the example, open the [Web Serial Plotter](https://docs.sparkfun.com/SparkFun_WebSerialPlotter/) and select the COM port and click "Connect" and you should see serial data print out in the top window and a nice colorful bar graph in the bottom window like the gif below shows:
103
+
104
+
<figuremarkdown>
105
+
[{ width="600"}](./assets/img/spectral_bars_v10.gif"Click to enlarge")
0 commit comments