Home › Forums › Mayfly Data Logger › Water level monitor with a Mayfly. › Reply To: Water level monitor with a Mayfly.
Hi
As usual Thanks for the support, I have added an RS232-to-TTL converter inline between the board and the mayfly and have had a go with the code you posted with only average success I seemed to be getting every second measurement as a 0 reading and some unreliable repeat-ability.
As I was dubious about the cheap converter I had added to the circuit I decided to try some code that worked well as a software serial option and just turned off the software converter. It seemed to be really good so I’ll go with that. I’ll attach it below for anyone else that may be playing around with these things. I agree the other 2 sensors you mention would be better for the job but I guess I’ll make do with what I have for now.
The example below can be used with a RS232 or TTL just by changing the true/false statement. true if you are using an RS232, false for TTL.
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 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(5, -1,false); // RX, TX, true sets the inverter void setup() { Serial.begin(57600); // Open serial communications and wait for port to open: mySerial.begin(9600); // set the data rate for the SoftwareSerial port delay(50); } void loop() { int index = 0; boolean startreading = false; char mm[6]; mySerial.flush(); while(index < 4){ if(mySerial.available()){ byte incoming = mySerial.read(); if(incoming == 'R') { startreading = true; } else if(startreading) { mm[index++] = incoming; } } } Serial.print("mm: "); Serial.print(mm); Serial.print(" "); Serial.println(); //delay(500); } |