Here is a quick blog post which is a followup to my previous blog post on - setting up BlueZ on the Beaglebone Wireless , as part of the blog post I have the BBC MicroBit talking to the Beaglebone Wireless via Bluetooth.
Here are the steps, and the Arduino code you will have to upload to the MicroBit -
First connect to the Beaglbone Wireless via SSH and setup Adafuit's Python library using the following commands, and also clone the repository so that we can run the UART service example
pip install Adafruit-BluefruitLE git clone https://github.com/adafruit/Adafruit_Python_BluefruitLE.git
Now for the BBC Microbit, download and install the latest version of the Arduino IDE(version that I have installed is 1.8.5), and also follow this guide on the Adafruit Learning system - https://learn.adafruit.com/use-micro-bit-with-arduino/adafruit-libraries to install the following libraries
- BLE Peripheral library
- Adafruit GFX library
- Adafruit_Microbit library
Copy paste the Arduino Code below into your, IDE and upload it to the BBC MicroBit
/* * Serial Port over BLE * Create UART service compatible with Nordic's *nRF Toolbox* and Adafruit's *Bluefruit LE* iOS/Android apps. * * Copyright (c) Sandeep Mistry. All rights reserved. * Licensed under the MIT license. See LICENSE file in the project root for full license information. * BLESerial class implements same protocols as Arduino's built-in Serial class and can be used as it's wireless * replacement. Data transfers are routed through a BLE service with TX and RX characteristics. To make the * service discoverable all UUIDs are NUS (Nordic UART Service) compatible. * * Please note that TX and RX characteristics use Notify and WriteWithoutResponse, so there's no guarantee * that the data will make it to the other end. However, under normal circumstances and reasonable signal * strengths everything works well. */ //07022018- Modified to send button press to Beaglebone Wireless #include <Adafruit_Microbit.h> Adafruit_Microbit microbit; void setup() { Serial.begin(115200); Serial.println("Microbit ready!"); //setup the two buttons on the microbit pinMode(PIN_BUTTON_A, INPUT); pinMode(PIN_BUTTON_B, INPUT); //custom services and characteristics can be added as well microbit.BTLESerial.begin(); microbit.BTLESerial.setLocalName("microbit"); // Start LED matrix driver after radio (required) microbit.begin(); } void loop() { microbit.BTLESerial.poll(); forward(); //loopback(); spam(); } // forward received from Serial to microbit.BTLESerial and vice versa void forward() { if (microbit.BTLESerial && Serial) { int byte; if (microbit.BTLESerial.available()) { Serial.write(microbit.BTLESerial.read()); } char buffer[10]; memset(buffer, 0x0, 10); int idx = 0; while (Serial.available() && idx != 10) { buffer[idx] = Serial.read(); idx++; } if (idx) { microbit.BTLESerial.write(buffer, idx); } } delay(1); } // echo all received data back void loopback() { if (microbit.BTLESerial) { int byte; while ((byte = microbit.BTLESerial.read()) > 0) { microbit.BTLESerial.write(byte); } } } // send button press void spam() { if (microbit.BTLESerial) { //microbit.BTLESerial.print(millis()); //microbit.BTLESerial.println("data"); if (! digitalRead(PIN_BUTTON_A)) { Serial.println("Button A"); microbit.BTLESerial.println("ButA"); } if (! digitalRead(PIN_BUTTON_B)) { Serial.println("BUtton B"); microbit.BTLESerial.println("ButB"); } delay(1000); } }
Now on the Beaglebone run the uart_service.py from the example folder , and once you see the transmission from the Beaglebone to Microbit saying 'Hello Bluetooth!', press the buttons on the Microbit and you should see them appear on the SSH teminal for the Beaglebone as shown in the screenshot below.
Video coming soon, edit is still a work in progress
Top Comments