Go Down

Topic: interfacing software with arduino uno (Read 502 times) previous topic - next topic

mickchunming

Sep 08, 2015, 11:39 pm Last Edit: Sep 08, 2015, 11:44 pm by mickchunming
I wish to ask that why my arduino program cannot comunicate by using the rs232. The pins I used are Pin 0 and Pin 1 to transfer and received the data. Below is my coding but  I dont know where I program wrongly, can anyone help me?

PaulS

Code: [Select]
   while(Serial.available()<9){
       //light Led
   }
   if (Serial.available()>7) {

The while loop is going to spin until there are 9 bytes of data to read. It's silly, then, to test for there being more than 7 byes. 9 will ALWAYS be more than 7.

Do not post code with huge chunks commented out. Delete that crap.

Do not post piss-poorly formatted code. Use Tools + Auto Format first.

Some comments in the code to explain what you think it's doing would be good.

So would a schematic.

Why are you connecting the device to the hardware serial pins? Keep those for debugging, until you KNOW that the code is working. Use SoftwareSerial to create a software serial port on two other pins.
The art of getting good answers lies in asking good questions.

mickchunming

Sorry I am new in coding, so you mean that I need to debug it by using SoftwareSerial function?

Robin2

#3
Sep 09, 2015, 11:52 am Last Edit: Sep 09, 2015, 11:53 am by Robin2
You should use SoftwareSerial to make the connection to your RS232 device and leave the Tx0 and Rx0 pins free to communicate with the Arduino Serial Monitor.

Note that "proper" RS232 uses voltages that can damage an Arduino and you may need something like a MAX232 to convert the RS232 signals to the TTL levels that the Arduino uses.

The code examples in Serial Input Basics may be useful. They can be easily adapted to work with SoftwareSerial.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up