The Snap!Bridge example program provides an easy way to interface between MicroBlocks and Snap! projects via a USB-serial connection. It only works in browsers that support WebSerial (Chrome or Edge) or WebBluetooth (Chrome, Edge, various browsers on Android, or the Bluefy browser on iOS).
Although the program includes support for features of the MakerBit and Hyperduino shields, it can be used to get sensor values from a micro:bit or Calliope min or to interact with the pins of other boards.
The program can also be extended to support the features of other boards.
Interactions between Snap! and MicroBlocks requires programs on both sides to handle the communications. The MicroBlocks program is "Snap!Bridge", one of the example programs that comes with MicroBlocks (in the "Other" folder). The Snap! program is "MicroBlocks Bridge v1.4" linked below.
Prepare the board (e.g. a micro:bit or Calliope mini) by first installing the MicroBlocks firmware. If you are new to MicroBlocks, see Get Started.
Run MicroBlocks, either in a Chrome or Edge browser or download and run the stand-alone app. Plug in the board. The stand-alone app should connect to the board automatically when it is plugged in. If running in the browser, click the USB icon and select the board to connect. A green circle should appear behind the USB icon showing that the board is connected.
Select "open" from the File menu (file icon), click the "Examples" shortcut button, then open the "Other" folder. Select "Snap!Bridge" and click the "Open" button.
Wait a few seconds for the program to load onto the board. You'll see a circular progress indicator to the left of the green start button as it is loading. When loading is complete, exit the MicroBlocks app or close the MicroBlocks tab in the browser.
Finally, unplug the board from the USB cable. That will ensure a clean start when the board is next plugged in or powered up.
The board is prepared!
Dowload the file "MicroBlocks Bridge v1.4.xml" (linked below).
In a Chrome or Edge browser, go to the Snap! website. Click the "Run Snap!" button. Drag and drop the file "MicroBlocks Bridge v1.4.xml" onto Snap! to load it.
Make sure that MicroBlocks has been closed, then plug in the board.
Click the green flag in Snap! to run the program. You'll get a browser dialog box asking which board you want to connect to. There may be several COM ports listed, but it should be obvious from the name which one is your board. Select that board and click the "Connect" button.
You can also select connect wireless via Bluetooth Low Energy (BLE) if your board support that. (The micro:bit V2 and Calliope mini V3 both support BLE.)
When the connection is made you will see a talk bubble in Snap! like this:
That indicates that Snap! has successfully connected to MicroBlocks. It also tells you the version of the SnapBridge program (1.1) and what type of board ("Calliope V3") it is running on.
You'll see several variable watchers on the stage for some of the data being streamed from the board such as the tilt, light, and temperature sensors. Open the Variables category in the blocks palette to see other data that is reported, including arrays of values for the digital and analog pins.
You can now write Snap! scripts that use sensor and pin values from the board. Here is a simple script that graphs the Tilt-x sensor value.