BNSBluetooth - RobotC Library for the HC-05

Hello all! One of things on Team BNS we have been trying to figure out is ways of sending and receiving data on the fly to be able to better debug our robots. Our initial approach to this is to use an HC-05 Bluetooth module that connects into the extra UART port on the cortex. There are a lot of advantages to using the HC-05 module like this, such as many computers and phones have bluetooth built in, so connecting to your robot should be pretty straight forward. Additionally, being able to send data to the robot will allow for quick adjustments for things like tuning PID controllers on the fly. Finally, it’s always fun to learn about UART if you don’t know much about it yet :slight_smile:


Now what we’ve written is a small library that does two things.

First, allows you to reprogram your HC-05 module to different names/baudrates using AT Commands. This reduces the need to breakout an additional arduino or usb->uart dongle to change these internal settings.

Second, we have included a few examples on how to send and receive data over the UART port on the Vex Cortex.

Check out the library here :
NOTE: I have noticed a lot of bugs with the debug stream in RobotC 4.32, it’s recommended that 4.27 is used.

To set the HC-05 into a “reprogrammable” mode, set the key pin to 5V


Here is screenshot from my phone when running the IMEBluetoothDemo.c file.


And the wiring from the HC05 to the cortex:


1 Like

As a proof of concept, I was able to print velocity measurements from the IME’s along with the motor power, then use an app from the android app store to display those values on a graph realtime!

App I used here:

Code used on the cortex:

The red line is the IME velocity calculations and the green line is the set PWM.


1 Like

Nice work, I need to order a module and try this out.

Can you elaborate on this, I did not upgrade from 4.30 yet but the release notes implied that the debug stream was improved in 4.32.

I posted a somewhat brief thread on the RobotC forums here:

What I’ve concluded is after so many characters are sent, the debug stream hangs and reprints the same set of characters indefinitely. If you press “stop”, it resends a lot of the text is already did and continues to reprint more text. I haven’t found a workaround to this yet.


(well except for the logging bug. And I just upgraded to 4.32. Wunderbar)

Error:Undefined procedure ‘delay’.

Why do I get this?

Which version of RobotC are you using? This library is only supported on 4.xx (tested on 4.27) and it’s possible “delay” wasn’t a function in RobotC 3.xx. Also, if you are using 4.xx, are you in “Vex IQ” mode or “Vex Cortex” mode?

(Idea creds: Tabor)

Ty for ANSS …
I’m using the 3.64.
I’ll search the version 4.27 and I keep trying.

Just wanted to chime in with a couple of quick notes: the debug stream issue in the current build of ROBOTC 4.32 is a known issue and is currently being debugged/explored, and we hope to have a fix available as soon as possible. We’ll update our blog ( with more information as it becomes available.

As a heads up, the sleep() and delay() commands introduced in ROBOTC 4.X are exactly the same as the wait1MSec() command in ROBOTC 3.X and 4.X installations (you can also use them interchangeably).

This particular library may not work on older versions of ROBOTC 3.X, but if the delay() command is the only change, a quick find/replace to wait1MSec() should resolve that issue.

Even I need to connect everything to see if it works what you advise me. Thanks for your answer.

I have fear at connect the “key” to 5V and damage the HC05 or Cortex.
How can i ensure the integrity of the components?
After of this, what i do? i disconnect the “key”? how i configure the HC05?
Sorry for all questions but i m noob in all this.

All good questions I didn’t really talk about in my original post!

The “key” pin technically is 3V3, so there is a risk of damaging the HC05 if you connect it to the cortex’s 5V. Though, in my experience the HC05 can handle the 5V fine. If you’re concerned, you can create a voltage divider out of resistors to bring the 5V down to 3.3V. See this image.

So to reprogram the settings of the HC05, do the following:

  • Unpower the cortex so that the HC05 module is no longer on.
  • Connect the “Key” pin to power, whether that is 5V or 3V3.
  • Turn on the cortex and you should see the HC05 have long blinks.
  • Send any AT commands you need to change the internal settings.

To run the HC05 normally:

  • Unpower the cortex so that the HC05 module is no longer on.
  • Disconnect the “Key” pin so that it’s floating, no longer connected to anything.
  • Turn on the cortex and you should see the HC05 rapidly blink.
  • Connect your device (say a phone). When successful, the HC05 will blink twice, every so often.
  • Send whatever data you need to to your device :slight_smile:

Let me know if anything is unclear or doesn’t work!

All is ok explained, i will try following you tips.

You indicated this “- Send any AT commands you need to change the internal settings.”
How can i send the AT commands? What programm i need ?

Check out atDemo.c from my repo. Link Here:

The basic steps are the following:

Set the cortex’s buad rate to 38400, which is what the HC05 uses in AT mode:

setBaudRate(UART1, baudRate38400);

Test the connection, bnsAtTestConnection returns true if it was able to communicate with the module succesfully.


Then do whichever AT commands you want to perform as shown in that file. For instance, to set the name of the bluetooth module, you can just say:

bnsATSetName(UART1, "TEAM BNS");

Hope that helps!

All this configuration, is really necesary? Can i connect and use the module directly?

Yes it’s necessary to set the baudrate and it’s good to check so you know you’re communicating properly.

What do you mean by “Can I connect and use the module directly?”. Once you have programmed the module to the settings you want, you can remove the “key” pin and communicate as you want. I recommend running “atDemo.c” to try to set all the parameters on the hc05, then run “bluetoothDemo.c” to see if you can get "Foo!’ on the device you connecting to over bluetooth.

I thought that the module HC05 had a compatible default settings with vex cortex. In this moment i can’t change configuration of module because, tomorrow, i have a presentation and need use the HC05.

The monday i will continue with the configuration, but you attentive! i will continue asking! jajajajjaj thank for all.

If you know what baudrate the HC05 is set to already, you can just set the cortex to that baudrate and it should work fine! The AT commands just lets you customize those settings so you can for instance achieve a faster baudrate.

Good luck! :smiley:

Sorry for asking this (a lot of this is way over my head), but is it possible for the Bluetooth to send the debug stream over to the said connected device? If so, how many characters per second could it handle? Thanks!