Here's the system I want to work on:
- The weight controller device detects weight which can transfer data via RS232 serial connection
- I used RS232 converter to TTL serial module to connect the weight controller device to Arduino
- The TTL connections were made to respective pins of Arduino UNO Board (GND-GND, VCC-5V, RX-0, TX-1)
The serial print from serial connection should produce 17 character length string : ST,GS 1.58,kg
Why am I getting strange results at times?
// Read Serial (RS232) data from Weight Controller Device via RS232 to TTL Converter Module
// Ignore the include statement, the editor does not allow pasting certain characters
include SoftwareSerial.h
int RX_PIN = 2;
int TX_PIN = 3;
int BAUD_IDE = 9600;
int BAUD_WEIGHT_SENSOR = 9600;
// serial port from weight controller
SoftwareSerial mySerial = SoftwareSerial(RX_PIN, TX_PIN);
void setup() {
mySerial.begin(BAUD_WEIGHT_SENSOR);
Serial.begin(BAUD_IDE);
}
void loop() {
while (mySerial.available()) {
int inChar = mySerial.read();
if (inChar != '\n') {
serialData += (char)inChar;
}
else {
int dataSize = serialData.length();
Serial.print(serialData);
Serial.print(" length: ");
Serial.print(dataSize);
Serial.print("\n");
delay(3000);
serialData = "";
}
}
serialData = "";
}
// this one works perfectly but i want to store as string to
process
// information and use for other functions
/*void loop() {
if (mySerial.available()){
Serial.print((char)mySerial.read());