Creating a bluetooth controller

I have a robot created that I can control with my Android phone via Bluetooth. I am wanting to create a controller that can connect to the bot via blue tooth and use that rather than my phone. The only problem is, I have no idea how to have the Arduino controller be a master Bluetooth and have it connect to a slave Bluetooth without the help of an OS.

Anyone have ideas or somewhere they can point me too?

I have a robot created that I can control with my Android phone via Bluetooth

This is a bit confusing, if you created a robot that already work with your phone over bluetooth, then how are you having trouble creating a bluetooth controller? Did you create the code for your phone or did you just copy and paste in someone elses without actually understanding it? I would think the controller would be extremely easy to make considering you should already know what to send to the robot to get it to work. Are you looking to have the robot control the controller? No, so I would think you would want the bluetooth in the robot, to be the slave and the bluetooth in the controller be the master.

What seems to be giving you trouble that you can't figure out yourself?

The phone works fine and I created all the code. The problem is if I were to create an Arduino powered controller with, a joy stick, some buttons, accelerometer and Bluetooth. I have no idea how to pair the controller to the bot as the controller will not have an OS, like my phone does. The problem isn't the code, its setting Bluetooth slave/master relationships. I know the controller needs to be the Master, but how do I pair the Slave(the bot) to the controller without and OS?

What bluetooth modules are you using, most HC-05/06 modules pair automatically when they are within a 30 ft range of each other.

I only have 1 module for the bot right now and I am unsure of the model(at work can't check) though i belive its an HC-06. I haven't even gotten started on the controller, I was just getting the last pieces of information before starting. I will check out those models and see if that can work. Thanks

As I understand it, you simply want to use another Arduino as a controller i.e. Arduino <> Arduino communication, rather than the phone. I’m not surprised you have no idea how to do it and, while Hazard may be inclined to elaborate, I don’t think the HC-0x are a good place to start.

The only example of Arduino <> Arduino communication I have ever found is here.

This has auto-connect and the full symphony but note particularly that he is not using HC-0x, not even as the slave. Maybe that was just his inclination and I can’t see why an HC-06 cannot be used as the slave. He uses BlueSmirf

I’m speculating that there are varying degrees of master, and while the HC-05 can be configured as a master, it is short of the commands to be sufficiently masterful in order to run an HC-06. It can probably be used as master with gamepads etc., but I don’t indulge in that and I have never seen a situation where the HC-05 is employed as master. When I asked here before about Arduino <> Arduino communication with HC-05, all I got was deafening silence, and I think that said it all.

Stick with the phone! They seem ideal for the purpose, and probably cheaper than Arduino+BlueSmirf

I'm not surprised you have no idea how to do it and, while Hazard may be inclined to elaborate, I don't think the HC-0x are a good place to start.

It's a simple serial connection, why is that hard to understand? No, there is no actually library dedicated to bluetooth, but there really doesn't need to be. If you can send a single character to the arduino with the serial monitor, then it should not be so difficult to remove the connection and make it wireless.

I'll admit it is tough to understand how the bluetooth modules need to be set up, but once you get past that, it's a breeze. I myself had a hard time getting my modules to work and it wasn't until much trial and error that I found out that most modules can only pair to their counterpart if they are same versions. I also found out that a master wont connect to the bluetooth in a computer or laptop nor will it connect to another master. You can have Master to slave and slave to slave but that's it.

The module AgentNoise has, must be a slave otherwise it would not have connect to his phone, unless his phone knows to change the state of the module from master to slave, but I doubt it.

Another thing to know is most bluetooth modules, both masters and slaves, are usually set to 9600 by default. So if or when they do auto connect, you can run a simple sketch on both to send and receive a single character between the two. Maybe have one blink the LED on the others board.

HazardsMind:

I’m not surprised you have no idea how to do it and, while Hazard may be inclined to elaborate, I don’t think the HC-0x are a good place to start.

It’s a simple serial connection, why is that hard to understand?

I also found out that a master wont connect to the bluetooth in a computer or laptop nor will it connect to another master. You can have Master to slave and slave to slave but that’s it.

The module AgentNoise has, must be a slave otherwise it would not have connect to his phone, unless his phone knows to change the state of the module from master to slave, but I doubt it.

What Agent said was

I have no idea how to have the Arduino controller be a master Bluetooth and have it connect to a slave Bluetooth without the help of an OS.

This is not a simple serial question and it is hard to understand. One thing for sure, is that it is a hell of along way from

If you can send a single character to the arduino with the serial monitor, then it should not be so difficult to remove the connection and make it wireless.

It is not simple if only because a connection to the serial monitor takes no extra progarmming, but this exercise will. Indeed, rather lot, I imagine, and probably none of which I know anything about.

What you said was

most HC-05/06 modules pair automatically when they are within a 30 ft range of each other.

I have never seen that, I don’t know anybody else who has either, and I would like to know how you do that. I’m not saying it doesn’t happen, yet, but I believe others do. I’m saying that that is what I want to do and have not been able to find out how. It could be that there is a great swirling sea of Arduino <> Arduino bluetooth communication somewhere, but it is somewhere else. Needless to say, I’m prepared to set up my HC-05 as a master on the strength of good evidence., but I admit it is a low-priority item.

The module Agent has is indeed a slave, an HC-06, but I don’t think that matters. Phones are masters and have no trouble communicating with each other, or with laptops for that matter, without any need to change their configuration. The HC-05 is a slave by default anyway.

So what have you got?

Yeah, as far as I can tell the HC-05 and HC06 do not automatically pair. The only problem I have with is using my phone is that when I want to switch between autonomous control and motion control its basically impossible because none of the apps I can find will let me turn the accelerometer data off and be able to send alphanumeric characters too. So, I figured I would make a control because I don't know anything about android development. Maybe I can figure out how to get it to work with Arduino to Arduino communication

I have four bluetooth modules, two are HC-05, and the other 06(which ones were which, I dont remember), which I took the time to test and see how they work and how far they can go before cutting out.

The far wall of my bedroom to my front door is 37.2ft, in which I wanted to know how far I could be and still have them pair up. I found out that they can still find each other, pair up at 34 - 36 ft, but given my house is mesh lined, I thought the number would vary. Turns out, not by much. I tested the paring range again outside and roughly at 40ft they could just barely pair up. (They would pair up for a few seconds then lose connection)

As I said, yes they can be difficult to set up if you’re doing it for the first time, but once you get a hang of it, its simple plug and play. At least with the modules I have. They are all currently set to the default setting, 9600, no parity bit…etc. Yet, I can throw together a simple Serial sketch to send one char from one arduino to the other and see it on the serial monitor.

A V1.2 will not pair with a V1.02 nor to a V1.05, but two V1.05 will. So technically I only have one working pair, but I can still use the other slave, (V1.2) to debug to my computer if needed.

These are the only modules I own, so the same can’t be said with confidence for the blue, Silver or GoldSmirf. Their protocol may be completely different or they could be the same, but if I don’t have them, then I can’t test them.

I tried to resize the image as best I could without losing quality.

Added: the two on the left do automaticly pair to one another, but the other two, since they are not the same version, I can’t be certain. I do know that all four need to be manually paired when connecting to my laptop.

AgentNoise: the HC-05 and HC06 do not automatically pair.

I won't ask where I might have heard that before. Maybe Hazard is onto something, but more to the point is the Android. It seems that your real problem is getting a command to robot to do what I imagine is a simple task - switch off something - and I'm surprised if it's hard. I know nothing about it, but one of the biggest threads on the forum is about bluetooth Android joysticks. It goes on for pages, so surely there is something in there about task commands as well?

I'm not motivated to follow Cantin. I think, if you are going to spend the money, it might be better to use NRF24, but you might get value from him.

Well with more research you can get them to pair automatically but it doesn't seem to be the default settings. Hc-3/HC-05 is the recommended pairing.

As for the phone, the problem is, that when I have my robot in autonomous it mode it can't pick up the command to switch because the buffer is constantly over written by the accelerometer data, when ever the program gets a delay,because I can't get it to stop sending the accelerometer data. So, if I push 'm' to get it back to motion control it never picks it up because the buffer was over written in 250ms delay it took for the bot to turn. There is no way around this without a custom App, or maybe a customer delay function, I'm working on that too.

Could you post the robots code, I'm curious as to what it looks like.

AgentNoise: when I have my robot in autonomous it mode it can't pick up the command to switch because the buffer is constantly over written by the accelerometer data, when ever the program gets a delay,because I can't get it to stop sending the accelerometer data.

Dr Frankenstein does spring to mind here. This is all out of my field, being a humble data-logger myself, but I will be interested to hear how this all pans out........

See attached for the code.

An over view of whats happening; When you switch it on it listens for an ‘m’ or ‘a’ to choose autonomous or motion control . If you push m it calls the motion function, now you can control it by tilting your phone(Neat!). If you push a it enters autonomous mode by calling the autolistener function. You can enter autonomous at start up or when in motion control by laying the phone flat and pushing a. That all works just fine, but when in autonomous mode you can’t switch to motion because when the bot hits a delay the buffer still gets over written with accelerometer data since I can’t easily turn it off with the app I’m using.

Bot_Code_2.txt (9.74 KB)

In case anyone is interested on getting the HC-0X to auto pair, you can follow these instructions on getting into the programming mode http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/

The list of commands can be found here. You are specifically looking for the connection mode and binding commands(page 9 if you save/print as PDF) http://elecfreaks.com/store/download/datasheet/Bluetooth/HC-0305%20serail%20module%20AT%20commamd%20set%20201104%20revised.pdf

I just took a look at your code, and I'm not surprised it doesn't respond. You have so many delays and a while loop that is unneeded. I see your using the meetandroid library too, I personally don't really like that library. So if you want, I will show you how to fix your library so that it responds much better. But first you need to learn about the Blink without delay example sketch because that's is what will help your code a lot.

I'm not actually using the MeetAndroid library functions I just forgot to remove the include tags for it.

Please let me know how I can improve it. Especially if you can help me get past the delay problem

Let me ask you this, how do you want to control it? Do you want to send single characters ('W', 'S', 'A', 'D') or a string of accelerometer data ( -20 ... 20, -20 ... 20) -> (forward/reverse, left/right)?

Motion control with accelerometer data and send either m or a to switch between motion control and autonomous mode. So both, more or less