Hallo
Ich habe einen Arduino Mega für das Empfangen von seriellen Daten an Pin 0 und 1 sowie ein Bluetooth Modul, welches an Pin 11 empfangen soll und diese Daten dann an Pin 28, resp. 30 per SoftwareSerial weitergibt.
Nun wenn ich den folgenden Testsketch für das Empfangen von Bluetoothdaten auf einen UNO lade, dann funktioniert es ohne Probleme:
#include <SoftwareSerial.h> //adds library for software serial (Bluetooth module)
const unsigned long Baudrate = 9600; //starts serial ports with a baudrate by 9600 b/s
const unsigned long BaudrateBT = 19200; //starts serial port for the Bluetooth module with a baudrate by 19200 b/s
const byte Bluetooth = 11; //Bluetooth Module connected to pin D11
String BT_RX; //reads the letter from Bluetooth serial
//create software serial ports
SoftwareSerial BT(Bluetooth, 20); //RX, TX pin from Bluetooth module
void setup() {
BT.begin(BaudrateBT); //starts serial port with a baudrate by "BaudrateBT" (b/s)
BT.setTimeout(3); //sets the maximum milliseconds to wait for serial data
Serial.begin(Baudrate); //starts serial port with a baudrate by "BaudrateMP" (b/s)
}
void loop() {
//read software serial and send it via software serial xx to the device
while (BT.available() > 0) { //while serial is available, make...
BT_RX = BT.readString(); //store received string from serial to BT_RX
Serial.print(BT_RX); //send string from BT_RX to the serial pin
Serial.print('\r'); //send carriage return to the serial pin
}
}
Wenn ich nun aber auf meinem Mega in den seriellen Empfangssketch diesen Teil einfüge, dann empfängt er keine Daten mehr per Bluetooth. Oder es macht den Anschein, weil der serielle Monitor nichts mehr anzeigt. Ist hier etwas zu beachten, was beim UNO anders ist? Oder was könnte hier das Problem sein?
/**SETTINGS**/
const unsigned long Baudrate = 38400; //starts serial ports with a baudrate by 38400 b/s
const unsigned long BaudrateBT = 19200; //starts serial port for the Bluetooth module with a baudrate by 19200 b/s
const unsigned long BaudrateMP = 9600; //starts serial port wit ha baudrate by 9600 b/s
const unsigned long BaudrateTC = 2400; //starts serial port wit ha baudrate by 2400 b/s
const byte RSSIsensitivity = 40; //received signal strength from Xbee controls the range until signal is lost and the fail safe will stop the motors,
//the Xbee's standard edition will give a value between 0 and 92 and the pro version a value between 0 and 100
const byte DDstop = 90; //Dome drive, basic position joystick (stop position)
const byte FDLRstop = 90; //Foot drive left/right, basic position joystick (stop position)
const byte FDUDstop = 90; //Foot drive forward/backward, basic position joystick (stop position)
const byte MPanel = 28; //MPanel connected to pin D28
const byte TClight = 30; //TClight connected to pin D30
const byte XbeeRSSI = 10; //Xbee RSSI pin connected to pin D10
const byte Bluetooth = 11; //Bluetooth Module connected to pin D11
int DP1 = 0;
int DP2 = 0;
int DP3 = 0;
int DP4 = 0;
int DP5 = 0;
int DP6 = 0;
int HTLR = 0;
int HTUD = 0;
int HF = 0;
int HT = 0;
int HR = 0;
int BUT16 = 0;
int BUT19 = 0;
int BUT20 = 0;
int BUT21 = 0;
int BUT22 = 0;
int BUT23 = 0;
char var = 0; //reads the letter from serial
int rssi = 0; //variable for RSSI value from Xbee, the standard edition will give a value between 0 and 92 and the pro version a value between 0 and 100
String BT_RX; //reads the letter from Bluetooth serial
#include <SoftwareSerial.h> //adds library for software serial (Bluetooth module)
//create software serial ports
SoftwareSerial BT(Bluetooth, 20); //RX, TX pin
SoftwareSerial MP(12, MPanel); //RX, TX pin
SoftwareSerial TC(13, TClight); //RX, TX pin
void setup() {
Serial.begin(Baudrate); //starts serial port with a baudrate by "Baudrate" (b/s)
Serial1.begin(Baudrate); //starts serial port with a baudrate by "Baudrate" (b/s)
Serial2.begin(Baudrate); //starts serial port with a baudrate by "Baudrate" (b/s)
Serial3.begin(Baudrate); //starts serial port with a baudrate by "Baudrate" (b/s)
BT.begin(BaudrateBT); //starts serial port with a baudrate by "BaudrateBT" (b/s)
BT.setTimeout(3); //sets the maximum milliseconds to wait for serial data
MP.begin(BaudrateMP); //starts serial port with a baudrate by "BaudrateMP" (b/s)
TC.begin(BaudrateTC); //starts serial port with a baudrate by "BaudrateTC" (b/s)
//definition of input/output pins
pinMode(XbeeRSSI, INPUT_PULLUP); //pin XbeeRSSI is an input
}
void loop() {
unsigned long currentMillis = millis(); //count milliseconds
//RSSI value from the Xbee to detect when the signal is missing
rssi = pulseIn(XbeeRSSI, LOW, 200); //read the RSSI value from Xbee (the XBee’s RSSI PWM period is 200µs), the standard edition will give a value between 0 and 92 and the pro version a value between 0 and 100
if(rssi <= RSSIsensitivity){ //if RSSI value is less or equal to RSSIsensitivity (inside controllable range), then make...
//read serial and store it to designation or send it via serial xx to the next Arduino
while(Serial.available() > 0){ //while serial is available, make...
var = Serial.read(); //store first character from serial to var
switch(var){
case 'A' : DP1 = Serial.parseInt(); //if var is equal to A, then store second character from serial to DP1
break; //finish the command and return
case 'B' : DP2 = Serial.parseInt();
break;
case 'C' : DP3 = Serial.parseInt();
break;
case 'D' : DP4 = Serial.parseInt();
break;
case 'E' : DP5 = Serial.parseInt();
break;
case 'F' : DP6 = Serial.parseInt();
break;
case 'G' : Serial2.print('G'); //if var is equal to G, then send the character G to serial2
Serial2.println(Serial.parseInt()); //send second character from serial to serial2
Serial2.flush(); //waits for the transmission of outgoing serial2 data to complete
break;
case 'H' : Serial2.print('H');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'I' : Serial2.print('I');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'J' : Serial2.print('J');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'K' : Serial2.print('K');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'L' : Serial2.print('L');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'M' : HTLR = Serial.parseInt();
break;
case 'N' : HTUD = Serial.parseInt();
break;
case 'O' : Serial2.print('O');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'P' : Serial2.print('P');
Serial2.println(Serial.parseInt());
Serial2.flush();
break;
case 'Q' : Serial3.print('Q');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'R' : Serial3.print('R');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'S' : Serial3.print('S');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'T' : Serial3.print('T');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'U' : Serial3.print('U');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'V' : Serial3.print('V');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'W' : Serial3.print('W');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'X' : Serial1.print('X');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'Y' : Serial1.print('Y');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'Z' : Serial1.print('Z');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'a' : HF = Serial.parseInt();
break;
case 'b' : HT = Serial.parseInt();
break;
case 'c' : HR = Serial.parseInt();
break;
case 'd' : Serial1.print('d');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'e' : Serial1.print('e');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'f' : Serial1.print('f');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'g' : Serial1.print('g');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'h' : Serial3.print('h');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'i' : Serial1.print('i');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'j' : Serial1.print('j');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'k' : Serial1.print('k');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'l' : Serial3.print('l');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'm' : Serial1.print('m');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'n' : Serial1.print('n');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'o' : Serial1.print('o');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'p' : Serial3.print('p');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'q' : Serial1.print('q');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'r' : Serial1.print('r');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 's' : Serial1.print('s');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 't' : BUT16 = Serial.parseInt();
break;
case 'u' : Serial1.print('u');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'v' : Serial1.print('v');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case 'w' : BUT19 = Serial.parseInt();
break;
case 'x' : Serial3.print('x');
Serial3.println(Serial.parseInt());
Serial3.flush();
break;
case 'y' : BUT21 = Serial.parseInt();
break;
case 'z' : Serial1.print('z');
Serial1.println(Serial.parseInt());
Serial1.flush();
break;
case '@' : BUT22 = Serial.parseInt();
break;
case '$' : BUT23 = Serial.parseInt();
break;
}
}
}
else if(rssi > RSSIsensitivity){ //if RSSI value is greater than RSSIsensitivity (out of controllable range), then make...
Serial1.print('X'); //send the letter X (for dome drive) by serial1
Serial1.println(DDstop); //dome movement stopped (left < 90 < right, 80 slow left, 0 full throttle resp. 100 slow right, 180 full throttle)
Serial1.print('Y'); //send the letter Y (for foot drive left/right) by serial1
Serial1.println(FDLRstop); //travel stopped (right < 90 < left, 80 slow right, 0 full throttle resp. 100 slow left, 180 full throttle)
Serial1.print('Z'); //send the letter Z (for foot drive forward/backward) by serial1
Serial1.println(FDUDstop); //travel stopped (backwards < 90 < forwards, 80 slow backward, 0 full throttle resp. 100 slow forward, 180 full throttle)
}
//read software serial and send it via software serial xx to the device
while (BT.available() > 0) { //while serial is available, make...
BT_RX = BT.readString(); //store received string from serial to BT_RX
MP.print(BT_RX);
MP.print('\r');
TC.print(BT_RX);
TC.print('\r');
}
}
Grüsse
Stef