How to use dual mode bluetooth module in the Arduino IDE?


#1

I want to make a custom remote control for my mbot and I have no idea how to use the module in the Arduino IDE since it is connected to the board not through one of the ports. How would I go about using the chip in my sketch?


#2

Hi,
For a starter I’d suggest you have a look at the meBluetooth example that comes with the makeblock library.

Then you could have a look at this tutorial which probably does what you want. However, this tutorial is made for the robot kits, not mbot. Regarding mBot you could possibly create a test sketch in mBlock and then study the arduino code it produces from it. Then just copy the code to arduino IDE and continue testing.

Please don’t forget to post your solution here in the forum, there are many people here who will appreciate if you share how it works.

Cheers,
Stefan


#3

I have looked in mBlock for anything relating to the bluetooth module but there is only the greyed bluetooth option in the connect menu. Otherwise I can see the IR blocks. I’ve seen the tutorial before but that bot uses the port connection for the bluetooth module. Looking at the example sketch I see that the code is using a different baud than the one I’ve been using. Maybe thats the issue.


#4

You can use 115200.


#5

I dont know if this problem have been already solved but, i look into this post and the tutorial srothe said, and find a way to make mBot work with his bluetooth module using the same app srothe used in his tutorial, the bluetooth that come with mBot not the MeBluetooth Add-on. It was trough the Arduino IDE but the problem was that mBot had none blocks that support a connection of some sort, but the board is made in a way that the bluetooth works like a wired serial if mBot is the slave on the connection, you can use the Serial.write and Serial.read from arduino to read the bytes sent to mBot Bluetooth. So its more easy than i first imagined just write a code that includes the Wire.h and SoftwareSerial.h … the MeMCore.h and the default onboard Me add-ons that mBot has (rgb led’s, light sensor, motors etc…). When the app on the cellphone connects to the mBot board the hardware open the serial channel and you can read the bytes sent to the serial using the Serial.read function … simple as that. If you want to test on the pc instead, i recommend use the realterm software, the serial monitor on the arduino IDE its text based so if you want to transmit bytes that are non-Ascii the realterm is perfect for that.

The baudrate i used was indeed 115200 … In the arduino setup function i just used the Serial.begin(115200) and the controller app on android find the baudrate automatically.

The source code for mBot default firmware has all of this plus all the modes that he is pre-programmed to do. But in the default firmware the functions that read the serial use a protocol … here is a link of someone on the forum that made a post about this protocol and how it works in case someone wants to use/customize or expand the default firmware.

In the default firmware look for the parseData function where the program selects if the received command was to read a sensor or activate something … just follow the next functions calls and you will see the function runModule that contains the switch case that handles the commands that can be sent trough the mBot smartphone app via bluetooth.

If this looks a mess i sorry for the post. My first language is not english and i never write a post before. If i polish my code and someone show some interest, i can share it after. Thanks, and i hope it helped.