I'm trying to send data from my arduino sensors to my Mac as serial data through bluetooth. The data sends properly when I send it through a USB connection, but not when I connect to my computer with a HC-06 bluetooth module. My computer connects successfully to the arduino over bluetooth, but no data is sent. How do I configure my bluetooth connection so that data from my arduino sends data to my Mac?
navinbalaji:
I'm trying to send data from my arduino sensors to my Mac as serial data through bluetooth. The data sends properly when I send it through a USB connection, but not when I connect to my computer with a HC-06 bluetooth module. My computer connects successfully to the arduino over bluetooth, but no data is sent. How do I configure my bluetooth connection so that data from my arduino sends data to my Mac?
Serial.write(data);
Done (assuming the bauds match).
navinbalaji:
but no data is sent.
It probably is, your successful use of cable strongly implies that, but is not being received by Bluetooth. Further, since you can communicate via USB cable OK, there is nothing essentially wrong with the code, which is normallySerial.print(data);
Assuming
- that you really mean a Mac and not an iSomething, and
- the baud rate really does match with that of bluetooth
the problem may well be wiring. For starters, have you got
Tx bluetooth > Rx Arduino and
Rx bluetoioth > Tx Arduino?
Note also that
My computer connects successfully to the arduino over bluetooth
is never correct. Your computer only connects to bluetooth, and bluetooth connects to Arduino - i.e. Bluetooth is a go-between. This means you have to ensure two connections are kosher
- Computer <> Bluetooth - wireless
- Arduino <> Bluetooth - wires
It would appear that the first is, so look at the second.
I've triple and quadruple checked my connections, had a friend check, and they are correct. The weird thing is that when I write and read all in Matlab over bluetooth, it works fine. I'm just not reading the serial data when I write using the Arduino IDE.
By process of elimination you can troubleshoot your own problems. Here are two options:
-
Connect Bluetooth module to FTDI / usb serial port and communicate through that device to another device: This will rule out of the Bluetooth module is functioning correctly (or firewire, or whatever proprietary ports that only a Macintosh is limited to).
-
Attempt to connect that module and Arduino to a different Bluetooth source besides the Mac: This will rule out the Macintosh from issues. Most every mobile phone has Bluetooth, go to the app store and download Bluetooth serial console.
Should I try using SoftwareSerial?
If your using an Arduino Nano, Uno (I wouldn't know since you haven't specified) - you probably have to use softwareSerial in order to seperate your debug messages from the Bluetooth data. Arduino Mega 2560 have 3 hardware serial uart ports to pick from.
Then.... You have to play a fun game with the pins on the HC-05/06 to toggle it in and out of command mode, which the unit needs a power-cycle in order to switch between modes. It took me about a MONTH (at least) to figure that out the first time I tried it. There's like 3 pins if I remember right - one of them triggers the board into command mode, another one is a connection on/off signal, and I can't remember if / what the 3rd one did.
P.S. - BY the way... There is a hc-05 and hc-06. One is a master and one is a slave. The master can also be configured as a slave, but the slave can not be configured as a master. I had been under the impression I could just attach the module to another device, but it doesn't work like that. You have to bind a device TO the module, it won't just auto-connect itself (real bummer, I was planning to have the device auto-sense when my phone was near and automatically do stuff, but that whole idea failed)....
DocStein99:
Most every mobile phone has Bluetooth,
But only Android blueteeth talk to an HC-06
Nick_Pyner:
But only Android blueteeth talk to an HC-06
Whoopse. No, I don't know what the iPhones do with their bluetooth devices, but if it's anything like the way they handle the rest of the hardware, then you'll be in for a nice fun time learning how to write all your own applications from scratch to do each and every little function, that the Androids do by default for free.
Indeed. This is because IOS only use Bluetooth4, while The HC-05 is bluetooth 3, or perhaps 2.
IF
You already have an Isomething
You don't mind Apple Corp holding you by the short and curlies and
You aren't too serious about what you are doing
You might find the HM-10, which is BT4, a quite satisfactory replacement, and BT4 even brings some advantages of its own.
However, if you can afford an iPhone, you can surely afford to get a cheap Android as well, and use that to do the real work.
navinbalaji:
I've triple and quadruple checked my connections, had a friend check, and they are correct. The weird thing is that when I write and read all in Matlab over bluetooth, it works fine. I'm just not reading the serial data when I write using the Arduino IDE.
This makes no sense at all, particularly the last sentence. It might be time to post your code and a wiring diagram.
Since you can send via USB, your code should be kosher - provided you are using hardware serial.
Nick: I have the HM 10 modules, also a real android phone (since I like to do things like swap memory tf cards, sim chips, batteries - or find an mp3 file in a directory structure that ISNT scrambled on purpose to prevent me from copying my own music)......
Anyway - whay devices do you use to connect.hm-10, are you connecting to a phone? I had real trouble finding working example projects on the android. I did get the old school hc 05 to work, but hm 10 failed me.
I'm afraid I have no experience with HM-10. I have a couple but have never gotten round to using them as I find the HC-05/6 just fine. I had a casual go at HM-10 but no joy. I understand they work the same as HC-05. Other users round here are fine with them. I use Bluetooth Graphics Terminal, usually on a cheapo Huawei.
Yes, from what I read before I bought hm 10 (after working with hc 05) was that they "just go right in". Its NOT the case, the things make every effort to avoid being setup in SPP mode, and want me to read a dictionary-size book full of device definitions to communicate as a sensor. If I could find ANYONE who claimed actually got them to work, I could only get a few lines explaining to me they had a hard time with them and just use them to turn lights on or off (which is far too much work for a basic feature like that).
The whole protocol wants me to register something, and handle data specific way, only sending so many bytes in each packet that is only sent X number of times per second, accoesing to device class definitition. The HM 10 was the biggest waste of my effort and time, next to being forced to learn Macintosh operating system at my job, so that I could fix those fake computers when they broke - since the customers themselves actually didnt know how to use them either.
DocStein99:
Yes, from what I read before I bought hm 10 (after working with hc 05) was that they "just go right in". Its NOT the case, the things make every effort to avoid being setup in SPP mode, and want me to read a dictionary-size book full of device definitions to communicate as a sensor.
I think that's right, and I misunderstood. I just haven't had the motivation to pursue this.
If I could find ANYONE who claimed actually got them to work
There are quite a few people on this forum who have done so these days. They didn't wax lyrical about how hard it was, so I assumed it was straightforward, and I had just missed something simple.
so that I could fix those fake computers when they broke - since the customers themselves actually didnt know how to use them either.
They are the sort of people macintoshes are made for.