Hello everyone,
I have an arduino uno and a micro and trying to make communication between them by using rx tx. However i have a trouble. My uno reads an analog data and sends it via tx leg. I can see the datas via serial monitor but i cannot receive it from arduino micro. The tx leg of uno is connected to the rx leg of micro.
When i disconnect the uno from my computer (power is still on). it stops sending data. tx led does not emit light anymore.
I believe it only communicates with the computer but not with the arduino micro.
Can you help me with that problem?
Thank you.
My codes are below.
Arduino Uno's code(tx code)
int pot=0;
int a;
void setup()
{
pinMode(pot, INPUT);
Serial.begin(9600);
}
void loop()
{
a=map(analogRead(pot),0,1023,0,255);
Serial.println(a);
delay(1000);
}
Tx side - may need to use Serial.write instead of Serial.print.
Rx side:
if(Serial.available()>1) // two bytes are coming over, 0x000000XX and 0xXXXXXXXX
{
alow = Serial.read(); // maybe swap these two so placement is correct
ahigh = Serial.read();
a = (ahigh<<8) | alow;
Serial.println(a, HEX); // check high/low positioning
// do your mapping stuff, print again to make sure it is correct
delay(1000);
}
i have tried them but rx side still does not recieve anything and rx led does not emit light.
Everything on the board is common grounded. when i remove the usb cable of uno it's tx led stops working it stops sending data.
Maybe is there any code that needed to be written in the setup so rx will recieve data
Below is some servo/pot test code (you don't need servos to test). check the output using the serial monitor. If yu can see the output, then you could add a delimiter prior to transmitting to make the data reception easier.
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int potpin1 = 0; //analog input pin A0
int potpin2 = 1;
int newval1, oldval1;
int newval2, oldval2;
void setup()
{
Serial.begin(9600);
myservo1.attach(2);
myservo2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newval1 = analogRead(potpin1);
newval1 = map(newval1, 0, 1023, 0, 179);
if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){
myservo1.write(newval1);
Serial.print("1- ");
Serial.println(newval1);
oldval1=newval1;
}
newval2 = analogRead(potpin2);
newval2 = map(newval2, 0, 1023, 0, 179);
if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){
myservo2.write(newval2);
Serial.print("2- ");
Serial.println(newval2);
oldval2=newval2;
}
delay(50);
}