-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample_01_BasicReadings.ino
More file actions
110 lines (87 loc) · 2.52 KB
/
Copy pathExample_01_BasicReadings.ino
File metadata and controls
110 lines (87 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Using the AMS AS7343 Sensor.
This example shows how to setup the AS7343 sensor with default settings and
print out 4 channels from the sensor (Red, Green, Blue, and NIR).
By: Pete Lewis
SparkFun Electronics
Date: 2025/04/22
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.
Hardware Connections:
IoT RedBoard --> AS7331
QWIIC --> QWIIC
Serial.print it out at 115200 baud to serial monitor.
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/products/23220
*/
#include <SparkFun_AS7343.h>
SfeAS7343ArdI2C mySensor;
void setup()
{
Serial.begin(115200);
while (!Serial)
{
delay(100);
};
Serial.println("AS7343 Example 01 - Basic Readings");
Wire.begin();
// Initialize sensor and run default setup.
if (mySensor.begin() == false)
{
Serial.println("Sensor failed to begin. Please check your wiring!");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Sensor began.");
// Power on the device
if (mySensor.powerOn() == false)
{
Serial.println("Failed to power on the device.");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Device powered on.");
// Set the AutoSmux to output all 18 channels
if (mySensor.setAutoSmux(AUTOSMUX_18_CHANNELS) == false)
{
Serial.println("Failed to set AutoSmux.");
Serial.println("Halting...");
while (1)
;
}
Serial.println("AutoSmux set to 18 channels.");
// Enable Spectral Measurement
if (mySensor.enableSpectralMeasurement() == false)
{
Serial.println("Failed to enable spectral measurement.");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Spectral measurement enabled.");
}
void loop()
{
mySensor.setLedDrive(0); // Set LED drive to min (0 = 4mA)
mySensor.ledOn();
delay(100);
// Read all data registers
// if it fails, print a failure message and continue
if (mySensor.readSpectraDataFromSensor() == false)
{
Serial.println("Failed to read spectral data.");
}
mySensor.ledOff();
Serial.print(mySensor.getBlue());
Serial.print(",");
Serial.print(mySensor.getRed());
Serial.print(",");
Serial.print(mySensor.getGreen());
Serial.print(",");
Serial.print(mySensor.getNIR());
Serial.print(",");
Serial.println();
delay(500);
}