How to reference Bluetooth module in Megapi?


#1

Greetings -
I’m using the Bluetooth module (from my mBot, not the RJ25 module) on the Megapi and I’m wondering what code is needed to initialize it within Arduino IDE. I’ve looked at all examples - there’s only one and it references the RJ25 module - and also searched around in the “firmware” sketches for the MegaPi.
I know it’s just a serial passthrough device once working, but what do I need to do for includes and code for initialization?
All I need (for now) are those two items.
Thank you for your help.


#2

Hi @BigAl,

Be sure to copy @tec_support on questions like these to get a faster answer. :slight_smile:

I’m not sure that you need to do much beyond pairing up the Bluetooth with your device or computer. The onboard firmware sets it up as a serial port if I recall correctly. However, @tec_support will be able to provide a much more thorough answer.

Regards,

Chuck


#3

I just assumed there was a method to specify the serial port (in the sketch) in order to distinguish it from the other serial ports (serial monitor and the TFT). I also assumed you’d need to initialize it somehow.

Like with the MeWifi, I have some conceptual issues to deal with, I imagine. I couldn’t get over the idea that you needed (or could) do nothing with the MeWifi module, other than treat it as a passthrough. It finally dawned on me one morning. But you do need to initialize and specify a port for it, so I figured I need at least do that with the BT.

Maybe I should just try it first, then determine if there’s an issue. (now, there’s an idea!)


#4

This is from a sketch (also concerning using BT) that illustrates what I’m talking about.
MeBluetooth bluetooth(PORT_5);
And then:
bluetooth.begin(115200);
In use:
bluetooth.read();

After that, of course, you can reference incoming or outgoing serial data designated for the bluetooth port. Without these declarations, how does one address the bluetooth serial port specifically on the Megapi and mBot chassis? Just:
serial.begin(115200);?
and
serial.read();?
If that’s the answer, how do you differentiate between serial monitor and bluetooth?


#5

Hi BigAl,

Since the Ultimate 2.0 robot use the MegaPi board with the Bluetooth Module for mBot.
You can refer to the instructions for Ultimate 2.0 have a try: http://learn.makeblock.com/en/ultimate2/


#6

That page does mention how to connect to the Bluetooth from other devices, but no mention of programming it. Do you have any example code of a Bluetooth controlled Megapi?

A single example of how you reference the module from within arduino would be great.


#7

Hi @BigAl

May be this example helps?

I wrote it for the Ultimate 1, but BT handling should not have changed.

Cheers, Stefan


#8

@srothe, thanks for the reply, but you actually are stating the same thing I am. You’re using the MeBluetooth module, which I get perfectly. (The version 1 used the Orion and a MeBluetooth module.) When you instantiate it:
MeBluetooth bluetooth(PORT_5);
you expose and name the methods. I’m asking how to do that exact thing when the module is the pinned version used on the mBot and Megapi. You can’t, unless you assign the Bluetooth, like in your sketch,v work with the module using its name. I tried.
I looked through some of the example code and found a section (i don’t recall where) where the sketch is checking for a command coming in through bluetooth. It just looks through serial, serial1 and serial2, checking to see if something had been received.
If that line was doing what I want, it seems a bit haphazard and doesn’t address sending data. I suppose, if it worked, you could then set the bluetooth serial port as the one you found the data on. I’m not sure.
Just seems there should be a concrete way, like with the MeBluetooth module, to specify the port for communication.


#9

Hmmm, ok got it.

Did you look through the code of the involved libraries? May be there is a method which is just mot described in any tutorial? Sorry I can just try and throw in brief ideas here.


#10

Hi BigAl,

There is no more code for this Bluetooth module.
It does not require any initialization, when it powers on, starts flash and directly enter the pass through, you can use Bluetooth to directly search for connections. No code processing is required.


#11

I do understand that. Once powered up, I can see and attach to it from other devices. But how do I send through it from the MegaPi?
As @srothe and I both have shown, when you use the MeBluetooth module, you can reference it by it’s name (whatever you decide the name is). How do I reference the MegaPi bluetooth module? Is it only through the serial connection? If so, which does it use?


#12

Hi BigAl,

Please refer to the explanation in this link: http://forum.makeblock.cc/t/bluetooth-megapi/5661


#13

Weird, I can’t access that topic. :frowning:


#14

@tec_support , I can’t access this topic either. Please fix the access rights.


#15

Hi Charles & Srothe,

BigAl sent me a private message in this link, I think only BigAl can access that link.
You may ask BigAl to invite you guys, haha:smile:
Here I attach the screenshot:


#16

I don’t know how to invite you guys to a message thread.


#17

Should be an invite button towards the bottom of the screen. :slight_smile:


#18

Not that I see.


#19

Hm, ok, try adding our “handles” (@chuckmcknight, etc.) to the thread.


#20

Hello,

What was the answer here ?
On the arduino side, the sketch should look on which Serial port of the Mega to talk with the bluetooth module ?
Serial/Serial1/Serial2/ ? Or should we use a MeBluetooth object ? In such case, what is the port number to use ?