I'm new to Arduino, and eager to learn but there is too many information regarding same problems and I'm simply lost.
I would like to make a RS232 to SD data logger but I'm stuck when it comes to dealing with serial communication.
I'm aware that it has already been discussed and there are good tutorials (even already built loggers) but I would like to make it from scratch and get into this amazing Arduino world.
I understand "Serial" and Serial monitor, and I've been practicing with it, but can't figure out the best way to solve the following:
- Send "0R0+CR+LF" via SoftwareSerial
- Capture the response from device via SoftwareSerial and display it on Serial monitor (in the code comments, you'll see how the response looks like).
This is just a beginning, later I plan to write received string on SD card (just pass it as it is, without parsing it as it is already CSV).
I've built a RS232 shifter and it is working when I connect Arduino to another PC running terminal application (I can chat using Serial monitor and PC2).
/*Arduino Uno logger for Vaisala WXT520 weather sensor*/
#include <SoftwareSerial.h>
SoftwareSerial vaisala(2, 3); // RX, TX
String command = "0R0"; //request data from sensor, must be followed with CR+LF
String data = ""; // maybe change this approach and not use String
void setup()
{
vaisala.begin(19200); // default device settings are 19200,8,N,1
}
void loop()
{
vaisala.println(command); //println because CR+LF must be sent
//device will return the following string:
// 0R0,Dx=005D,Sx=2.8M,Ta=23.0C,Ua=30.0P,Pa=1028.2H,Rc=0.00M,Rd=10s,Th=23.6C<cr><lf>
/* capture whole received string and print it to Serial Monitor */
if (vaisala.available()>0)
data = vaisala.read();
Serial.println(data);
delay(2000); //
}
Unfortunately, I can't test this sketch because I can't properly communicate with the mentioned device but that is another issue I'll try to solve myself (I think built in RS232 port on device is broken, so I'll try to use RS485 but I'm waiting RS485/232 converter to arrive).
Regarding the device response given in the code comment, what is the best approach to deal with it?
Thanks in advance!!!