am trying to build a connection between two
Leonardo Microcontrollers using Zigbee
Using which XBees? How are they connected to the Leonardos? How are the XBees configured?
I've done the net tutorials but it isn't working
with me
Was that the net tutorial on how to dye Easter eggs while wearing a pink tutu and dancing the Maramba? What part of that didn't work? Didn't the eggs come out the right color?
is there difference between using uno or Leonardo
Yes.
and is there something called xbee.begin(9600)
Maybe. Far to many unanswered questions for this one to make any sense by itself.
Using which XBees? How are they connected to the Leonardos? How are the XBees configured?
xbee Series 2, connected directly to the leonardo. they are configured using XCTU.
Was that the net tutorial on how to dye Easter eggs while wearing a pink tutu and dancing the Maramba? What part of that didn't work? Didn't the eggs come out the right color?
it was the hello world;
this is my code in the sender
void setup() {
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void command(char command)
{
Serial.println(command);
}
and this is in the receiver
void setup() {
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
//Standard PWM DC control
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
int reading = 869;
int reading2 = 31;
int reading3 = 55;
int state = 0;
int sensorValue1;
int sensorValue2;
int sensorValue3;
int speed1;
int speed2;
void command(char command)
{
Serial.println(command);
}
void setup() {
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
if(state==0)
{
speed1=450;
speed2=450;
}
sensorValue1 = analogRead(A0);
delay(1);
if ( sensorValue1 < reading)
{
speed1=225;
speed2=450;
command('1');
}
sensorValue2 = analogRead(A2);
delay(1);
if ( sensorValue2 < reading3)
{
command('2');
speed1=450;
speed2=225;
}
// read the input on analog pin 0:
analogWrite (E1,speed1); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,speed2);
digitalWrite(M2,HIGH);
delay(7);
}
and this is the 2nd code for the following car
//Standard PWM DC control
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
int state = 0;
int speed1;
int speed2;
int command;
void setup() {
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
analogWrite (E1,speed1); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,speed2);
digitalWrite(M2,HIGH);
delay(1);
The major difference between the UNO and the Leonardo is that on the UNO pins 0 and 1 are connected to the Serial instance, while on the Leonardo, they are connected to the Serial1 instance. On the UNO, Serial is also connected to the USB interface. On the Leonardo, Serial is connected to the USB interface.
So, it the XBee were connected, via a shield, to a UNO, via the hardware serial pins, and you wanted to read from the XBee and write to the Serial Monitor, you'd use Serial.read() and Serial.print().
If the XBee were connected, via a shield, to a real Leonardo, , via the hardware serial pins, and you wanted to read from the XBee and write to the Serial Monitor, you'd use Serial1.read() and Serial.print().
I don't know, on your clone, where the XBee is connected. You might have luck reading data from it, assuming that it is properly configured, using Serial1.read() instead of Serial.read(), and you might have luck sending data to it using Serial1.print() instead of Serial.print().