i have two xbee pro 528 one as router and one as cordinater. im using xctu with two seperat instances opened and i get them to comunicate through the serial monitor in xctu.
im using a arduino micro with the uart adaptor and a mega with the seed studios xbee xhield v2.1. it supposed to send hellow world to the cordinator but nothing. this is my code with router side first
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("hello world");
delay(5000);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
Serial.write(Serial.read());
}
}
So the XBees communicate thru X-CTU and not between 2 arduinos? Try switching RX and TX. What is the 'uart adaptor'? Is it a voltage level translator? Oh and one more thing, try changing Serial.read and Serial.print on the Micro to Serial1.print and Serial1.read. The Serial Monitor reads Serial and the RX and TX pins are Serial1.
The adaptor is on the micro it has the pins for 5v grnd rx tx and rst that was the first code the mega has the shield the second code .... I'm assuming youent the mega to change to serial1 should I also change serial.begin to serial1
With the second piece of code you are trying to send and receive serially at the same time using the same pins. This isnt going to work. Try the software serial library:
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
Connecting the RX and TX of the Xbee to pins 10 and 11
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("hello world");
delay(5000);
}
In the micro yes the rx light flashes every 5 seconds but the shield Has lights for power=steady, rx signal = off , associate indicator= flash and status (sleep/on)= steady
so i disconected the mega with the cordinator from xctu and just used the arduino serial monitor with the router xbee still on xctu through the usb adaptor. i go into console work mode and connect it to the serial the packets and characters i type all get sent and show up on the arduino serial monitor for the mega im assuming this means the problem is with my ardino micro set up or code
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
mySerial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
mySerial.println("hello world");
delay(5000);
}
only problem now is on te mega side i shows that its connected but data received is constant 0 i know i did something wrong with the interupt...maybe i dont need it but heres the code
#include <Servo.h>
#include <MotorDriver.h>
Servo camera;
int data = 0;
const int rx_led = 42;
void setup()
{
//MOTOR SHIELD SET MOTOR SPEEDS
motordriver.init();
motordriver.setSpeed(400, MOTORB);
motordriver.setSpeed(200, MOTORA); // steering motor
//DATA RECIEVE INDICATOR LIGHT
pinMode(rx_led, OUTPUT);
digitalWrite(rx_led, LOW);
//RECIEVER PINS
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
attachInterrupt(1, RF_VT, RISING);
//BEGIN SERIAL COMMUNICATION
Serial.begin(9600);
}
void loop()
{
//DATA FROM TRANSMITTER TO DETERMINE MOVE FUNCTION
//stop
if (data == 15)
{
motordriver.stop();
}
//turn wheels right
else if (data == 14)
{
motordriver.goRight();
}
//turn wheels left
else if (data == 13)
{
motordriver.goLeft();
}
// move forward
else if (data == 11)
{
motordriver.goForward();
}
//move backward
else if (data == 7)
{
motordriver.goBackward();
}
//straight left turn
else if (data == 9)
{
motordriver.goForward();
motordriver.goLeft();
}
//straight right turn
else if (data == 10)
{
motordriver.goForward();
motordriver.goRight();
}
//back left turn
else if (data == 5)
{
motordriver.goBackward();
motordriver.goLeft();
}
//back right turn
else if (data == 6)
{
motordriver.goBackward();
motordriver.goRight();
}
else
{
motordriver.stop();
}
//SERIAL PRINT DATA RECIEVED
delay(50);
Serial.print("data=");
Serial.println(data, DEC);
}
//=======================================
//=======================================
void RF_VT() // interrupt service function
{
data = Serial.read();
}
on my receiving side data starts out as 0 like it should but when i push the forward button it waits till i let go then sends data but its serial prints a bunch of random numbers then stops at 48 and jut stays constant even if i try other buttons from the controller.......is it possible its just adding the number in my code for as long as i push it max maby being 48 heres the code for the real project im doing conrol first
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12); // RX, TX
//BUTTON PINS
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
/*
const int Light = 10; //lights
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
*/
void setup()
{
//SET BUTTON AS PULLUP
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(SW3, INPUT_PULLUP);
pinMode(SW4, INPUT_PULLUP);
//pinMode(Light, INPUT);
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
mySerial.begin(9600);
}
void loop(void)
{
unsigned char i = 0;
//backwards
if (digitalRead(SW1) == HIGH)
{
i += 1;
}
//forward
if (digitalRead(SW2) == HIGH)
{
i += 2;
}
//left
if (digitalRead(SW3) == HIGH)
{
i += 4;
}
//right
if (digitalRead(SW4) == HIGH)
{
i += 8;
}
/* buttonState = digitalRead(LIGHT);
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
Serial.println("off");
}
delay(50);
}
lastButtonState = buttonState;
if (buttonPushCounter % 2 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
} */
delay(50);
mySerial.print("i=");
mySerial.println(i, DEC);
Serial.print("i=");
Serial.println(i, DEC);
}
#include <Servo.h>
#include <MotorDriver.h>
Servo camera;
int data = 0;
const int rx_led = 42;
void setup()
{
//MOTOR SHIELD SET MOTOR SPEEDS
motordriver.init();
motordriver.setSpeed(400, MOTORB);
motordriver.setSpeed(200, MOTORA); // steering motor
//DATA RECIEVE INDICATOR LIGHT
pinMode(rx_led, OUTPUT);
digitalWrite(rx_led, LOW);
//RECIEVER PINS
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
//BEGIN SERIAL COMMUNICATION
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
}
//DATA FROM TRANSMITTER TO DETERMINE MOVE FUNCTION
//stop
if (data == 15)
{
motordriver.stop();
}
//turn wheels right
else if (data == 14)
{
motordriver.goRight();
}
//turn wheels left
else if (data == 13)
{
motordriver.goLeft();
}
// move forward
else if (data == 11)
{
motordriver.goForward();
}
//move backward
else if (data == 7)
{
motordriver.goBackward();
}
//straight left turn
else if (data == 9)
{
motordriver.goForward();
motordriver.goLeft();
}
//straight right turn
else if (data == 10)
{
motordriver.goForward();
motordriver.goRight();
}
//back left turn
else if (data == 5)
{
motordriver.goBackward();
motordriver.goLeft();
}
//back right turn
else if (data == 6)
{
motordriver.goBackward();
motordriver.goRight();
}
else
{
motordriver.stop();
}
//SERIAL PRINT DATA RECIEVED
delay(50);
Serial.print("data=");
Serial.println(data, DEC);
}