Arduino Bluetooth Module HC-06 Error - bluetooth

I'm having trouble getting my bluetooth module for my Arduino Uno working. I have followed the instructions from this website:
http://www.instructables.com/id/Arduino-AND-Bluetooth-HC-05-Connecting-easily/?ALLSTEPS
So on my bluetooth settings it says COM7 Incoming so I put that in Putty and COM8 for outgoing so I put that in the arduino IDE. I get these errors
Sketch uses 3,016 bytes (9%) of program storage space. Maximum is 32,256 bytes.
Global variables use 226 bytes (11%) of dynamic memory, leaving 1,822 bytes for local variables. Maximum is 2,048 bytes.
avrdude: ser_open(): can't open device "\\.\COM8": Access is denied.
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x31
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x31
Thanks

You are getting that "programmer is not responding" message because some other process is using the COM8 port. You can't program the Arduino through that port if some other program (like a serial terminal) is using the port, so exit the program, program the Arduino, and then open up the program again.

First, are you trying to download your program via bluetooth, because if you are, don't, it won't work. If you are trying to upload the program using a usb cable make sure you are in that correct com port(NOT THE BLUETOOTH COM PORT). When uploading the program, keep the power and ground connected so it is still activated, but you need to disconnect the rx and tx connections(the two digital port connections). This is a common problem with the bluetooth modules because for some reason, when rx and tx are connected it interferes with the programs ability to upload.

This problem, or the similar problem, "avrdude: stk500_recv(): programmer is not responding", is easily solved.
These problems occur if the Arduino is already wired to a breadboard with a HC-06 Bluetooth module.
First, unplug the Arduino from the power source and then remove the connections from the Arduino to the breadboard. Power-up the Arduino and check the serial comm. port is correct. Now uploading a sketch to the Arduino will occur without issues. Finally, unplug the power to the Arduino and then rewire the Arduino to the breadboard.
When the Bluetooth module is attached to the Arduino, the module prevents the Arduino's serial port from connecting to the USB from uploading sketches.

Related

BlueZ modify LE CONNECT_REQ Timeout

I'm trying to connect to a BTLE device from Linux from C++ with BlueZ.
Connecting to most devices works fine, but there is a special device which times out with 90% probability. From a standard Android smartphone the connection to this particular device works as intended.
For #Emil's advice in my other question (thanks!) I've setup a Link Layer sniffer tool for further investigation.
During the sniff period I tried connecting to the device(Destination) from both device(Good) and device(Bad).
Device(Good) is working perfectly - it connected
Device(Bad) is not working - timed out
Now I have a Link Layer data of both device connection trials and there is one significant difference between their trials:
Device(Good)'s LL Data for its CONNECT_REQ uses 500 for Timeout value (which is 625ms) while Device(Bad)'s LL Data in CONNECT_REQ uses 42 (which is 52.5ms).
I think Device(Destination)'s response is normally (mostly) arriving between those two, ie after 52.5ms and below 625ms, but sometimes it arrives in less than 52.5ms, and then also BlueZ can connect to it finally.
Is there any possibility to change this Timeout property for CONNECT_REQ in BlueZ? Maybe with setsockopt by any chance?
Or this is something hardcoded into kernel, even for bluetooth adapters attached to USB?

Read data from bluetooth - Android, Raspberry Pi Zero, Bluetooth

I have an application in Android which connects with my Raspberry Pi Zero via Bluetooth.
I start connection in my phone and I only confirm a pairing in RPI.
I send a data from my Android to RPi and I know, this data is received in RPi because when I use:
sudo hcidump -a hci0
I see this data
But I don't have idea how can I write a programm (in python for example) which will read this data and run of led or something else with GPIO.
I tried pybluez.service but I have only:
Waiting for connection on channel 2
I tried
sudo rfcomm watch hci0
but I have:
"Can't bind RFCOMM socket : Address already in use
And others,I tried the first 5-10 tutorials in google or youtube and nothing.
The Bluetooth error "Can't bind RFCOMM socket: Address already in use": means that the bind() function used by the command producing the error (in your case, rfcomm) failed because there is another local socket with the same number (in your case, referred to channel 2) already bound by a local application.
A way to solve this problem is to find the local application in your system which is currently binding that socket (maybe another instance of rfcomm on the same channel). Close the socket in that application, or simply terminate it.

Connecting to BT LE device using org.bluez.Adapter.CreateDevice fails with org.bluez.Error.Failed: Operation canceled Error

I'm trying to set up a connection to a Bluetooth 4.0 LE device on Linux using the BlueZ 4.X DBus interface.
To test this I use the following command:
dbus-send --system --dest=org.bluez --print-reply /org/bluez/<PID of bluetoothd>/hci0 org.bluez.Adapter.CreateDevice string:<MAC of BT device>
This command seems to work most times, giving a result like:
method return sender=:1.238 -> dest=:1.262 reply_serial=2
object path "/org/bluez/9652/hci1/dev_BC_6A_29_26_C2_1C"
and enabling me to interact with the device DBus object.
However, starting from yesterday, this seems to fail very frequently returning the following error:
Error org.bluez.Error.Failed: Operation canceled
When debugging the bluetooth daemon, (using bluetoothd -n -d) I notice the following things when executing the method call:
bluetoothd[340]: src/adapter.c:create_device() BC:6A:29:26:C2:1C
bluetoothd[340]: src/adapter.c:adapter_create_device() BC:6A:29:26:C2:1C
bluetoothd[340]: src/device.c:device_create() Creating device /org/bluez/340/hci0/dev_BC_6A_29_26_C2_1C
bluetoothd[340]: src/device.c:btd_device_ref() 0xb7ad8: ref=1
bluetoothd[340]: src/device.c:device_set_temporary() temporary 1
bluetoothd[340]: src/device.c:btd_device_ref() 0xb7ad8: ref=2
bluetoothd[340]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[340]: plugins/mgmtops.c:mgmt_event() Received 14 bytes from management socket
bluetoothd[340]: plugins/mgmtops.c:mgmt_connect_failed() hci0 BC:6A:29:26:C2:1C status 4
bluetoothd[340]: src/event.c:btd_event_conn_failed() status 0x04
bluetoothd[340]: src/device.c:device_remove() Removing device /org/bluez/340/hci0/dev_BC_6A_29_26_C2_1C
bluetoothd[340]: src/device.c:device_set_temporary() temporary 1
bluetoothd[340]: src/device.c:btd_device_unref() 0xb7ad8: ref=1
bluetoothd[340]: src/device.c:btd_device_unref() 0xb7ad8: ref=0
bluetoothd[340]: src/device.c:device_free() 0xb7ad8
As far as I can see, my Bluetooth dongle sends me an error event (status 4) when I try to connect to the device.
However, when I use hcitool ot gatttool to connect to the device, everything works perfectly.
I found that this happens mostly after I try to connect to the device using a different program (i.e cinnamon-settings), and cancel the connection prematurely. I also noticed this with other programs like bluetooth-properties on Angstrom.
My guess is that Bluez sends the wrong HCI commands to my bluetooth dongle in certain conditions. I think this is because the gui programs try to pair with the device instead of just connecting to it, which may cause BlueZ to think my device is a Bluetooth 2.0 device.
Thus far I seemed to be able to resolve this problem by connecting to my BT device using a gui application, waiting till it fails, and restarting my computer. However, the problem seems to reoccur occasionally, making this very painful.
I have seen this problem on systems running both BlueZ version 4.99 and 4.101.
Does anyone know how I can solve this correctly?
It seems like my predictions where more or less correct. After many hours of debugging the Bluetooth daemon I discovered that connecting to BT LE devices without a preliminary scan causes the daemon to try to connect to the device as a BR/EDR device. This is because the daemon's "internal cache" is filled with the EIR information at the time the device is discovered. If this information is not available when connecting to a LE device the CreateDevice method will fail.
A simple solution is to always make sure to discover devices before connecting to them.
The BlueZ 5 API introduction and porting guide also describes this problem, and how it is solved in BlueZ 5:
Bluetooth Low Energy essentially extended Bluetooth addresses with one extra bit, requiring one to always know whether an address is “random” or “public”. This caused issues with the BlueZ 4 API where the address was given to BlueZ in the CreateDevice and CreatePairedDevice calls. Since the parameter didn’t contain any of this extra random/public information bluetoothd had to maintain an internal cache to look up the necessary info. Another complication to the matter is that the BlueZ D-Bus API doesn’t differentiate between traditional BR/EDR devices and LE devices so there are essentially three possible address types: BR/EDR, LE public and LE random.

Initiate connection from Arduino to remote device

I am trying to achieve that my arduino-built device connects automatically to a device after it is switched on. The board is an Arduino Mini Pro and the bluetooth module is the Bluetooth Mate Silver (RN42). The devices are already paired, the bluetooth module is in slave mode, the remote device (in this case a normal laptop) is discoverable. I am using the SoftwareSerial library provided with the Arduino software.
Here is my setup:
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
// bluetooth
// set baud rate to 9600
bluetooth.begin(9600);
// start command mode
bluetooth.print("$$$");
// reply delay
delay(100);
// set to slave mode
bluetooth.println("SM,0");
// reply delay
delay(100);
// set device pin to 0403
bluetooth.println("SP,0403");
// reply delay
delay(100);
// connect to pixelsense
bluetooth.println("C," + remoteMAC); // remoteMAC is a string with the mac address
// reply delay
delay(2500);
// leave command mode
bluetooth.println("---");
// reply delay
delay(100);
}
I read the command set of the RN42 and I think the commands are correct. I can connect to Arduino via bluetooth but the other direction isn't working. I also tried using the master mode or storing the remote mac in the flash instead of using a string. From the documentation it should be possible to initiate connections from the RN42, but I haven't quite found out how this works in details. Can anyone provide any help to solve my issue?
EDIT: The device does not seem to enter command mode at all. At least the flash lights don't indicate that. Is there anything wrong with the commands so that the command mode cannot be accessed?
After nearly a week, I came across a solution. Actually it seems to be important that there is any program that accepts a bluetooth connection. I tried it the whole time with the Windows 7 Bluetooth dialog menu entry "Receive a file" but that did not work. So I used a third party program that listens for incoming connections and that actually worked. Basically everything I did was fine except for the missing connection listener.
Sometimes if I upload new code to the Arduino there is the problem that the connection cannot be established. This can be solved by removing and readding the bluetooth device.
The code for the RN42 Bluetooth Client above works. The library SoftwareSerial provided with the Arduino software is used.
I think you may need to put some delay after bluetooth.begin(9600), to let set its baudrate and then issue print command.
You can enter into the command mode only in 60s after the module is powered on. You can see if the timer is still counting using the status LED(if it blink 2 per second). Sorry for my bad english.
On startup the RN-42 needs 500ms before it can enter command mode try 'delay(500);' before 'bluetooth.begin(115200);' and that should get you there. Also CTS should be tied low
as can be seen on page 45 of the document found at the link below.
https://cdn.sparkfun.com/assets/1/e/e/5/d/5217b297757b7fd3748b4567.pdf
PG 45
"3.3 INTERFACING TO A MICROPROCESSOR
Roving Networks Bluetooth devices can connect to 3.3-V (only) microprocessors using
the UART interface. When interfacing with a microprocessor, use the following guidelines:
• The Bluetooth device power, ground, RX, and TX signals must be connected and
CTS should be held low or tied to RTS.
• The Bluetooth device can go into command mode 500 ms after booting.
• The microprocessor should send $$$ with no carriage return or line feed to enter
command mode.
3.3.0.1 HOW DO I KNOW THE MODULE IS READY FOR COMMAND MODE?
500 ms after rebooting, the module is ready for command mode. You send $$$with no
carriage return.
3.3.0.2 WHICH HARD SIGNALS SHOULD I CONNECT?
You should connect power, ground, RX, and TX. CTS should be low or you can connect
or tie it to RTS."

Rn42 Bluetooth Module does not respond

I want to send some commands to my RN42 Bluetooth Module over the serial port using hterm. But i does not respond. I can connect to the bluetooth modul and the status LED blinks right.
I tried to send $$$ to change to command mode (modul should respond with cmd but does nothing) and 0x00 to disconnect.
Do you guys know what could be wrong?
A couple things that I have run into that you could try:
Ensure that the baud rate of hterm is set to the default 115k
Depending on the firmware version of the RN42 you may have to enter command mode within a one minute time frame. Try power cycling the module and sending the $$$ as soon as possible

Resources