0

I have an Arduino Uno and an Adafruit data logging shield and I have connected a digital pressure sensor that uses serial communication. The sensor requires a character to start transmitting data. I have managed to read the data using this code:

#include <SoftwareSerial.h> 
SoftwareSerial mySerial(8,9); 

int depth;

void setup() {

    Serial.begin(9600);
    mySerial.begin(9600);
    mySerial.print("C");

}

void loop() 
{

 if (mySerial.available()) {

   depth = mySerial.read();

 }

}

This returns the following:

C1000
C1000
C1000

where 1000 is the value.

I have written another code that logs data to the shield and tested with other sensors but I cannot log data from this sensor by modifying the above code and cannot find any relevant examples. If I add something like this it does not return the same value.

logfile.println(depth);

Complete newbie in so any suggestions are welcome.

UPDATE

enter image description here

  • Comments are not for extended discussion; this conversation has been moved to chat. – VE7JRO Jul 5 '19 at 16:53
1

use the C as the line start indicator. if received char is 'C' then do a file.println(); example with output to Serial

#include <SoftwareSerial.h> 
SoftwareSerial mySerial(8,9); 

void setup() {
    Serial.begin(9600);
    mySerial.begin(9600);
    mySerial.print("C");
}

void loop() {
 if (mySerial.available()) {
   char c = mySerial.read();
   if (c == 'C') {
     Serial.println();
   }
   Serial.write(c);
 }
}
| improve this answer | |
  • But this code does not do anything different than the simple code. My problem is not that I am not reading the data or that I do not see the data printed in the serial monitor. I do receive all the data. The problem comes when I try to log the data. I think the data come in so fast from the serial, but when I add delays everything is messed up. – Nik_ol Jul 5 '19 at 10:08
  • it prints completely different then the code in Question. did you try it? – Juraj Jul 5 '19 at 10:25
  • Yes I tried it. It prints the same with a gap between its measurement. Also it uses a lot more of the dynamic variable. But it prints the same with a gap between each C1000 – Nik_ol Jul 5 '19 at 11:44
  • is it not what you want? every set on a new line? – Juraj Jul 5 '19 at 11:59
  • No. I want to log the data to an SD card. When I use this code to log I get one number every second. I have added a screen shot in the original post. I want to get all the 4 numbers in one second and then the new 4 numbers in the next second. – Nik_ol Jul 5 '19 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.