RoboticsGeneral

Maqueen UART via Bluetooth Low Energy

userHead Account cancelled 2019-07-26 04:49:22 9770 Views3 Replies
Hi,
I am developing an app using MIT App Inventor (the Scratch like language you can use to create Android apps developed at MIT) to control the Maqueen Robot. And I am planning to show it next week at MIT at the App Inventor summit. My proof of concept works fine. The phone communicates with the micro:bit using UART over Bluetooth (BLE) and the Makecode extension https://github.com/DFRobot/pxt-maqueen is used to let the Maqueen move.
But: I would like to do more! Like line following and obstacle avoidance. Whenever I try to add something more, there is an error message on the micro:bit: 020 - sad smiley. As far as I could find, this means that there is a storage problem.

I found in the micro:bit documentation that the Bluetooth service in the micro:bit requires a lot of storage and that you should remove what you do not need, like the infrared service. So this is my first question: would there be a possibility to have a version of the Maqueen extension without the infrared support?
Further, I have been reading this post: viewtopic.php?f=12&t=16884&p=29628&hili ... art#p29628 where there is mention of a (storage) problem with the ultra sensor for obstacle avoidance. My second question, is there indeed a problem with the obstacle avoidance that could crash the micro:bit?
Cheers, Ghica.

I show the code I used below and to be practical I show the JavaScript version:

function mqGoBck () {
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, mqSpeed)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, mqSpeed)
}
function moveMaQueen () {
if (mqCommand == "Fwd") {
mqGoFwd()
} else if (mqCommand == "Bck") {
mqGoBck()
} else if (mqCommand == "Rgt") {
mqGoRgt()
} else if (mqCommand == "Lft") {
mqGoLft()
} else if (mqCommand == "Stp") {
mqStop()
} else {
basic.showString(uaInput)
basic.showString("" + mqSpeed)
}
}
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Fullstop), function () {
uaInput = bluetooth.uartReadUntil(serial.delimiters(Delimiters.Fullstop))
mqCommand = uaInput.substr(0, 3)
mqSpeed = parseFloat(uaInput.substr(3, 3))
bluetooth.uartWriteNumber(mqSpeed)
moveMaQueen()
})
function mqGoFwd () {
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, mqSpeed)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, mqSpeed)
}
bluetooth.onBluetoothDisconnected(function () {
maqueen.motorStopAll()
basic.showString("D")
})
function mqGoRgt () {
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 50)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 0)
}
bluetooth.onBluetoothConnected(function () {
basic.showIcon(IconNames.Happy)
})
function mqGoLft () {
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 50)
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 0)
}
function mqStop () {
maqueen.motorStopAll()
}
let uaInput = ""
let mqCommand = ""
let mqSpeed = 0
basic.showString("MQ 8")
bluetooth.startUartService()
2019-07-28 03:40:29 Hi Ghica,
I am not in DFRobot Team or anything, but I wanted to provide this as an option to your problem:
BLE on micro:bit indeed does take a lot of space for what little it provides. One can easily do without it buy using a normal HC05/06 type bluetooth card.
Since you are already indicating that you would like to do away with the IR sensor, meaning you can reuse those pins, as well as the UltraSonic sensor pins (if you do not need them) for the TX/RX pins that will be needed for BT IO.
Using the HC05 type BT card, one does not need BLE extension and simply can use the Serial IO to exchange bluetooth messages and commands.
Hope this helps with your project and demonstration.
userHeadPic anonymous