I connect My router with DD-WRT to my Arduino
everything work great I can read everything over Serial Monitor without any weird charterers.
Router Arduino
TX RX
RX TX
GND GND
What I want is to send SSH command from my router to my Arduino to control PIN13
From what I know TX-RX it's a serial port like USB!
So I made simple code:
void setup () {
pinMode(13,OUTPUT);
Serial.begin(115200);
}
void loop () {
int val;
if (Serial.available ()) {
delay (100);
while (Serial.available() >0) {
val=Serial.read();
if(val=='1') {digitalWrite(13,HIGH); }
else if (val=='0') digitalWrite(13,LOW);
}
}
}
When I send commands from Serial Monitor it's work LED off,on
But when I tried that from my Router by using this simple command it dose not work at all
There are so many things that could be wrong on the router configuration. You should find a way to test it separately. One way is to hold the Arduino reset line low. Then you should be able to monitor the serial data from the router, using the Arduino USB serial connection. But TX and RX lines will be reversed. Perhaps they already are...
If Serial Monitor can talk directly to the Router via RX/TX then the Arduino can't talk to the Router, only to Serial Monitor. The Router and Arduino are both using TX to send to Serial Monitor and RX to receive from Serial Monitor. That means the Arduino TX and Router TX are connected together. To have the Arduino talk to the Router instead of Serial Monitor, reverse the RX and TX connections on the Router.
In order for the Arduino to use both the Router and Serial Monitor you need a second serial port. Use Software Serial, an Arduino Leonardo (Serial to Serial Monitor and Serial1 to Router), or an Arduino Mega (Serial to Serial Monitor and Serial1 , Serial2, or Serial3 to Router).
I flip my wires it doesn't work too!, I believe the problem from my Arduino code,
sending a command from my router only work if I upload empty code to my Arduino, only inside serial Monitor
Any other suggestions!?
I only want to send commands from my router to Arduino.
narzan:
sending a command from my router only work if I upload empty code to my Arduino, only inside serial Monitor
Any other suggestions!?
Yes, re-read Robin2's post.
It is very likely your "problem" is related to the auto-reset of the Arduino board, which occurs each time the serial port is re-opened with your echo command.
if (Serial.available ()) {
delay (100);
while (Serial.available() >0) {
This makes absolutely no sense. There is no reason to check if the serial buffer has at least 1 character, delay, and then check if it still has 1 character.
UPDATE
It's work now if I send 1 it's ON
But if i send 0 it doesn't work
I worked befure with USB serial port + VB.net
but always worked with values at this moment I really not know what I am doing and why when I removed that it's work
if (Serial.available ()) {
delay (100);
while (Serial.available() >0) {
narzan:
Can you explain that more please more hints..
I used the same code that useauly use with VB.net over serial port, it's weird That douse it work,
It's bad form to not at least check if there is something in the serial buffer. You didn't quite understand my point earlier.
void setup () {
pinMode(13, OUTPUT);
Serial.begin(115200);
}
void loop () {
int val;
if (Serial.available() > 0) {
val = Serial.read();
if (val == '1') {
digitalWrite(13, HIGH);
}
if (val == '0') {
digitalWrite(13, LOW);
}
}
}
The reason your code works without the check is that Serial.read() returns -1 when there are no characters in the buffer. So in theory, your code is fine. In practice, it is bad form.
It's work on VB.net without any problem ?!
I saw some articles to be sure, I didn't see anything different.
Just see This article
you can wright the code line I will not eat you