From e3da32e18bb19a4e0c8eb6bd8eb4760f8a28ce52 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Tue, 27 Jul 2021 10:22:06 -0400 Subject: [PATCH] Added examples for AS7265x and AS7341 spectrometers, with JSON files for use with Serial Studio --- .../AS7265x_spectrometer/AS7265x.json | 172 ++++++++++++++++++ .../AS7265x_spectrometer.ino | 76 ++++++++ .../AS7341_Spectrometer/AS7341_2.json | 172 ++++++++++++++++++ .../AS7341_Spectrometer.ino | 21 ++- 4 files changed, 434 insertions(+), 7 deletions(-) create mode 100644 LightSensors/AS7265x_spectrometer/AS7265x.json create mode 100644 LightSensors/AS7265x_spectrometer/AS7265x_spectrometer.ino create mode 100644 LightSensors/AS7341_Spectrometer/AS7341_2.json diff --git a/LightSensors/AS7265x_spectrometer/AS7265x.json b/LightSensors/AS7265x_spectrometer/AS7265x.json new file mode 100644 index 0000000..3adc02f --- /dev/null +++ b/LightSensors/AS7265x_spectrometer/AS7265x.json @@ -0,0 +1,172 @@ +{ + "t": "AS7365x", + "g": [ + { + "t": "Readings", + "d": [ + { + "t": "395nm", + "v": "%1", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "435nm", + "v": "%2", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "460nm", + "v": "%3", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "485nm", + "v": "%4", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "510nm", + "v": "%5", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "535nm", + "v": "%6", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "560nm", + "v": "%7", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "585nm", + "v": "%8", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "645nm", + "v": "%9", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "705nm", + "v": "%10", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "900nm", + "v": "%11", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "940nm", + "v": "%12", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "610nm", + "v": "%13", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "680nm", + "v": "%14", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "730nm", + "v": "%15", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "760nm", + "v": "%16", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "810nm", + "v": "%17", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "860nm", + "v": "%18", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + } + ] + } + ] +} \ No newline at end of file diff --git a/LightSensors/AS7265x_spectrometer/AS7265x_spectrometer.ino b/LightSensors/AS7265x_spectrometer/AS7265x_spectrometer.ino new file mode 100644 index 0000000..fe0a8f9 --- /dev/null +++ b/LightSensors/AS7265x_spectrometer/AS7265x_spectrometer.ino @@ -0,0 +1,76 @@ +/* + AS7265x spectrometer test + + Works with MKR1010, MKR1000, Nano 33 IoT + Uses the following libraries: + http://librarymanager/All#SparkFun_AS7265X (for the sensor) + + created 22 Jun 2021 + by Tom Igoe +*/ +// include required libraries and config files +#include + +// initialize the light sensor: +AS7265X sensor; + +void setup() { + Serial.begin(9600); // initialize serial communication + // if serial monitor is not open, wait 3 seconds: + if (!Serial) delay(3000); + if (!sensor.begin()) { + Serial.println("Sensor is not responding. Please check wiring."); + while (true) + ; + } + // print header labels: + Serial.println("395nm, 435nm, 460nm, 485nm, 510nm, 535nm, \ + 560nm, 585nm, 645nm, 705nm, 900nm, 940nm, \ + 610nm, 680nm, 730nm, 760nm, 810nm, 860nm"); +} + +void loop() { + + // Read all 18 channels. This takes several seconds: + sensor.takeMeasurements(); + // print a header: + Serial.print("/* "); + // Print sensor readings: + Serial.print(sensor.getCalibratedA()); + Serial.print(","); + Serial.print(sensor.getCalibratedB()); + Serial.print(","); + Serial.print(sensor.getCalibratedC()); + Serial.print(","); + Serial.print(sensor.getCalibratedD()); + Serial.print(","); + Serial.print(sensor.getCalibratedE()); + Serial.print(","); + Serial.print(sensor.getCalibratedF()); + Serial.print(","); + Serial.print(sensor.getCalibratedG()); + Serial.print(","); + Serial.print(sensor.getCalibratedH()); + Serial.print(","); + Serial.print(sensor.getCalibratedI()); + Serial.print(","); + Serial.print(sensor.getCalibratedJ()); + Serial.print(","); + Serial.print(sensor.getCalibratedK()); + Serial.print(","); + Serial.print(sensor.getCalibratedL()); + Serial.print(","); + Serial.print(sensor.getCalibratedR()); + Serial.print(","); + Serial.print(sensor.getCalibratedS()); + Serial.print(","); + Serial.print(sensor.getCalibratedT()); + Serial.print(","); + Serial.print(sensor.getCalibratedU()); + Serial.print(","); + Serial.print(sensor.getCalibratedV()); + Serial.print(","); + Serial.print(sensor.getCalibratedW()); + // print a footer: + Serial.println(" */"); +} diff --git a/LightSensors/AS7341_Spectrometer/AS7341_2.json b/LightSensors/AS7341_Spectrometer/AS7341_2.json new file mode 100644 index 0000000..648c562 --- /dev/null +++ b/LightSensors/AS7341_Spectrometer/AS7341_2.json @@ -0,0 +1,172 @@ +{ + "t": "AS7365x", + "g": [ + { + "t": "Readings", + "d": [ + { + "t": "395nm", + "v": "%2", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "435nm", + "v": "%3", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "460nm", + "v": "%4", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "485nm", + "v": "%5", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "510nm", + "v": "%6", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "535nm", + "v": "%7", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "560nm", + "v": "%8", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "585nm", + "v": "%9", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "645nm", + "v": "%10", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "705nm", + "v": "%11", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "900nm", + "v": "%12", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "940nm", + "v": "%13", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "610nm", + "v": "%14", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "680nm", + "v": "%15", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "730nm", + "v": "%16", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "760nm", + "v": "%17", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "810nm", + "v": "%18", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + }, + { + "t": "860nm", + "v": "%19", + "g": true, + "u": "counts", + "w": "bar", + "min": 0, + "max": 65535 + } + ] + } + ] +} \ No newline at end of file diff --git a/LightSensors/AS7341_Spectrometer/AS7341_Spectrometer.ino b/LightSensors/AS7341_Spectrometer/AS7341_Spectrometer.ino index 523d87d..ed6f941 100644 --- a/LightSensors/AS7341_Spectrometer/AS7341_Spectrometer.ino +++ b/LightSensors/AS7341_Spectrometer/AS7341_Spectrometer.ino @@ -1,24 +1,30 @@ /* - AS7341 sensor readings + AS7341 sensor readings. Reads and prints the results + as a CSV string. This version uses a non-blocking + approach, using the startReading() and checkReadingProgress() + functions. It's about 2 seconds between readings. + + The printing and the JSON file with this sketch are formatted + for use with Serial Studio: + https://github.com/Serial-Studio/Serial-Studio Library: http://librarymanager/All#Adafruit_AS7341 - Reads and prints the results as a CSV string. - + created 18 Jun 2021 + modified 22 Jun 2021 by Tom Igoe */ #include +// instance of the sensor library: Adafruit_AS7341 as7341; // array to hold the raw readings: uint16_t readings[12]; -// last time you got a reading: -long int lastTime = 0; void setup() { // init serial, wait 3 secs for serial monitor to open: Serial.begin(9600); @@ -26,7 +32,8 @@ void setup() { if (!as7341.begin()) { Serial.println("Sensor not found, check wiring"); - while (true); + while (true) + ; } Serial.println("415nm, 445nm, 480nm, 515nm, 555nm, 590nm, 630nm, 680nm, Clear, 910nm"); @@ -56,7 +63,7 @@ void loop() { // skip 4 and 5 as they are repeats: if (r == 4 || r == 5) continue; Serial.print(readings[r]); - if (r < 11 ) Serial.print(","); + if (r < 11) Serial.print(","); } // print a footer: Serial.println(" */");