hi all
i wrote a standard code for two atmega328p on standalone boards with baud rate 9600 as following:
first MC:
if(Serial.available())
{
delay(100);
while(Serial.available()>0)
{
c=Serial.read();
v+=c;
if(Serial.available()<0)
{
break;
}
}
}
second MC
if(Serial.available())
{
delay(100);
while(Serial.available()>0)
{
c=Serial.read();
v+=c;
if(Serial.available()<0)
{
break;
}
}
}
hardware connection:
TX--> RX
RX--> TX
GND--> GND
but i receive nothing , while i have full serial communication with no atmega328p on UNO board.
can any one help me?
Which one is sending? I don't see any Serial.print or Serial.write.
the two codes have sending code
Serial.println(data); in the loop function
but i cut off the receiving code
thanks for replaying
LarryD
March 24, 2016, 8:18pm
4
Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
Please, show us a schematic and picture of your circuit.
ok friend
Note: as i told in the first post that i test each MC alone with the UNO board ( same FTDI function) and i got my aim.
MC 1 code
char c;
String v;
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(5,INPUT);
}
void loop()
{
if(Serial.available())
{
delay(100);
while(Serial.available()>0) // must make sub string
{
c=Serial.read();
v+=c;
if(Serial.available()<0)
{
break;
}
}
}
delay(10);
if(v=="hi")
{
digitalWrite(13,HIGH);
v="";
}
if(digitalRead(5)==HIGH)
{
Serial.println("buzzon");
}
}
MC 2
char c;
String v;
void setup()
{
Serial.begin(9600);
pinMode(9,OUTPUT);
pinMode(8,INPUT);
}
void loop()
{
if(Serial.available())
{
delay(100);
while(Serial.available()>0)
{
c=Serial.read();
v+=c;
if(Serial.available()<0)
{
break;
}
}
}
if(v=="buzzon")
{
digitalWrite(9,HIGH);
v="";
}
if(digitalRead(8)==HIGH)
{
Serial.println("hi");
}
}
LarryD
March 24, 2016, 9:36pm
6
Will you show us your schematic and a good image of the wiring.
Use character strings rather than String.
.
Robin2
March 24, 2016, 10:26pm
7
Have a look at Serial Input Basics
...R
LarryD:
Will you show us your schematic and a good image of the wiring.
Use character strings rather than String.
.
it is a pcb board
connection as following:
RX--> TX
TX--> RX
GND --> GND
all input pins are connected to 10k resistor and ground.
push buttons are connected to VCC and input pins.
Robin2
March 30, 2016, 8:21pm
10
palmood:
any help friends?
You have not told us what you have tried based on the Replies you have already received. Maybe it would be an idea to read through all of them again.
...R
LMI1
March 30, 2016, 8:42pm
11
Are you using same pins as Arduino uses for serial bus. Then you could see data you send in the serial monitor. OK, if I understand you correctly you are not. I am not sure what you wrote, but you see if you actually really sending something, if you put a LED(and a resistor), multimeter or oscilloscope to your data pin. Serial speed is high ofcourse, so multimeter or LED shows little, but it will show something.