Home › Forums › Mayfly Data Logger › Using AltSoftSerial with Mayfly
Tagged: AltSoftSerial, Atlas Scientific
- This topic has 3 replies, 3 voices, and was last updated 2021-08-18 at 4:50 PM by Scott Ensign.
-
AuthorPosts
-
-
2019-02-25 at 11:05 AM #12824
I’m currently using NeoSWSerial to take water level measurements using a Maxbotix 7383 HRXL-WRLST sensor (pins: neoSSerial1Rx = 11, neoSSerial1Tx = -1), but I am interested in using AtlSoftSerial because it is more accurate. Does anyone know the Mayfly pin designations for AltSoftSerial? Is it possible to use one of the Grove ports like I am currently using with NeoSWSerial? Thanks in advance for any advice!
-
2019-02-25 at 11:10 AM #12825
With AltSoftSerial, data in to the Mayfly goes on pin 6, out from Mayfly on pin 5. It’s kind-of a pain because the Tx and Rx are broken into different Grove ports, but for something like the Maxbotix that you only need Rx for, it’s fine.
-
2021-08-18 at 1:19 PM #15837
I’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} -
2021-08-18 at 4:50 PM #15838
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 pin
-
-
AuthorPosts
- You must be logged in to reply to this topic.