How to reference Bluetooth module in Megapi?


#21

After some further testing I (found there were 4 serials on Mega). Bluetooth is on Serial3
So to communicate with the MegaPi Bluetooth module, pairing is done automatically by the module, you only need to setup the serial communication.
Here is a simple sketch to test this.

#include <MeMegaPi.h>

void setup() {
	Serial.begin(115200);
	Serial3.begin(115200);
}

void loop() {
	// Write back data received from Bluetooth to Serial monitor
	if (Serial3.available()) {
		Serial.write(Serial3.read());
	}
	// Send to Bluetooth data received from Serial monitor
	if (Serial.available()) {
		Serial3.write(Serial.read());
	}
}

#22

I’ll test that today.

All I ever got back from support is what you see in this thread. I tried a variation of their code which looped through the serial ports but mine hung as soon as I tried Serial1. I did read somewhere else (wish I could remember where) that Serial1 was used, but I’d just set this issue aside for a bit while I worked on other things.

I’m guessing you are using the plug-in BT module and not the MeBlueTooth RJ25 module, yes?


#23

Yes I am using the plug-in BT, straight from the Ultimate 2.0 box.
And this code worked using the board as you assemble it for the first robot from the book.


#24

I’m just combing my test scripts for turning - trying to use compass readings to repoint the tank - and I’ve added in the Serial3 as you pointed out. Testing later this afternoon.

While OTT, I’m pretty new to robots and microcontrollers and I really don’t want to copy what others have done, so it takes me a lot longer to get even simple things running. I could copy/paste examples (I have) and code from other places (I’ve done that, too) but I learn much better and it stays with me longer if I write it.

I’ll let you know what happens tonite. Hopefully, this is the last changes I need to make to the bot to get it running autonomously (at least in the house).


#25

@bigAL can you usb zhe bt at the end i am build a project need chaining zhe phone and zhe megapi,but when i use zhe magepi bt mod (not rj25),i cant chaining zhem, but i can chaining ardunio uno and other bt mod ,so canyou show me how you fix it ,or can i see your code


#26