I need your help. I want to display a number using this program from my PC to arduino and to my u8g display. Currently, I am testing using AccessPort (from PC) to send data via usb to rs232 to TTL (arduino).
My code is pasted below. When I tried to send digit 1 to my arduino the receive signal is different it generates different numbers like 49, 10, 13 and keeps looping.
What could be the problem? I am using string and char but it is still the same.
I hope you could help me guys to display it correctly.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX
String incomingByte = ""; // for incoming serial data
void setup() {
mySerial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (mySerial.available() > 0) {
// read the incoming byte:
incomingByte = mySerial.read();
}
// say what you got:
mySerial.print("I received: ");
mySerial.println(incomingByte);
delay(1000);
}
There is a some misunderstanding. RS232 is not TTL. You don't need (I would say you MUST NOT) use RS232 to send data to arduino because it incompatible voltage levels.
Thank you for the clarification. So I was reading it correctly i tried to make it char and not as string and it worked but I still have some bugs in my program.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX
char incomingByte; // for incoming serial data
void setup() {
mySerial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (mySerial.available() > 0) {
// read the incoming byte:
incomingByte = mySerial.read();
}
// say what you got:
mySerial.print("I received: ");
mySerial.println(incomingByte);
delay(1000);
}
using the AccessPort and writing the data it does not immediately get the data. For example, I sent "1". it will say "I received: 1". However, when I send "2", it does not change the "I received: 1".