-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbasic_plotter.ino
More file actions
59 lines (51 loc) · 1.6 KB
/
basic_plotter.ino
File metadata and controls
59 lines (51 loc) · 1.6 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
/*
* Basic Arduino Serial Plotter Example
*
* This sketch generates sample data compatible with the Web Serial Plotter.
* It outputs multiple data series in CSV format with headers.
*
* Data Format:
* - Header line starts with '#' followed by series names
* - Data lines contain comma-separated values
* - Each line represents one time sample across all series
*
* Compatible with Web Serial Plotter at:
* https://github.com/your-repo/web-serial-plotter
*/
long lastDebug = 0;
int debugCount = 0;
void setup() {
Serial.begin(115200);
// Wait for serial connection
while (!Serial) {
delay(10);
}
Serial.println("[# Temperature,Humidity,Pressure,Light]");
// Small delay to ensure header is processed
delay(100);
}
void loop() {
// Send debug info every 1 second
if(millis() - lastDebug > 1000){
Serial.print("Debug no. ");
Serial.println(++debugCount);
lastDebug = millis();
}
// Generate sample sensor data
float temperature = 20.0 + 15.0 * sin(millis() / 5000.0) + random(-100, 100) / 100.0;
float humidity = 50.0 + 20.0 * cos(millis() / 3000.0) + random(-200, 200) / 100.0;
float pressure = 1013.25 + 10.0 * sin(millis() / 8000.0) + random(-50, 50) / 100.0;
float light = 500.0 + 300.0 * sin(millis() / 2000.0) + random(-1000, 1000) / 100.0;
// Output as comma-separated values
Serial.print("[");
Serial.print(temperature, 2);
Serial.print(",");
Serial.print(humidity, 2);
Serial.print(",");
Serial.print(pressure, 2);
Serial.print(",");
Serial.print(light, 2);
Serial.println("]");
// Sample rate: 50 Hz (20ms interval)
delay(20);
}