BNSBluetooth - RobotC Library for the HC-05

As it sits, you can create your own debugstream as such:


bnsSerialSend(UART1, "Hello World!");

or if you want to attach data to that:


string sendingStr;
stringFormat(sendingStr, "Hello World %f", 3.14);

bnsSerialSend(UART1, (char*)&sendingStr);

Now what I think what you’re question is more asking is can you use “writeDebugStream” to print over bluetooth? Directly, I don’t think that’s possible as the debug stream uses UART0 and you can’t change it (factcheck?). However, what might be possible is that writeDebugStream could be overwritten using something like “#define writeDebugStream bnsDebugStream”.

Looking at this thread, it looks like it could be possible to do that.

The following might work? (I won’t have access to RobotC for the next several days so this is untested code)


#define writeDebugStream bnsDebugStream

void bnsDebugStream(String str, float option1 = (-1), float option2 = (-1), float option3 = (-1))
{
  string sendingStr;
  stringFormat(sendingStr, str, option1, option2, option3);

  bnsSerialSend(UART1, (char*)&sendingStr);
}

I guess that’s assuming stringFormat can handle additional parameters even if str doesn’t contain them.

EDIT:
As for how many Bps bluetooth can handle, I normally set the baud rate to 57600, so that corresponds to around 5760 bytes per second (8 bits + 1 start + 1 stop). I have found on rare occasions faster then 57600 baud bits can be misinterpreted with the HC05 so I typically stick with that.

What method of changing the device password did you guys use?

bnsATSetName() can set the name, but are you keeping the password to the default 1234?

This seems like what you want to do but in Arduino speak…

AT command reference for this bluetooth guy…
http://www.instructables.com/files/orig/F3O/K70G/H1LWQ0PO/F3OK70GH1LWQ0PO.pdf

from this page:
http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/

AT command reference for this bluetooth guy…
http://www.instructables.com/files/o…0GH1LWQ0PO.pdf

from this page:
http://www.instructables.com/id/Chea…een-Arduino-a/

Sorry for the slow response, just been really busy recently. I have updated by repo with the function “bnsAtSetPIN” which can used as such:
bnsAtSetPIN(UART1, 1234);

EDIT: I’m not thinking right now, PIN != Password. Will add a password function tonight.

Also in terms of the writeDebugStreamLine, if you now add


#define writeDebugStream bnsDebugStream
#define writeDebugStreamLine bnsDebugStreamLine

to the top of your file, any debug streams will be sent over bluetooth!

This will work with a hc-06 module?
I have a JY-MCU v1.06 module, but i don’t know if it are hc-05 or hc-06. How can i know the model?
Thanks.

It looks like HC06 requires some modified commands to get it to work (I don’t have one to try unfortunately). All the AT commands in this library end with “\r\n”, while the HC06 won’t work if the AT commands end with “\r\n”. If you want to try, delete “\r\n” everywhere you see it in BNSlib_HC05.c

A good way to determine if you have HC-05 or HC-06 is to run bnsATTestConnection(UART1);
and see if you get connection. If not, then go into BNSlib_HC05.c and delete the “\r\n” and see if you can get any connection. Hopefully one of those two will connect!

Additionally, see here for more info: Using the HC-06 Bluetooth Module | MCU on Eclipse

Hope that helps!

Thanks so much, all is fine! Very very very very afraid jajajajaj, connect a JY-MCU v1.4 (hc-06) module and all is working. It was not necessary change nothing.
I repeat, THANKS SO MUCH!

I just purchased an HC05 and over the next couple of days will be playing with getting BNSBluetooth to work. I will be bothering Justin quite a bit to get everything working and then will post an indepth guide on how to get everything working out of the box. Hopefully some teams make cool uses of this throughout the year.

Okay so I honestly thought I would make an indepth guide. The process ended up being so incredibly easy that it never seemed necessary. So with a 9$ HC05 I used Bluetooth communication to my phone for all my debugging because everything is live and wireless. Example below of me tuning drive straight PID and stay pointing straight. The second one looks really poor but that is just because it is zoomed in so much. It never drifted more than 2 or 3 degrees from desired angle while driving straight.

This app below is incredibly useful because it live graphs data coming in and lets you set up multiple(up to 3) variables to independently graph. You can manually adjust the scale or allow it to auto adjust

I would strongly recommend people purchase a Bluetooth module and give this a try.