-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample04_SYND_Mode.ino
More file actions
106 lines (84 loc) · 2.76 KB
/
Example04_SYND_Mode.ino
File metadata and controls
106 lines (84 loc) · 2.76 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
/*
Using the AMS AS7331 Spectral UV Sensor in Synchronous Start and Stop (SYND) Mode.
This example shows how operate the AS7331 in SYND mode. This uses the active
low SYN pin to both start and stop the conversion. The conversion time is
calculated and stored in the `measures.outputConversionTime` field in units
of number of clock cycles.
By: Alex Brudner
SparkFun Electronics
Date: 2023/11/28
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
27 --> SYN
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;
const uint8_t synPin = 27;
void setup()
{
Serial.begin(115200);
while (!Serial)
{
delay(100);
};
Serial.println("AS7331 UV A/B/C Synchronous Start and End (SYND) mode example.");
Wire.begin();
// Configure SYN pin.
pinMode(synPin, OUTPUT);
digitalWrite(synPin, HIGH); // Active low, so start high.
// 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_SYND) == false)
{
Serial.println("Sensor did not get set properly.");
Serial.println("Halting...");
while (1)
;
}
Serial.println("Set mode to synchronous start/end (SYND). Starting measurement...");
// Set device to be ready to measure.
if (ksfTkErrOk != myUVSensor.setStartState(true))
Serial.println("Error starting reading!");
// Send start toggle.
digitalWrite(synPin, LOW);
delay(1);
digitalWrite(synPin, HIGH);
}
void loop()
{
// Delay a random period of time from 64ms (minimum for full read) and 300ms.
delay(random(64, 300));
// End measurement.
digitalWrite(synPin, LOW);
delay(1);
digitalWrite(synPin, HIGH);
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());
// Start next measurement.
digitalWrite(synPin, LOW);
delay(1);
digitalWrite(synPin, HIGH);
}