Now i'm trying to test the connection. I ssh to the router and am typing this command: echo 'hello' > /dev/tts/1
I'm trying to read the word hello through my serial monitor of the arduino. If i had connected the router to pin 0 (Rx) and pin 1(Tx) of the arduino, could I connect the usb to the pc and follow through the serial monitor, or i have to use softserial just for testing this?
Thanks for the reply. Yes they have both the same baud rate set at 9600.
My arduino code:
int number = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(13, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
number = Serial.read();
if (number == '55') {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000);
}
}
}
modded your code a bit, to test a single char at a time
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(13, OUTPUT);
}
void loop()
{
char c;
// send data only when you receive data:
if (Serial.available() > 0)
{
c= Serial.read();
if (c == '5')
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000);
}
if (c == '1')
{
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
}
}
Then try this
try echo '51515' > /dev/tts/1
A serial port transfers a byte a the time.
It is upon the sender/receiver to interpret it as a char, a (part of a) number, or anything.
Sending chars and expecting numbers or otherwise causes errors unless done on purpose.
In this latter case one must reassemble the number from char's by a function like atoi(),
the data comes in too fast for the serial port. As you run 9600 baud this is not likely to be the cause.,
It might be that another process is communicating with the same port on another baudrate (or even same baudrate) as I see the name PUTTY a well known serial application.
If you connect the Arduino to a normal PC does it work?
If you connect the WRT to a normal PC does it work?
If i had connected the router to pin 0 (Rx) and pin 1(Tx) of the arduino, could I connect the usb to the pc and follow through the serial monitor, or i have to use softserial just for testing this?
yes should work,
I don't have an openWrt so I can't repeat your experiments.
Does "ps " gives info about other processes using the tty port?
I managed to get the communication up and running correctly. However i connected the rx of arduino with tx of router and viceversa. Is it a problem, that arduino tx and rx are at 5V and routers tx and rx are at 3.3V. Should i regulate the voltage, or there's no harm if i leave it like that? The Max3232 connection i showed on first post seems it doesn't work.
Thanks for your interest in helping me sir, i really appreciate it
Serial should always be wired Tx->Rx (transmitting to receiving). As for the different logic levels, your only risk is to the router. It all depends on if it is 5v-tolerant. If you are concerned, just use a simple voltage divider on the arduino tx/router rx line.
newbiestudent:
I managed to get the communication up and running correctly. However i connected the rx of arduino with tx of router and viceversa. Is it a problem, that arduino tx and rx are at 5V and routers tx and rx are at 3.3V. Should i regulate the voltage, or there's no harm if i leave it like that? The Max3232 connection i showed on first post seems it doesn't work.
Thanks for your interest in helping me sir, i really appreciate it
Hi, please follow this and find the "voltage divider" technique that is used there between WRT and SSC-32 motor controller. Do the same between Arduino and WRT. I remember I did it this way and everything was fine. Hope this helps
It worked... however i think i had some bits shifted since there was some delay created by the capacitors.
As soon as i removed the capacitors, the message i was writing appeared correctly. So now i'm able to communicate between the router and the arduino. The advantage of this is that is bi-directional