-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample01_Basic_OneShot.ino
More file actions
87 lines (68 loc) · 2.19 KB
/
Example01_Basic_OneShot.ino
File metadata and controls
87 lines (68 loc) · 2.19 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
/*
Using the AMS AS7331 Spectral UV Sensor in Command/One Shot (CMD) Mode.
This example shows how operate the AS7331 in the default CMD mode. The start
command is sent, then delays until the conversion time has passed before
reading out the UV values.
By: Alex Brudner
SparkFun Electronics
Date: 2023/11/17
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/23517 - Qwiic 1x1
https://www.sparkfun.com/products/23518 - Qwiic Mini
*/
#include <Arduino.h>
#include <SparkFun_AS7331.h>
#include <Wire.h>
SfeAS7331ArdI2C myUVSensor;
void setup()
{
Serial.begin(115200);
while (!Serial)
{
delay(100);
};
Serial.println("AS7331 UV A/B/C Command (One-shot) mode Example.");
Wire.begin();
// Initialize sensor and run default setup.
if (myUVSensor.begin() == false)
{
Serial.println("Sensor failed to begin. Please check your wiring!");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Sensor began.");
// Set measurement mode and change device operating mode to measure.
if (myUVSensor.prepareMeasurement(MEAS_MODE_CMD) == false)
{
Serial.println("Sensor did not get set properly.");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Set mode to command.");
}
void loop()
{
// Send a start measurement command.
if (ksfTkErrOk != myUVSensor.setStartState(true))
Serial.println("Error starting reading!");
// Wait for a bit longer than the conversion time.
delay(2 + myUVSensor.getConversionTimeMillis());
// Read UV values.
if (ksfTkErrOk != myUVSensor.readAllUV())
Serial.println("Error reading UV.");
Serial.print("UVA:");
Serial.print(myUVSensor.getUVA());
Serial.print(" UVB:");
Serial.print(myUVSensor.getUVB());
Serial.print(" UVC:");
Serial.println(myUVSensor.getUVC());
delay(2000);
}