-
Notifications
You must be signed in to change notification settings - Fork 33
/
opengamma_pico.ino
726 lines (574 loc) · 20.6 KB
/
opengamma_pico.ino
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*
Open Gamma Detector Sketch
Only works on the Raspberry Pi Pico with arduino-pico!
Triggers on newly detected pulses and measures their energy.
2022, NuclearPhoenix. Open Gamma Project.
https://github.com/Open-Gamma-Project/Open-Gamma-Detector
## NOTE:
## Only change the highlighted USER SETTINGS
## except you know exactly what you are doing!
## Flash with default settings and
## Flash Size: 2MB (Sketch: 1984KB, FS: 64KB)
TODO: There are still some ADC issues?
TODO: Coincidence measurements?
TODO: Sleep modes instead of delays
TODO: Add more OLED features?
*/
#include <hardware/adc.h> // For corrected temp readings
#include <SimpleShell.h> // Serial Commands/Console
#include <ArduinoJson.h> // Load and save the settings file
#include <LittleFS.h> // Used for FS, stores the settings file
#include <Adafruit_SSD1306.h> // Used for OLEDs
const String FWVERS = "2.4.0"; // Firmware Version Code
const uint8_t GND_PIN = A0; // GND meas pin
const uint8_t VCC_PIN = A2; // VCC meas pin
const uint8_t VSYS_MEAS = A3; // VSYS/3
const uint8_t VBUS_MEAS = 24; // VBUS Sense Pin
const uint8_t PS_PIN = 23; // SMPS power save pin
const uint8_t AIN_PIN = A1; // Analog input pin
const uint8_t INT_PIN = 16; // Signal interrupt pin
const uint8_t RST_PIN = 22; // Peak detector MOSFET reset pin
const uint8_t LED = 25; // LED on GP25
const uint16_t EVT_RESET_C = 2000; // Number of counts after which the OLED stats will be reset
/*
BEGIN USER SETTINGS
*/
// These are the default settings that can only be changed by reflashing the Pico
const float VREF_VOLTAGE = 3.3; // ADC reference voltage, defaults 3.3, with reference 3.0
const uint8_t ADC_RES = 12; // Use 12-bit ADC resolution
const uint32_t EVENT_BUFFER = 50000; // Buffer this many events for Serial.print
const uint8_t SCREEN_WIDTH = 128; // OLED display width, in pixels
const uint8_t SCREEN_HEIGHT = 64; // OLED display height, in pixels
const uint8_t SCREEN_ADDRESS = 0x3C; // See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
const uint8_t TRNG_BITS = 8; // Number of bits for each random number, max 8
struct Config {
// These are the default settings that can also be changes via the serial commands
volatile bool ser_output = true; // Wheter data should be Serial.println'ed
volatile bool geiger_mode = false; // Measure only cps, not energy
volatile bool print_spectrum = false; // Print the finishes spectrum, not just
volatile bool auto_reset = true; // Periodically reset S&H circuit
volatile size_t meas_avg = 5; // Number of meas. averaged each event, higher=longer dead time
volatile bool enable_display = false; // Enable I2C Display, see settings above
volatile bool trng_enabled = false; // Enable the True Random Number Generator
};
/*
END USER SETTINGS
*/
volatile uint32_t spectrum[uint16_t(pow(2, ADC_RES))]; // Holds the spectrum histogram written to flash
volatile uint16_t events[EVENT_BUFFER]; // Buffer array for single events
volatile uint16_t event_position = 0; // Target index in events array
volatile uint32_t last_time = 0; // Last timestamp for OLED refresh
volatile uint32_t trng_stamps[3]; // Timestamps for True Random Number Generator
volatile uint8_t trng_index = 0; // Timestamp index for True Random Number Generator
volatile uint8_t random_num = 0b00000000; // Generated random bits that form a byte together
volatile uint8_t num_index = 0; // Bit index for the generated number
volatile Config conf; // Configuration object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void serialInterruptMode(String *args) {
String command = *args;
command.replace("set int -", "");
command.trim();
if (command == "spectrum") {
conf.ser_output = true;
conf.print_spectrum = true;
Serial.println("Set serial interrupt mode to full spectrum.");
} else if (command == "events") {
conf.ser_output = true;
conf.print_spectrum = false;
Serial.println("Set serial interrupt mode to events.");
} else if (command == "disable") {
conf.ser_output = false;
conf.print_spectrum = false;
Serial.println("Disabled serial interrupts.");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Must be 'spectrum', 'events' or 'disable'.");
return;
}
saveSetting();
}
void toggleAutoReset(String *args) {
String command = *args;
command.replace("set reset -", "");
command.trim();
if (command == "enable") {
conf.auto_reset = true;
Serial.println("Enabled auto-reset.");
} else if (command == "disable") {
conf.auto_reset = false;
Serial.println("Disabled auto-reset.");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Must be 'enable' or 'disable'.");
return;
}
saveSetting();
}
void setDisplay(String *args) {
String command = *args;
command.replace("set display -", "");
command.trim();
if (command == "enable") {
conf.enable_display = true;
Serial.println("Enabled display output. You might need to reset the device.");
} else if (command == "disable") {
conf.enable_display = false;
Serial.println("Disabled display output. You might need to reset the device.");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Must be 'enable' or 'disable'.");
return;
}
saveSetting();
}
void toggleGeigerMode(String *args) {
String command = *args;
command.replace("set mode -", "");
command.trim();
if (command == "geiger") {
conf.geiger_mode = true;
event_position = 0;
Serial.println("Enabled geiger mode.");
} else if (command == "energy") {
conf.geiger_mode = false;
event_position = 0;
Serial.println("Enabled energy measuring mode.");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Must be 'geiger' or 'energy'.");
return;
}
saveSetting();
}
void toggleTRNG(String *args) {
String command = *args;
command.replace("set trng -", "");
command.trim();
if (command == "enable") {
conf.trng_enabled = true;
Serial.println("Enabled True Random Number Generator output.");
} else if (command == "disable") {
conf.trng_enabled = false;
Serial.println("Disabled True Random Number Generator output.");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Must be 'enable' or 'disable'.");
return;
}
saveSetting();
}
void measAveraging(String *args) {
String command = *args;
command.replace("set averaging -", "");
command.trim();
const size_t number = command.toInt();
if (number > 0) {
conf.meas_avg = number;
Serial.println("Set measurement averaging to " + String(number) + ".");
} else {
Serial.println("No valid input '" + command + "'!");
Serial.println("Parameter must be a number >= 0.");
return;
}
saveSetting();
}
float analogReadTempCorrect() {
digitalWrite(RST_PIN, HIGH); // ADDED: Disable peak&hold
// Copy from arduino-pico/cores/rp2040/wiring_analog.cpp
adc_init(); // Init ADC just to be sure
adc_set_temp_sensor_enabled(true);
//digitalWrite(PS_PIN, HIGH); // Disable Power Save For Better Noise
//detachInterrupt(digitalPinToInterrupt(INT_PIN)); // ADDED: Disable interrupts shortly
delay(1); // Allow things to settle. Without this, readings can be erratic
adc_select_input(4);
uint16_t v = adc_read();
//digitalWrite(PS_PIN, LOW); // Re-Enable Power Saving
//resetSampleHold(); // ADDED: Reset S&H after the detached interrupt and re-enable interrupts
//attachInterrupt(digitalPinToInterrupt(INT_PIN), eventInt, HIGH);
adc_set_temp_sensor_enabled(false);
digitalWrite(RST_PIN, LOW); // ADDED: Enable peak&hold again
return 27.0 - ((v * VREF_VOLTAGE / (pow(2, ADC_RES) - 1)) - 0.706) / 0.001721;
}
void deviceInfo(String *args) {
Serial.println("=========================");
Serial.println("-- Open Gamma Detector --");
Serial.println("By NuclearPhoenix, Open Gamma Project");
Serial.println("2022. https://github.com/Open-Gamma-Project");
Serial.println("Firmware Version: " + FWVERS);
Serial.println("=========================");
Serial.println("CPU Frequency: " + String(rp2040.f_cpu() / 1e6) + " MHz");
Serial.println("Runtime: " + String(millis() / 1000.0) + " s");
Serial.println("Temperature: " + String(round(analogReadTempCorrect())) + " °C");
Serial.println("USB Connection: " + String(bool(digitalRead(VBUS_MEAS))));
float v = 3.0 * analogRead(VSYS_MEAS) * VREF_VOLTAGE / (pow(2, ADC_RES) - 1);
Serial.println("Supply Voltage: " + String(round(v * 10.0) / 10.0) + " V");
Serial.println("Free Heap Memory: " + String(rp2040.getFreeHeap()) + " B");
Serial.println("Used Heap Memory: " + String(rp2040.getUsedHeap()) + " B");
Serial.println("Total Heap Size: " + String(rp2040.getTotalHeap()) + " B");
}
void fsInfo(String *args) {
FSInfo64 fsinfo;
LittleFS.info64(fsinfo);
Serial.print("Total Bytes: ");
Serial.println(fsinfo.totalBytes);
Serial.print("Used Bytes: ");
Serial.println(fsinfo.usedBytes);
Serial.print("Block Size: ");
Serial.println(fsinfo.blockSize);
Serial.print("Page Size: ");
Serial.println(fsinfo.pageSize);
Serial.print("Max Open Files: ");
Serial.println(fsinfo.maxOpenFiles);
Serial.print("Max Path Length: ");
Serial.println(fsinfo.maxPathLength);
}
void getSpectrumData(String *args) {
for (size_t i = 0; i < pow(2, ADC_RES); i++) {
Serial.println(spectrum[i]);
}
}
void clearSpectrum() {
for (size_t i = 0; i < pow(2, ADC_RES); i++) {
spectrum[i] = 0;
}
}
void clearSpectrumData(String *args) {
Serial.println("Clearing spectrum...");
last_time = millis();
clearSpectrum();
Serial.println("Cleared!");
}
void readSettings(String *args) {
File saveFile = LittleFS.open("/config.json", "r");
if (!saveFile) {
Serial.println("Could not open save file!");
return;
}
String file = "";
while (saveFile.available()) {
file += saveFile.readString();
}
saveFile.close();
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, file);
if (error) {
Serial.print("Could not load config from json file: ");
Serial.println(error.f_str());
return;
}
serializeJsonPretty(doc, Serial);
Serial.println();
Serial.println("Read settings file successfully.");
}
void resetSettings(String *args) {
const Config defaultConf;
conf.ser_output = defaultConf.ser_output;
conf.geiger_mode = defaultConf.geiger_mode;
conf.print_spectrum = defaultConf.print_spectrum;
conf.auto_reset = defaultConf.auto_reset;
conf.meas_avg = defaultConf.meas_avg;
conf.enable_display = defaultConf.enable_display;
conf.trng_enabled = defaultConf.trng_enabled;
Serial.println("Applied default settings.");
saveSetting();
}
void rebootNow(String *args) {
Serial.println("You might need to re-connect after reboot.");
Serial.println("Rebooting now...");
delay(1000);
rp2040.reboot();
}
void serialEvent() {
Shell.handleEvent(); // Handle the serial input
}
void saveSetting() {
// Physically save file everytime a setting changes.
// Not the best for flash longevity, but it's ok.
File saveFile = LittleFS.open("/config.json", "w");
if (!saveFile) {
Serial.println("Could not open save file!");
return;
}
DynamicJsonDocument doc(1024);
doc["ser_output"] = conf.ser_output;
doc["geiger_mode"] = conf.geiger_mode;
doc["print_spectrum"] = conf.print_spectrum;
doc["auto_reset"] = conf.auto_reset;
doc["meas_avg"] = conf.meas_avg;
doc["enable_display"] = conf.enable_display;
doc["trng_enabled"] = conf.trng_enabled;
serializeJson(doc, saveFile); //serializeJsonPretty()
saveFile.close();
Serial.println("Successfuly written config to flash.");
}
void readSetting() {
File saveFile = LittleFS.open("/config.json", "r");
if (!saveFile) {
Serial.println("Could not open save file!");
return;
}
String json = "";
while (saveFile.available()) {
json += saveFile.readString();
}
saveFile.close();
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, json);
if (error) {
Serial.print("Could not load config from json file: ");
Serial.println(error.f_str());
return;
}
conf.ser_output = doc["ser_output"];
conf.geiger_mode = doc["geiger_mode"];
conf.print_spectrum = doc["print_spectrum"];
conf.auto_reset = doc["auto_reset"];
conf.meas_avg = doc["meas_avg"];
conf.enable_display = doc["enable_display"];
conf.trng_enabled = doc["trng_enabled"];
Serial.println("Successfuly loaded config from flash.");
}
void resetSampleHold() { // Reset sample and hold circuit
digitalWrite(RST_PIN, HIGH);
delayMicroseconds(1); // Discharge for 1 µs, actually takes 2 µs - enough for a discharge
digitalWrite(RST_PIN, LOW);
}
void drawSpectrum() {
const uint16_t BINSIZE = round(pow(2, ADC_RES) / SCREEN_WIDTH);
uint32_t eventBins[SCREEN_WIDTH];
uint16_t offset = 0;
uint32_t max_num = 0;
uint32_t total = 0;
for (uint16_t i = 0; i < SCREEN_WIDTH; i++) {
uint32_t totalValue = 0;
for (uint16_t j = offset; j < offset + BINSIZE; j++) {
totalValue += spectrum[j];
}
offset += BINSIZE;
eventBins[i] = totalValue;
if (totalValue > max_num) {
max_num = totalValue;
}
total += totalValue;
}
if (max_num <= 0) { // No events accumulated, catch divide by zero
return;
}
float scale_factor = float(SCREEN_HEIGHT - 11) / float(max_num);
uint32_t time_delta = millis() - last_time;
if (time_delta <= 0) { // Catch divide by zero
return;
}
display.clearDisplay();
display.setCursor(0, 0);
display.print(total * 1000.0 / time_delta);
display.print(" cps");
int16_t temp = round(analogReadTempCorrect());
if (temp < 0) {
display.setCursor(SCREEN_WIDTH - 30, 0);
} else {
display.setCursor(SCREEN_WIDTH - 24, 0);
}
display.print(temp);
display.println(" C");
uint32_t seconds_running = round(time_delta / 1000.0);
if (seconds_running < 10) {
display.setCursor(SCREEN_WIDTH - 18, 8);
} else if (seconds_running < 100) {
display.setCursor(SCREEN_WIDTH - 24, 8);
} else if (seconds_running < 1000) {
display.setCursor(SCREEN_WIDTH - 30, 8);
} else {
display.setCursor(SCREEN_WIDTH - 36, 8);
}
display.print(seconds_running);
display.println(" s");
for (uint16_t i = 0; i < SCREEN_WIDTH; i++) {
uint16_t val = round(eventBins[i] * scale_factor);
display.drawFastVLine(i, SCREEN_HEIGHT - val - 1, val, SSD1306_WHITE);
}
display.drawFastHLine(0, SCREEN_HEIGHT - 1, SCREEN_WIDTH, SSD1306_WHITE);
display.display();
if (total > EVT_RESET_C) {
last_time = millis();
clearSpectrum();
}
}
void eventInt() {
digitalWrite(LED, HIGH); // Activity LED
if (conf.trng_enabled) {
// Calculations for the TRNG
if (trng_index < 2) {
trng_stamps[trng_index] = micros();
trng_index++;
} else {
trng_stamps[trng_index] = micros();
uint32_t delta0 = trng_stamps[1] - trng_stamps[0];
uint32_t delta1 = trng_stamps[2] - trng_stamps[1];
if (delta0 < delta1) {
bitWrite(random_num, num_index, 0);
} else {
bitWrite(random_num, num_index, 1);
}
if (num_index < TRNG_BITS - 1) {
num_index++;
} else {
Serial.print(random_num, DEC);
Serial.println(";");
random_num = 0b00000000; // Clear number
num_index = 0;
}
trng_index = 0;
}
}
uint16_t mean = 0;
delayMicroseconds(1); // Wait to allow the sample/hold circuit to stabilize
if (!conf.geiger_mode) {
uint16_t meas[conf.meas_avg];
//digitalWrite(PS_PIN, HIGH); // Disable Power-Saving
for (size_t i = 0; i < conf.meas_avg; i++) {
meas[i] = analogRead(AIN_PIN);
}
//digitalWrite(PS_PIN, LOW); // Enable Power-Saving
float avg = 0.0;
uint8_t invalid = 0;
for (size_t i = 0; i < conf.meas_avg; i++) {
// Pico-ADC DNL issues, see https://pico-adc.markomo.me/INL-DNL/#dnl
// Discard channels 512, 1536, 2560, and 3584. For now.
// See RP2040 datasheet Appendix B: Errata
if (meas[i] == 511 || meas[i] == 1535 || meas[i] == 2559 || meas[i] == 3583) {
invalid++;
continue; // Discard
}
avg += meas[i];
}
if (conf.meas_avg - invalid <= 0) { // Catch divide by zero crash
avg = 0.0;
} else {
avg /= conf.meas_avg - invalid;
}
mean = round(avg); // float --> uint16_t ADC channel
// Use median instead of average?
/*
float var = 0.0;
for (size_t i = 0; i < conf.meas_avg; i++) {
var += sq(meas[i] - mean);
}
var /= conf.meas_avg;
*/
}
if (conf.ser_output || conf.enable_display) {
events[event_position] = mean;
spectrum[mean] += 1;
//Serial.print(' ' + String(sqrt(var)) + ';');
//Serial.println(' ' + String(sqrt(var)/mean) + ';');
if (event_position >= EVENT_BUFFER - 1) { // Increment if memory available, else overwrite array
event_position = 0;
} else {
event_position++;
}
}
resetSampleHold();
digitalWrite(LED, LOW);
}
/*
SETUP FUNCTIONS
*/
void setup() {
rp2040.wdt_begin(5000); // Enable hardware watchdog to check every 5s
pinMode(INT_PIN, INPUT);
pinMode(RST_PIN, OUTPUT_12MA);
pinMode(AIN_PIN, INPUT);
pinMode(LED, OUTPUT);
analogReadResolution(ADC_RES);
resetSampleHold(); // Reset before enabling the interrupts to avoid jamming
attachInterrupt(digitalPinToInterrupt(INT_PIN), eventInt, HIGH);
}
void setup1() {
pinMode(PS_PIN, OUTPUT_4MA);
digitalWrite(PS_PIN, LOW); // Enable Power-Saving
pinMode(GND_PIN, INPUT);
pinMode(VCC_PIN, INPUT);
pinMode(VSYS_MEAS, INPUT);
pinMode(VBUS_MEAS, INPUT);
Shell.registerCommand(new ShellCommand(getSpectrumData, F("read spectrum")));
Shell.registerCommand(new ShellCommand(readSettings, F("read settings")));
Shell.registerCommand(new ShellCommand(deviceInfo, F("read info")));
Shell.registerCommand(new ShellCommand(fsInfo, F("read fs")));
Shell.registerCommand(new ShellCommand(toggleTRNG, F("set trng -")));
Shell.registerCommand(new ShellCommand(setDisplay, F("set display -")));
Shell.registerCommand(new ShellCommand(toggleGeigerMode, F("set mode -")));
Shell.registerCommand(new ShellCommand(serialInterruptMode, F("set int -")));
Shell.registerCommand(new ShellCommand(toggleAutoReset, F("set reset -")));
Shell.registerCommand(new ShellCommand(measAveraging, F("set averaging -")));
Shell.registerCommand(new ShellCommand(clearSpectrumData, F("clear spectrum")));
Shell.registerCommand(new ShellCommand(resetSettings, F("reset settings")));
Shell.registerCommand(new ShellCommand(rebootNow, F("reboot")));
Shell.begin(2000000);
/*
LittleFSConfig cfg;
cfg.setAutoFormat(false);
LittleFS.setConfig(cfg);
*/
LittleFS.begin(); // Starts FileSystem, autoformats if no FS is detected
readSetting(); // Read all the detector settings from flash
/*
Serial.begin();
while(!Serial) {
; // Wait for Serial
}
*/
Serial.println("Welcome to the Open Gamma Detector!");
Serial.println("Firmware Version " + FWVERS);
if (conf.enable_display) {
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("Failed communication with the display. Maybe the I2C address is incorrect?");
conf.enable_display = false;
} else {
display.setTextSize(1); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.println("Open Gamma Detector");
display.print("FW ");
display.println(FWVERS);
display.display();
delay(1000);
}
}
}
/*
LOOP FUNCTIONS
*/
void loop() {
// Interrupts run on this core
//__wfi(); // Wait For Interrupt
if (conf.auto_reset) {
resetSampleHold();
}
rp2040.wdt_reset(); // Reset watchdog, everything is fine
delayMicroseconds(500);
}
void loop1() {
if (conf.ser_output) {
if (Serial) {
if (conf.print_spectrum) {
for (uint16_t index = 0; index < uint16_t(pow(2, ADC_RES)); index++) {
Serial.print(String(spectrum[index]) + ";");
//spectrum[index] = 0;
}
Serial.println();
} else if (event_position > 0 && event_position <= EVENT_BUFFER) {
for (uint16_t index = 0; index < event_position; index++) {
Serial.print(events[index]);
Serial.print(";");
}
Serial.println();
}
}
event_position = 0;
}
if (conf.enable_display) {
drawSpectrum();
}
delay(1000); // Wait for 1 sec, better: sleep for power saving?!
}