Im doing a school project where i have an arduino mega, with a bees shield (Bees Shield | Seeed Studio Wiki). On this shield i have the bluetooth bee (Bluetooth Bee | Seeed Studio Wiki) and a XBee 2.5. They are plugged directly onto the bees shield, with no other wiring.
I have gotten the xbee to work on 9600 baud rate, and the bluetooth to work on a 38400 baud rate, but thats seperatly. How do get them to work, so that i can connect to the bluetooth with my phone, and then have the xbee send commands?
I have written some code, where i tried, but can you help me out to see what the problem might be? When i use this code none of them work, i cant see it on bluetooth, and the xbee won't receive commands.
//long DATARATE = 38400;
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte1; // a variable to read incoming serial data into
int incomingByte2;
void setup()
{
Serial1.begin(9600);
Serial2.begin(38400);
pinMode(ledPin, OUTPUT);
//------BLUETOOTH SETUP-------
Serial2.print("\r\n+STWMOD=0\r\n"); // set to slave
delay(1000);
Serial2.print("\r\n+STNA=HomeAutoDroid\r\n"); // DSC = digital setting circles
delay(1000);
Serial2.print("\r\n+STAUTO=0\r\n"); // don't permit auto-connect
delay(1000);
Serial2.print("\r\n+STOAUT=1\r\n"); // existing default
delay(1000);
Serial2.print("\r\n +STPIN=0000\r\n"); // existing default
delay(2000); // required
// initiate BTBee connection
Serial2.print("\r\n+INQ=1\r\n");
delay(2000); // wait for pairing
//----------------------------
}
void loop()
{
if (Serial2.available() > 0) {
incomingByte2 = Serial.read();
if (incomingByte2 == 'X') {
Serial.println("-----------Menu------------");
Serial.println(" T - TEST ");
Serial.println(" T - TEST ");
Serial.println(" H - TEST ");
Serial.println(" D - TEST ");
Serial.println("---------------------------");
}
if (incomingByte2 == 'H') {
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
if (incomingByte2 == 'L') {
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
}
if (Serial1.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte1 = Serial.read();
if (incomingByte1 == 'X') {
Serial.println("-----------Menu------------");
Serial.println(" T - TEST ");
Serial.println(" T - TEST ");
Serial.println(" H - TEST ");
Serial.println(" D - TEST ");
Serial.println("---------------------------");
}
if (incomingByte1 == 'H') {
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
if (incomingByte1 == 'L') {
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
}
}
Are the jumpers on that board set correctly so that the bluetooth device IS connected to Serial2? Are the jumpers on that board set correctly so that the XBee is connected to Serial1? That board is not designed for a Mega, so you must be running wires to the Serial1 and Serial2 pins.
PaulS:
Are the jumpers on that board set correctly so that the bluetooth device IS connected to Serial2? Are the jumpers on that board set correctly so that the XBee is connected to Serial1? That board is not designed for a Mega, so you must be running wires to the Serial1 and Serial2 pins.
What serial output are you seeing?
i tried to run 2 wires from the 2 holes where it says "Bee 2 RX and TX", i ran them to the TX1 and RX2.
I can't see through the board. I can't see where the other ends of the black and red wires go. There should be 4 of them, since the blue tooth and the XBee are bidirectional devices.
PaulS:
I can't see through the board. I can't see where the other ends of the black and red wires go. There should be 4 of them, since the blue tooth and the XBee are bidirectional devices.
The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2
The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2
I can't see the picture again. There need to be 4 wires - two for the bluetooth device and two for the XBee. The 2 from the blue tooth device go to TXn/RXn, and the two from the XBee go to TXm/RXm. Use Serialn to talk to the bluetooth, and Serialm to talk to the XBee.
The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2
I can't see the picture again. There need to be 4 wires - two for the bluetooth device and two for the XBee. The 2 from the blue tooth device go to TXn/RXn, and the two from the XBee go to TXm/RXm. Use Serialn to talk to the bluetooth, and Serialm to talk to the XBee.
Serialm and serialn? like the serial1 and serial2 in my code?
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Serialm and serialn? like the serial1 and serial2 in my code?
Yes.
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Yes, no, and maybe. As of the last picture you posted, you don't have the hardware connected properly, so no amount of software diddling is going to work.
Serialm and serialn? like the serial1 and serial2 in my code?
Yes.
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Yes, no, and maybe. As of the last picture you posted, you don't have the hardware connected properly, so no amount of software diddling is going to work.
Now that the bluetooth bee is wired to rx2 and tx2. I need to write the code, so that it can read bluetooth bee on 38400 baudrate and the xbee on baudrate 9600.
I need to send these codes through the serial on baudrate 38400
What is the Serial Monitor supposed to do with this crap? Why are you not sending this to the bluetooth device on Serial3 (if the device is connected to TX3/RX3)?