@ensign
Active 2 weeks, 3 days agoForum Replies Created
-
AuthorPosts
-
Thanks to everyone that contributed to our Survey regarding Monitor My Watershed. We are summarizing the results to inform our future efforts.
Jake, I deleted a “test” site of mine last week in MMW and it worked as expected (no error).
Problem solved. As Sara has noted before, the AltSoftSerial can only use pin 6 on the Mayfly for receiving and pin 5 for transmitting. So, while the sketch worked with Software Serial as shown above (and would have worked by defining pin 6 for transmitting and pin 5 for receiving), my pairing of the sensor rx and tx wires to the Grove jack was wrong. See lines 17 and 18 above; I swapped the wiring from the sensor to the Grove jack and now get data from the sensor. This is what the portion of the sketch in question should look like to work with AltSoftSerial:
12345678* white wire from RGB sensor to yellow Grove wire to D5 on Mayfly Grove connection* green wire from RGB sensor to white Grove wire to D6 on Mayfly Grove connection* ======================================================================= *///#include <SoftwareSerial.h> //include the SoftwareSerial library#include <AltSoftSerial.h> //this is the alternative to SoftwareSerial#define rx 6 //define Mayfly pin 6 as the receive pin#define tx 5 //define Mayfly pin 5 as the transmit pinI’m struggling to use AltSoftSerial in place of Software Serial to connect an Atlas-Scientific Color sensor to a Mayfly. The script below successfully communicates and reports sensor data as expected with Software Serial (with lines 21 and 26 active instead of lines 22 and 27 as shown below). As shown below I don’t get any data from the sensor. Any advice?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465/** =========================================================================* RGBsensorAutoMode.ino* Example of using the Atlas Scientific RGB sensor modified from* code provided by Atlas Scientific:* https://atlas-scientific.com/probes/ezo-rgb-embedded-color-sensor/** author: Scott Ensign <ensign@stroudcenter.org>* Build Environment: Arduino IDE* Hardware Platform: EnviroDIY Mayfly Arduino Datalogger V0.5** DISCLAIMER:* THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.** The wiring from the RGB sensor was spliced to a Grove cable as follows:* black wire from RGB sensor to black Grove wire to grd on Mayfly Grove connection* red wire from RGB sensor to red Grove wire to V on Mayfly Grove connection* white wire from RGB sensor to white Grove wire to D6 on Mayfly Grove connection* green wire from RGB sensor to yellow Grove wire to D5 on Mayfly Grove connection* ======================================================================= *///#include <SoftwareSerial.h> //include the SoftwareSerial library#include <AltSoftSerial.h> //this is the alternative to SoftwareSerial#define rx 5 //define Mayfly pin 5 as the receive pin#define tx 6 //define Mayfly pin 6 as the transmit pin//SoftwareSerial RGBserial(rx, tx); //define how the software serial port is going to workAltSoftSerial RGBserial(rx, tx); //this is the alternative to SoftwareSerialvoid setup() { //set up the hardwareSerial.begin(9600); //set baud rate for the hardware serial port_0 to 9600RGBserial.begin(9600); //set baud rate for the software serial port to 9600pinMode(22, OUTPUT); //On the Mayfly Data Logger, pin 22 supplies power to the Grove portsdigitalWrite(22, LOW);}void loop() { //digitalWrite(22, HIGH); //turn on power to the Mayfly's Grove portsdelay(500); //wait 500 millisecondsRGBserial.readStringUntil("\r"); //holds for 1 second; this and the subsequent two commands remove the introductory returns from the RGB sensorRGBserial.readStringUntil("\r"); //holds for 1 secondRGBserial.readStringUntil("\r"); //holds for 1 secondRGBserial.print('R'); //send that string to the Atlas Scientific productRGBserial.print('\r'); //add a <CR> to the end of the stringdelay(500); //wait 500 millisecondsint red = RGBserial.parseInt(); //myserial.parseFloat is an alternative, but unnecessary hereint green = RGBserial.parseInt();int blue = RGBserial.parseInt();int lux = RGBserial.parseInt();while (RGBserial.available() > 0) { // this gets ride of the "*OK" or anything else trailing at the endRGBserial.read();}Serial.print("Red: "); // print "Red: " to the serial monitorSerial.println(red); // print the red value from the sensorSerial.print("Green: "); // ...Serial.println(green);Serial.print("Blue: ");Serial.println(blue);Serial.print("Lux: ");Serial.println(lux);delay(1000); // wait ___ milliseconds; adjust this value to set the sampling interval for the sensor}This sketch is also available here: https://github.com/ScottEnsign/SDoutput. I’d welcome input and refinement.
Hi @Selbig. Here is a very simple sketch that prints a file from the microSD card to the serial monitor. It might be too rudimentary for your purposes, but thought I would share it here. Notice the line “// SD.remove(“datalog.txt”);” is commented out. Uncomment this line to DELETE the file specified instead of printing it to the serial monitor. I find it is helpful for my work to have this option available when I need it.
Arduino12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970//This sketch displays the files on a Mayfly Data Logger microSD card to the serial monitor and then outputs//a specific file named in the sketch below to the serial monitor.#include <SPI.h>#include <SD.h>File root;void setup() {Serial.begin(9600); // Open serial communications and wait for port to openwhile (!Serial) {; // wait for serial port to connect. Needed for native USB port only}Serial.print("Initializing SD card...");if (!SD.begin(12)) { // digital pin 12 is the microSD slave select pin on Mayfly; see if the card is present and can be initializedSerial.println("Card failed, or not present"); // don't do anything morewhile (1);}Serial.println("card initialized.");Serial.println("");root = SD.open("/");Serial.println("Files on microSD card");printDirectory(root, 0);Serial.println("");Serial.println("Displaying file:");// SD.remove("datalog.txt"); // THE NUCLEAR OPTION!!! UNCOMMENT TO DELETE THE FILE!File dataFile = SD.open("datalog.txt"); // Name the file to be opened.if (dataFile) { // if the file is available, write to it:while (dataFile.available()) {Serial.write(dataFile.read());}dataFile.close();}else {Serial.println("error opening datalog.txt"); // if the file isn't open, pop up an error:}}void loop() {// put your main code here, to run repeatedly:}void printDirectory(File dir, int numTabs) { //This is a function that displays all the files on the SD card to the serial monitor.while (true) {File entry = dir.openNextFile();if (! entry) {// no more filesbreak;}for (uint8_t i = 0; i < numTabs; i++) {Serial.print('\t');}Serial.print(entry.name());if (entry.isDirectory()) {Serial.println("/");printDirectory(entry, numTabs + 1);} else {// files have sizes, directories do notSerial.print("\t\t");Serial.println(entry.size(), DEC);}entry.close();}}Fiona, if you haven’t already found it, check out Adam Gold’s blog about using the Mayfly with Atlas Scientific sensors. Adam’s github has documentation about a carrier board that may involve isolation.
Hi Dan,
We recently did some internal testing of this issue and will post results soon. We don’t have a “fix”, but we did measure this behavior to guide our own interpretation of data.
Scott
Hi James,
I’ve used Atlas Scientific’s RGB sensor on lagrangian river drifters in the past. The application is written up in Limnology and Oceanography (or see this video abstract of the article). I’m attaching two simple sketches for using this sensor with the Mayfly Data Logger. The first (…AutoMode) just prints R,G,B, and Lux at an interval to the serial monitor. The …ManualMode sketch allows you to interact with the sensor using the commands from the datasheet. Please keep the EnviroDIY community updated on your progress.
Thanks,
Scott
Attachments:
Thanks, Neil. That’s helpful to know that ThingSpeak via Modular Sensors might be a better option for this user’s purposes. He has an interesting classroom laboratory application that I’ll encourage him to share if he is able to pilot it at his college.
-
AuthorPosts