Communication Blocks
The Luma Matrix extension provides blocks for wireless communication between multiple micro:bit devices equipped with Luma Matrix displays. This allows you to send images and color patterns from one device to another using the micro:bit's built-in radio capabilities.
Setting Up Communication
Before using any communication blocks, you need to set up the radio channel on both the sending and receiving micro:bits. All devices that want to communicate must be on the same radio channel.
radio.setGroup(1)
Available Communication Blocks
Send Image with Color
This block allows you to send a monochrome bitmap image with a specified color to another Luma Matrix. The receiving device will display the image in the chosen color.
Example usage:
lumaMatrix.sendImageWithColor(lumaMatrix.matrix8x8(`
. . . . . . . .
. # # . . # # .
. # # . . # # .
. . . . . . . .
# . . . . . . #
. # . . . . # .
. . # . . # . .
. . . # # . . .
`), 0xff0000)
Send Compressed Pixel Buffer
This block sends a full-color image by compressing the pixel buffer before transmission. This is useful when you want to send images with multiple colors.
Example usage:
lumaMatrix.sendPixelBuffer(lumaMatrix.getPixelBuffer())
Receive Matrix Data
This block sets up an event handler that triggers whenever matrix data is received over radio. The handler provides two parameters:
dataType
: Indicates whether the received data is a bitmap (1) or RGB image (2)receivedBuffer
: The actual data buffer containing the image information
Example usage:
lumaMatrix.onReceivedMatrix(function (dataType, receivedBuffer) {
if (dataType == 1) {
let image = lumaMatrix.parseImage(receivedBuffer)
let color = lumaMatrix.parseBufferForColor(receivedBuffer)
lumaMatrix.showImage(image, color)
} else if (dataType == 2) {
lumaMatrix.showPixelBuffer(lumaMatrix.parseColorImage(receivedBuffer))
}
})
Color Palette
For efficient communication, you can use predefined colors from the color palette:
- Red
- Green
- Blue
- Orange
- Yellow
- Purple
- White
- Black
Example using color palette:
lumaMatrix.sendImageWithColor(myImage, lumaMatrix.getColorPalette(lumaMatrix.eColorPalette.Yellow))
Technical Details
The communication protocol uses data compression to efficiently transmit images:
- Monochrome images are compressed to 8 bytes (1 bit per pixel)
- Color information is sent as RGB values (3 bytes)
- Full RGB images are compressed from 192 bytes to 24 bytes
- Large buffers are split into two packets for reliable transmission
Tips and Best Practices
- Always ensure all devices are on the same radio channel
- Add a small delay (1-2ms) between sending multiple packets
- Consider using the predefined color palette for more efficient communication
- Handle both bitmap and RGB image types in your receive handlers
- Test communication in areas with minimal radio interference
Troubleshooting
If you experience issues with communication:
- Verify that all devices are on the same radio channel
- Check if the devices are within range (typically 10-20 meters)
- Ensure the sending device has completed transmission before sending the next image
- Monitor the serial output for debugging messages
- Consider reducing the radio group number if there's interference