I am trying to send data over bluetooth and receive data in the app from 3 sensors. The sensors are not connected for this test because I am trying to fix the app and bluetooth at the moment.
I attached the app inventor blocks jpg for background knowledge, but I'm worried that the arduino code is wrong as I'm unsure if Serial.read() is sending all the data.
Nothing is showing up on the app and I'm not sure if the bluesmirf is sending data. Is there a way to check it is sending data correctly?
Sorry, I uploaded a jpg of the code for some reason!
I have Serial.read() printing from bluetooth.print right now
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(1000); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
delay(50);
}
void loop()
{
String string = "65,3.5,36.5,";
char myChar;
Serial.println(string);
while(Serial.available()){
myChar = Serial.read();
bluetooth.print(myChar);
}
delay(10000);
}
SoftwareSerial won't work at 115200 baud. 38400 is the best it can do I believe.
If you can't change the Bluetooth baud rate then maybe you could connect the Bluetooth device to pins 0 and 1 and use a USB-TTL cable connected to the SoftwareSerial pins to communicate with the PC at 9600 baud.
Or use an Ardduino Mega which has 3 spare HardwareSerial ports.
...R
PS. please post your program using the code button </> so it looks like this. See How to use the Forum. It makes it much easier for people to help you
I have the code at the beginning which changes the baud rate, changing it in command mode didn't help either.
I included the following in setup according to the hookup guide.
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(1000); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
Well I got it to receive data on my app with the following code, and I think I will try to follow suit with the sensors. Thanks Robin2 for your assistance while I learned how to use the forum too.
Although the guides use LEDs, the techniques can be used for other things.
To repeat what Robin has said; software serial at 115200 doesn't work. Based on my own experiments, with software serial I have only had 100% reliable communication at 9600. 38400 is usable if you don't mind the odd bit of missed data.
If speed is really important you need to use hardware serial but this introduces issues with uploading code and using the serial monitor. If you want more speed but don't need super fast have a look at AltSoftSerial. I have 100% reliable data at 38400 using AltSoftSerial. I think it will be good for faster baud rates but I haven't used it above 38400. I think it also depends on how much data you are sending and how frequently you are sending it.