Hi all, i'm struggling to add Bluetooth into the main code if anyone could help me, i would be gratefully appreciated. Both codes are attached bellow.
__help_pumptech.ino (15.2 KB)
BT_connection_final.ino (494 Bytes)
Hi all, i'm struggling to add Bluetooth into the main code if anyone could help me, i would be gratefully appreciated. Both codes are attached bellow.
__help_pumptech.ino (15.2 KB)
BT_connection_final.ino (494 Bytes)
In what way is the Bluetooth code not working?
It depends on exactly what you want to do, and that is currently unclear.
IF the "main code" is working
AND uses serial monitor to operate and/or report,
BUT you want to use Bluetooth INSTEAD,
NO change of code is required, other than ensuring the baud rate is correct.
All you need do is connect Bluetooth to hardware serial and go. Bluetooth is just serial without wires
IF you want to something with Bluetooth, IN ADDITION to what you re already doing, that will require extra programming.
IF you want to something with Bluetooth, IN ADDITION to what you re already doing, that will require extra programming.
Your base code does not use the String class and is well written to be non blocking.
You are headed in the wrong direction with this
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 9); // RX, TX
String readString;
void setup() {
Serial.begin(9600);
BT.begin(9600);
}
void loop() {
while (BT.available()) {
delay(50);
char c = BT.read();
readString += c;
}
if (readString.length() > 0) {
Serial.println(readString);
if (readString == "p3") {
Serial.println(readString);
}
if (readString == "button_2") {
}
}
readString = "";
}
Your base code does not use the String class and is well written to be non blocking.
Blush
I thought that I had turned the OP off using Strings a long while ago so I don't know why he has turned back to them.
As has been said, all that needs to happen is that the serial input be taken from Bluetooth instead of Serial.
You are making a meal out of something that is really quite simple
#include the SoftwareSerial library and create an instance of it using pins of your choice. Connect the Bluetooth device to the pins remembering to cross connect Tx and Rx
Now, supposing that the instance of SoftwareSerial is named BT, put the BT.begin() in setup() using the appropriate baud rate (9600 baud unless you changed it). Now the program will accept serial data from the Bluetooth device on the pins that you specified.
The only other thing to do is to change the available() and read() functions in the input routine to use the BT object instead of the Serial object
Job done