SERIAL and BT SERIAL Support

Issue #31 resolved
Turgut Guneysu created an issue

Hello MB Team,

I was wondering if there were any plans to support USB Serial and BT Serial connections in the microBlocks ?

It is imperative to have these to support wireless control of robotic cars etc for school projects. As you know, while the RADIO feature is pretty nifty, it lacks serious comms capability due to small number of buttons on the micro:bit board. A cell phone interface is very useful in this regard, but not possible to interface at this time in microBlocks.

Even if BT support is far down the priority list, the SERIAL (or SOFTSERIAL) would have been very useful now.

FEEDBACK:

I have been extensively using the microBlocks with kids for coding games, remote car controls, etc. I find that the development ease and execution and testing capabilities are far better than the MakeCode environment. Not needing to download code, immediate execution, instant change and test capabilities are very much appreciated. Also, the last bit of change implemented by John re language testing on the fly makes things very easy to test and correct.

Thanks a bunch for all the efforts ! It is WELL RECEIVED and will make microBlocks the best dev IDE out there.

Comments (7)

  1. John Maloney repo owner

    Thanks for sharing your experience with using MicroBlocks with kids. I’ve had similar experiences with MicroBlocks vs. MakeCode but I’m not an impartial observer. It’s great to someone with a more objective perspective report the same thing.

    I agree with the desirability for BT support. Unfortunately, the Bluetooth stack uses over 10K of RAM and the remaining 6K isn’t enough RAM for the MicroBlocks virtual machine.

    However, there are a couple of ways you can create remote controls that have more buttons. One way is to use a micro:bit tethered to a laptop to send radio commands to the robotic device. You have blocks to send various radio codes (e.g. numbers) sitting in the scripting are and you can issue commands just by clicking on them. It’s a bit crude – and it requires a laptop – but it works.

    Another way is to use a television remote control (ideally one that outputs “NEC” IR commands. Again, you’d use one micro:bit to send commands to the robot via radio. That micro:bit would have an IR receiver attached. You’d import the IR library and write a script that receives IR commands when buttons are pressed on the IR remote and then sends commands via radio to the robot. This is more complex and requires an IR receiver module (those cost less than $2.50 from places like SparkFun or AdaFruit). If you’re working with younger kids, you could create the IR remote program and just have them program their robots to respond to radio codes.

    A final (and probably the best) approach would be to use a Snap! project to control the tethered micro:bit. We’re working on a mechanism that will allow Snap! to interact with MicroBlocks via the MicroBlocks IDE, would run run a tiny HTTP server. This approach would let you create a UI for your robot in Snap! This feature isn’t out yet, but we’re working on it!

  2. Turgut Guneysu reporter

    Hi John,

    Thanks for the quick reply and pointers. Already did the TV remote option. Functionally not bad at all.

    However, it does not come up to the command level design capability of working with BT.

    I was wondering, you did not say anything about the SERIAL IO capability ! That is a standard feature of the micro:bit. And I actually prefer using BT via the SERIAL IO coding. That also eliminates the need for a 10K BLE load ! Do you think that is in the near future feature set?

    I am totally excited about the SNAP - microBlocks interface. That would truly enhance both products. As things develop, I see a very capable set of tools designed to work together like a learning eco-system. The disparate world of Scratch2, 3, micro:bit is driving me crazy.

    Finally, I was curious if you had a chance to review #29 of issues?

    Brgds.

  3. John Maloney repo owner

    What do you mean by “using BT via the SERIAL IO”? If you’re talking about sending serial data over Bluetooth, that also uses the Bluetooth stack so it has the same RAM issues. On the other hand, if you’re interested in communicating with a micro:bit running MicroBlocks over a USB-serial cable, that is already possible by using the same protocol that the IDE uses. That protocol is documented, although it’s not really intended for use by anything besides the IDE and the Mozilla IoT gateway.

  4. Turgut Guneysu reporter

    Just noticed your reply - sorry !

    What is meant by the BT via Serial IO is as such:

    micro:bit has Serial IO and Serial IO redirection support implemented very well as a standard tool. This allows one to mount a HC05/06 type BT device on various kits that accept micro:bit as a plug in device and some even supply a BT plug-in on the kit board.

    e.g.:

    Given this type of a setup, one mounts the BT card and the micro:bit on the Kit board. Then redirects micro:bit Serial IO to the port assigned to the BT card. After that one gains the CABLEless comms capability via outside world by simply using the BT Serial channel to read and write strings/nums etc. to any other device.

    At the other end, when we combine this with mobile based APPDev tools like APPInventor2 or any of the BT terminal APPs on Androids or iPhones, kids get to use mobile phones as a remote, without the hassles of the BLE BT mumbo jumbo ! And no 10K BLE stack needed.

    What is lacking in microBlocks, Snap!, SNAP4Arduino, and Scratch4Arduino is this ability to do Serial IO to a designated port.

    I hope I was able to explain.

    😅

  5. John Maloney repo owner

    Nice to know about the HC05/06 devices. I hadn’t come across those before.

    There are some technical challenges with supporting a secondary serial port on the BBC micro:bit. (The primary serial port is the one connected to the USB-serial chip that allows the MicroBlocks IDE to communicate with the MicroBlocks runtime system on the board.) Unfortunately, the NRF51 chip used in the BBC micro:bit has only a single UART. You could switch that UART to use different I/O pins, but then you couldn’t communicate with the board via the USB-serial connection.

    I haven’t checked the datasheets, but I’m pretty sure that most of the other processors that MicroBlocks supports have multiple UART’s, making it possible to open a secondary serial port on some other set of pins. While there would still be some technical challenges (and work) to support a secondary serial port on those boards, they would allow you to continue to use the MicroBlocks IDE while also using the secondary serial port. However, my impression is that you’d prefer to stick with the BBC micro:bit, so we’re stuck with the single-UART problem.

    Going back to the start of this discussion, it sounds like your goal is to remotely control robotic cars, etc. As you say, the “radio” commands offer a way to transmit the commands, but since a micro:bit only has two buttons, it’s not a great remote control…

    One option to get more buttons is to buy a micro:bit button or game controller extension board such as:

    https://www.elecfreaks.com/store/elecfreaks-joystick-bit-2-for-micro-bit.html

    https://www.elecfreaks.com/store/octopus-adkeypad.html

    Another option, since you’ve already worked with IR remote controls, is to use an IR remote control plus a “base station” micro:bit to send send radio commands to the remote robotic vehicle. The IR remote would transmit commands via IR to a micro:bit a few inches away that would then forward the commands via radio to the robotic vehicle. You’d essentially be turning an IR remote control into a radio remote control.

    One final option for the longer term (based on work still in progress and not well documented) would be to use the Mozilla Web of Things server built into the MicroBlocks IDE as an intermediary. This approach is similar to IR remote solution in that a micro:bit tethered to the IDE would serve as a radio base station that forwards command on the the robot. The program running on that micro:bit would be a Mozilla IoT Thing (see iot.mozilla.org).

    You could interact with it either via the (free) Mozilla IoT gateway or through a UI you’d create yourself in Snap! (There is an unreleased Snap! library that can communicate with the MicroBlocks IDE via the gateway API. I can send you a copy if you want to explore that approach.) It might take you a while to set this up, but the end result would be a control panel implemented in Snap! that would run on any internet-connected device able to run Snap!

  6. Turgut Guneysu reporter

    Hi John. Thx for the detailed explanation. The gist of it being no Serial IO support to be expected on micro: bit.

    My final comment re UART on micro:bit being used by the USB port is: the whole idea is to program and load the program via USB. But then programmatically break the USB link and switch to BT and run wireless and cableless. This can be done in MakeCode beautifully and works like a charm. However MakeCode is not microBlocks. And not having the Serial capabilities and supporting thethered ops only severely restricts microBlocks.

    Anyhow, respecting your views and dropping the subject.

    TG

    Get Outlook for Androidhttps://aka.ms/ghei36

  7. Log in to comment