Sending bluetooth serial data to mbot


#1

Hi, I’m trying to send bluetooth serial data from raspberry pi to mbot.

On mbot, I recycled the code from this thread:

Like this:

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#include <MeMCore.h>


void setup(){
    Serial.begin(115200);
    Serial.println("Start");
}

void loop(){
    if((Serial.available()) > (0)){
        Serial.println(Serial.read());
    }else{
        Serial.println("No");
    }
    _delay(1);
    _loop();
}

void _delay(float seconds){
    long endTime = millis() + seconds * 1000;
    while(millis() < endTime)_loop();
}

void _loop(){
}

On Pi side, I just wrote very simple python code, like this, with pairing Pi to mbot on rfcomm0.

#! /usr/bin/python
import serial
from time import sleep
bluetoothSerial = serial.Serial( "/dev/rfcomm0", baudrate=115200 )
bluetoothSerial.write("a")

Python code works without any errors. However, mbot couldn’t receive any data from Serial port.

Am I missing something? Appreciate your help. Thanks.


Raspberry Pi 3 and mBot
#2

Turned out I connected to Makeblock_LE, not Makeblock via bluetooth. Now it works.


#3

Dear yuk,
I just tried your code in my raspberryPi and mBot, but the mBot can’t receive any data from raspberry Pi, can you pls help on this ? I’ve no idea how to solve this, thanks in advance.
mBot is looping:
image
there’s no error in python:

BTW, I connect Makeblock via bluetooth, not Makeblock_LE, is this right ?


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.