I have a Duemilanove board.
I try to communicate with a RS232 device through pin 1&2.
config :
38400Bps/8bits/no parity/1stop byte / no control flow
I am using the NewSoftSerial library from arduiniana
I try to send AT command to my device thanks to this program:
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3);
void setup()
{
Serial.begin(9600);
Serial.println("Goodnight moon!");
mySerial.begin(38400);
}
void loop() // run over and over again
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
delay(100);
}
But it is not working.
When I send "AT" thanks to the terminal on my conputeur, the device shoud reply "OK" but nothing happen.
Normal communications use pins 0 & 1.This is connected to the USB / serial chip.
What hardware are you using to interface the arduino to the serial input. If you are not going through the USB port you need an RS232 to TTL voltage converter to enable it to work
If my arduino board is connected to my computor thanks the USB, I can't, on the same time, use the pin 0&1, can I?
I juste want use the Arduino board as a usb<->RS232 converter.
You told "If you are not going through the USB port you need an RS232 to TTL voltage converter to enable it to work "
In fact, i am sure that I don't need a max232 or similar RS232 interface adaptor.
Hey Grumpy_Mike - I think he made a mistake in the posting - if you look at his code, he's using pins 2 and 3. (It looks like he's trying to use the Arduino board as a serial passthrough board).
OP:
The question is, are you sure you have physically connected the "RS232" device to pins 2 and 3, and not pins 1 and 2?
The zigbit device has a maximum working voltage of 3.6V are you supplying it with this? Is your arduino a 5V system? If so you will need some voltage translation between the serial connections of both devices.
so i have to find an easy way to convert an hight speed (38400bd) 5v signal to a 3.6v signal
In fact, its a kind of max232 (15v<->5v) but working with 5v<->3,6v
If you know the solution ...
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3);
int numChar = 0;
int numCharb = 0;
int aa = 0;
void setup()
{
Serial.begin(9600);
Serial.println("let's go !");
mySerial.begin(38400);
Serial.flush();
mySerial.flush();
}
void loop() // run over and over again
{
if (mySerial.available()) {
readRadio();
}
if (Serial.available()) {
readinterface();
}
delay(100);
}
void readinterface(){
int index = 0;
delay(100); // let the buffer fill up
int numChar = Serial.available();
Serial.println(numChar);
char buffer[numChar];
int numCharB = numChar+1;
for (index = 0; index < numChar; index++) {
buffer[index] = Serial.read();
}
//buffer[index+1]='\r';
//buffer[index+2] = '\0';
mySerial.println(buffer);
Serial.println("Data_sent : ");
Serial.println(buffer);
// Clear the text and serial buffers
for (int x=0; x<numCharb; x++) {
buffer[x]='\0';
}
Serial.flush();
}
void readRadio(){
int index = 0;
delay(100); // let the buffer fill up
int numChar = mySerial.available();
if (numChar>2){
char buffera[numChar+2];
int numCharB = numChar+2;
for (index = 0; index < numChar; index++) {
buffera[index] = mySerial.read();
}
buffera[index+1]='\r';
buffera[index+2] = '\0';
Serial.print ("Data_read: ");
Serial.println (aa);
Serial.println(buffera);
// Clear the text and serial buffers
for (int x=0; x<numCharb; x++) {
buffera[x]='\0';
}
} Serial.flush();
aa = aa+1;
}
and here is what i can read :
let's go !
2
Data_sent :
atR
BA[ch149]
æ
Data_read: 0
ûÿ
@
ªüQ
ö
¨H¨JJêJÕ¤¤ü
2
Data_sent :
at
Data_read: 1
ì OK
3
Data_sent :
atx
Data_read: 2
ûá5ÿ
OK
quite hard to write on the forum, anyway, as u can see, when I sent AT, I didn't received only"ok"
When I sent "at" I received "(strange things) (carriage return) OK"