Hi there. I am having a bit of trouble with a bluetooth module which i purchased and just wanted to ask for advice on whether i am doing something stupid or whether the module might be broken. I have created the following arduino sketch which prints via serial and also toggles the inbuilt led. the sketch works over regular serial but when i connect via the bluetooth module i am able to toggle the led but the serial monitor wont display the print outs. i have connected to the module via a serial to ttl converter and issues AT commands and it is able to receive them and print to the monitor which is interesting. If anyone is able to see anything wrong with my approach i would be very grateful for a reply. thanks.
#define ledPin 13
bool toggle = false;
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop() {
if (Serial.available()){
char data = Serial.read();
if (data == 'a'){
toggle = !toggle;
digitalWrite(ledPin,toggle);
}
}
static unsigned long timer = millis();
if (millis() - timer > 1000){
timer = millis();
Serial.println("hi");
}
}
It may be that you are not able to use the hardware serial port for comms with the IDE monitor and the bluetooth in the same sketch. It's one or the other , but not both.
Try using software serial and connect the bluetooth to two digital pins other than 0 and 1.
What do you mean by "the sketch works over regular serial"? What is regular serial?
It may be that you are not able to use the hardware serial port for comms with the IDE monitor and the bluetooth in the same sketch. It's one or the other , but not both.
Try using software serial and connect the bluetooth to two digital pins other than 0 and 1.
What do you mean by "the sketch works over regular serial"? What is regular serial?
John.
hi, I have also tried testing one or the other and that doesnt work either. by 'regular serial' i mean having the arduino plugged into my computer using a serial to ttl converter, via a usb cable.
jpom:
Are the two modules definitely connected to the same GND?
How re you sending the command "a" to the bluetooth? From an Android phone?
the arduino and bluetooth module are both connected to the same ground (battery) as per the schematic. I'm sending the 'a' from the serial monitor in the arduino IDE. the bluetooth serial port shows up just as the wired ones do in the IDE. the flashing light on the modules goes to solid just as it should signifying that the connection has been made and as i say, i can send data from computer to arduino fine but its not working the other way round. I'm thinking that the module must be faulty but it is strange that i can send AT commands and receive their output...
"the bluetooth serial port shows up just as the wired ones do in the IDE." I don't know what that means.
Bluetooth is a device for communicating wirelessly with another device that has bluetooth capability. You seem to be trying to send data from the Arduino to the bluetooth and see the result back in the Arduino. I don't know.
I've been using the HC-05 with Nano and UNO and even connected directly to a GPS module without any Arduino involved. I connect the bluetooth to an Android phone or to the PC. I've used bluetooth terminal programs on both to read the data. All works well. I've written Android apps to control the Arduino via bluetooth.
It's not likely your bluetooth is faulty. I'm thinking you've made something that will not work, but I don't really understand what is is you've made.
Try putting aside the IDE monitor. Install the bluetooth terminal program for PC from Microsoft store. Then pair your PC with the bluetooth and use it for what it is designed for -- wireless communication.
I simply want to communicate with my arduino from my computer over bluetooth. im not sure where the confusion is coming from. i am using the arduino IDE because it has a built in serial monitor.
If you want to "simply communicate with your Arduino from your computer over Bluetooth" you do not use the serial monitor built in to the IDE, so perhaps that is where the confusion is coming from. Use a proper terminal programme like RealTerm, and connect it to the COM port on which PCs Bluetooth is residing.
Nick_Pyner:
If you want to "simply communicate with your Arduino from your computer over Bluetooth" you do not use the serial monitor built in to the IDE, so perhaps that is where the confusion is coming from. Use a proper terminal programme like RealTerm, and connect it to the COM port on which PCs Bluetooth is residing.
ok i will look into it. whats wrong with the serial monitor?
For starters, it's mis-named, it is really just a debugging facility. Arduino is connected to the IDE, of which the monitor is a part, via the cable through a particular COM port. Bluetooth is connected to the PC via a different COM port - which has nothing to do with Arduino. Your device manager should show the port. The port number may be very high. This is normal.
Nick_Pyner:
For starters, it's mis-named, it is really just a debugging facility. Arduino is connected to the IDE, of which the monitor is a part, via the cable through a particular COM port. Bluetooth is connected to the PC via a different COM port - which has nothing to do with Arduino. Your device manager should show the port. The port number may be very high. This is normal.
...but the bluetooth module shows up as a serial port in the arduino IDE once it has been paired.
I think that's nonsense or, at best, irrelevant. Arduino simply talks to its serial port and has no idea what's connected to it - if anything. Further, pairing has nothing to do with Arduino, it is a matter between Bluetooth and PC. In the pairing operation, Arduino serves no other purpose than to provide power, and that could actully be provided by something else. Same applies to connection. PC is no more aware of Arduino's presence as Arduino is aware of PC's COM port.
Nick_Pyner:
If you want to "simply communicate with your Arduino from your computer over Bluetooth" you do not use the serial monitor built in to the IDE, so perhaps that is where the confusion is coming from. Use a proper terminal programme like RealTerm, and connect it to the COM port on which PCs Bluetooth is residing.
There's no real reason not to use the Serial Monitor if OP just want's to manually communicate with the bluetooth module. It's already installed, easy to use, and works. I've used to to connect to my own bluetooth devices before without problem.
The only wrinkle is you have to make sure the COM port is correctly set. You can even open two instances of the Arduino IDE - one for uploading on one COM port and one for talking with the BT device on the other COM port to make things easier.
That being said, it does make a little more sense to use a different terminal emulator like Putty (or whatnot), but there isn't anything inherently wrong with doing it through the Arduino Serial Monitor.
screenshot of the serial ports menu in the arduino IDE - as you may be able to tell i am on a mac.
all of the listings are previsously paired bluetooth devices
Ah well, there you go, it's a macintosh. I have no idea how it would identify a Bluetooth module connected to an Arduino, which, being an Arduino Forum, is what I thought this was about. Perhaps it doesn't, and those Blueteeth are/were connected to mac's serial port(s), or it is simply a list of Blueteeth that have been paired with mac's built-in Bluetooth in the past and has nothing to do with with being connected to an Arduino.
The only thing of faint interest here is that it doesn't seem to tell you which serial port Arduino is using, which I would have thought was the only thing you really need to know, and is the only thing the port list on Windows tells you.
I don't think I have the latest IDE but, as far as I am aware, the only way the serial monitor on a windows PC can communicate with Arduino is via cable through a USB port.
Nick_Pyner:
Ah well, there you go, it's a macintosh. I have no idea how it would identify a Bluetooth module connected to an Arduino, which, being an Arduino Forum, is what I thought this was about. Perhaps it doesn't, and those Blueteeth are/were connected to mac's serial port(s), or it is simply a list of Blueteeth that have been paired with mac's built-in Bluetooth in the past and has nothing to do with with being connected to an Arduino.
The only thing of faint interest here is that it doesn't seem to tell you which serial port Arduino is using, which I would have thought was the only thing you really need to know, and is the only thing the port list on Windows tells you.
I don't think I have the latest IDE but, as far as I am aware, the only way the serial monitor on a windows PC can communicate with Arduino is via cable through a USB port.
the arduino IDE doesnt know that there is an arduino connected to the serial port.it just lists serial devices. the bluetooth ones are always there unlike the wired ones which appear when you plu them in. i am only using the arduino IDE because it has a built in serial monitor. the bluetooth module is indeed connected to an arduino in this instance via their respective TX RX ports. i am able to send data to the arduino via the serial monitor but not receive it. it is this which is confusing me.
gonadgranny:
i am able to send data to the arduino via the serial monitor
Are you able to do this with the USB cable disconnected? because here is a wild guess (and nothing more):... you are able to communicate with Arduino using the serial monitor because you are not using Bluetooth, you are doing it via cable. If this is indeed the case, read reply #8 again. I imagine there is a mac equivalent of RealTerm, which is just a freebie standard terminal progamme. If the cable is disconnected, I don't know what is going on - but I would like to know if that applies to Windows as well. We all learn, eventually, and this could be what the other guy was talking about.