Hello All,
I'm trying to use an Arduino Uno R3 to read data from a serial connection. I'm using softwareserial on pins 9(Rx) and 8(Tx), and I have an RS232 TTL device connected to my Uno.
The device coonected on the other end has the follwing capabilites:
Asynchronous, bi-directional, half-duplex
Data format Baud rate: 1200, 2400, 4800, 9600 bps
Data: 7 bits + parity 1bit (even or odd) or 8 bits (non-parity)
Start bit: 1 bit
Stop bit: 1 bit
Code: ASCII
Terminator: CRLF (CR: 0Dh, LF: 0Ah)
This is a sample of the string generated:
S T , + 0 0 1 2 . 3 4 5 gCR LF
If I open excel or notepad, data is continuosly written to application.
This is a sample of how the data is outputted:
ST,+0012.345g
ST,+0012.345g
ST,+0012.345g
ST,+0012.345g
ST,+0012.345g
ST,+0012.345g
The data is outputted about every 100ms
If I open a terminal emulator such as putty and connect at with the same vaules I'm attempting to use with my code, I see the same output.
I'm using the example code found in the arduino library.
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
#define rxPin 9
#define txPin 8
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(9600);
mySerial.begin(2400);
}
void loop()
{
Serial.println("this is a test"); // making code is working
Serial.println(mySerial.read());
delay(100);
}
I removed the if(mySerial.available()); statement since there was no output, and it returns a -1, which I assume is telling me there is no data.
Note: I am using a straight through cable. I have also tried a null modem. The TTL converter supports both 3.3v and 5v.
My issue is mst likely due to my lack of uderstanding of how the serial function works, or serial communication in general. I have tried many different versions of this code such as using pins 2 and 3 for Rx and Tx, as well as other snippets I have found while researching my issue. After a few weeks, I thought I would see if someone much smarter than me could shed some light on things for me.
Thanks!