MicroBlocks BLE Extension

MicroBlocks

MicroBlocks is a blocks programming language for physical computing.


Image of the pilot version of MicroBlocks version 2

It runs on microcontrollers such as the micro:bit, Calliope mini, AdaFruit Circuit Playground Express, and many others.

Code Interactively

MicroBlocks is a live environment. Click on a block and it runs immediately, right on the board. Try out commands. See and graph sensor values in real time. No more waiting for code to compile and download.

Multitask Naturally

Want to display an animation while controlling a motor? No problem! MicroBlocks lets you write separate scripts for each task and run them at the same time. Your code is simpler to write and easier to understand.

Run Everywhere

MicroBlocks runs on many different boards, but your scripts are portable. Buttons, sensors, and display blocks behave the same on all boards with the relevant hardware. MicroBlocks even simulates the micro:bit 5x5 LED display on TFT displays.

Unplug and go!

MicroBlocks downloads your code as you write it. When you like what your program does, just unplug the board and you're good to go. Make a pocket game, a fitness app, or light-up clothing that goes wherever you do.

MicroBlocks BLE Extension

The extension makes connecting to microcontrollers very easy. It does all the difficult work for you using the blocks it contains.

Methods:

Connect

Connects to the MicroBlocks device with the given name. Import the “Bluetooth LE” extension and use the “Bluetooth LE” block from that extension as the first parameter of this block. The second parameter is the name of the board you want to connect to such as “MicroBlocks XYZ” where XYZ is the board’s three-letter BLE ID.

Parameter Type
bleExtension component
name text

Disconnect

Disconnects from the currently connected BluetoothLE device, if any.


IsDeviceConnected

Returns true if a device is connected.

Return Type: boolean


SendMessage

Send the given message to MicroBlocks.

Parameter Type
message text

Events:

ConnectionChanged

This event is run when a device is connected or disconnected.

Parameter Type
isConnected boolean

MicroBlocksMessageReceived

This event is run when a MicroBlocks message is received.

Parameter Type
message text

This documentation was generated using Akshat Developer's Documentation Generator.

Examples

Connect to a board

The name of a MicroBlocks BLE enabled device is MicroBlocks followed by a space and the 3 letter BLE id.

If the board is a Raspberry Pi Pico W, then the name is Pico followed by a space and the 3 letter BLE id.

If your board has a display, it will show the BLE id when powering up. If the board doesn't have a display, you can get the BLE id by using the BLE id block that you can find in the Input category of MicroBlocks. The board has to be connected to the IDE to show the BLE id.

Receive a single value from the microcontroller

MicroBlocks Code

App Inventor code

Receive multiple values from the microcontroller

MicroBlocks Code

App Inventor Code

Receive multiple values from the microcontroller using keywords.

MicroBlocks Code

Using a space behind the keyword to separate keywords and values.

App Inventor Code

Splitting messages on the first space character found.

Send a message to the microcontroller from App Inventor

App Inventor Code

MicroBlocks Code

This block looks for a specific message

This block handles any message

Send a message with a value to the microcontroller from App Inventor

App Inventor Code

MicroBlocks Code

Example Project Beating Heart



beating_heart.aia (225.8 KB)
beatingheart.txt (4.3 KB)
Rename the beatingheart.txt file to beatingheart.ubp. The community doesn't allow files with the ubp extension.

I used the Tools Extension from @Taifun to keep the screen on while connected to the microcontroller.

Links:

Stable version of MicroBlocks v1

https://microblocks.fun/downloads/latest/
https://microblocks.fun/run/microblocks.html

Pilot version of MicroBlocks Version 2

https://microblocks.fun/downloads/pilot/
https://microblocks.fun/run-pilot/microblocks.html

Read about the new version 2 and why you could use that instead of version 1.

Extension version 1

fun.microblocks.microblocks.aix (12.6 KB)

We had already a number of meetings with members from the App Inventor development team and App Inventor Foundation, to see if this would benefit students learning physical computing.

11 Likes

The MicroBlocks extension is now featured on the App Inventor Foundation website.

So please give the extension a try, and see how much easier it is to work with BLE and micro controllers using MicroBlocks.

1 Like

(added to FAQ)

1 Like

Great article! I made an app based on this that controls two sliders with one MicroBlocks device. Here is the article. For your reference.

3 Likes

Thank you for using the extension. I posted your article on the MicroBlocks Discord server.

2 Likes

Very Useful and Great extension!
Thanks a lot, but it has some remarkable issues:
First, it does not work well with "Android companion" newer than version:2.68, it won't connect or throws a Java exception.
Second, everything looks good in the first connection, but if I disconnect and reconnect again, no messages will be sent. If I disconnect and reconnect again, the message may be sent correctly!
I would appreciate it if you could fix them.

If your issue is when running companion try the bugfix companion:

Select "NotNow" if asked.

2 Likes

Hi @Alex_Nolan,

Great that you tried the MicroBlocks extension. I hope the new Companion that Tim showed you will solve the problem. I really don't think it is related to the extension. I use the extension almost on a daily basis and it always works for me. It makes working with BLE and App Inventor so much easier.

With which microcontroller are you using the extension? Maybe you can share your project with us.

1 Like

Hi @TIMAI2,
Thank you very much. Version 2.73t6 has fixed the exception, and I hope it will be published on the Google Play Store soon.

Hi @Peter
Thanks for your response. Yes, the new companion fixes the exception thrown when running the app on my phone and improves the connectivity issue. But the non-working connections still exist.
The installed app using the APK file does not send or receive any messages at all, while it's connected!

Here is my project
MicroBlocks.aia (439.8 KB)

By the way, I am testing it using Doit ESP32 devkit V1.

1 Like

Great, what is EASY IOT?

That is my project logo, I am trying to teach my students about IoT and Robotics, of course in an easy manner :wink:

1 Like

Do you know the MicroBlocks website and the learn website and wiki MicroBlocks LEARN and Home | MicroBlocks Wiki

I would love to see what you are doing in your lessons especially since you are using MicroBlocks. How did you discover MicroBlocks? Was it this topic?

It is not working when you install? Are you able to connect using BLE?

Can you also show the MicroBlocks code?

Do you have a link?

Well, I am a fan of MicroBlocks for many reasons, first of all, it supports ESP32 very well, second it runs very smoothly and has great features. I know the website and wiki. actually, one of my colleagues introduced MicroBlocks to me about a year ago.

When I install the APK, BLE connects very well but no data communication happens at all. after a lot of connect and disconnects, there would be one time that everything works fine.

Maybe it's an issue in MicroBlocks firmware, I am Using V250.
Another interesting issue is that the BLE keeps disconnecting just after connecting, as long as the USB cable is connected to the ESP32 and MicroBlocks IDE is running.

Hi @Alex_Nolan,

That's strange. I use BLE with Pico, CoCube, microbit v2, calliope mini 3, ESP32, ESP32 S3, etc, etc and it always works. I can not see what is inside the costum blocks you made. Could you share the ubp file.

What phone and android version are you using?

Could you join the MicroBlocks Discord MicroBlocks, the MicroBlocks developers could help also with your question.