My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.

Adding Bluetooth Remote Control To :MOVE mini

Our :MOVE mini kit offers a great introduction to robotics, it can be used in a number of different ways that are mainly facilitated by the code that you place onto the microbit. In this resource we’d like to show you how to add Bluetooth remote control to :MOVE mini.

intro pic

Adding Bluetooth functionality to :MOVE mini is as easy as putting some code onto the microbit and downloading the Bitty Software controller App for an iOS/Android device.  You will find the download and links at the foot of this resource.

 

Kitronik Custom Blocks For The Microbit Javascript Block Editor:

Kitronik has created some custom blocks for the microbit PXT Javascript Block editor. These can be found in the Kitronik github. For the Servo:Lite board, the address is:

https://github.com/KitronikLtd/pxt-kitronik-servo-lite

In the JavaScript Block editor click the ‘Advanced’ button in the toolbox, then click the ‘Add Package’ button and type in the github URL. Press the search magnifying glass and the package should appear:

add-package-pxt-editor-microbit

Simply click on it to add it to the project. You will now have access to the following blocks:

kitronik-servo-lite-blocks-1000

In order to be able to take advantage of the microbits Bluetooth functionality we have to first add the Bluetooth package. Select Add Package from the menu and then select Bluetooth. Whenever you write code and the Bluetooth module is enabled, when you press download your code will be compiled with the commands to activate Bluetooth services on the microbit included.

We are now ready to write some code.

 

Writing The Code:

As we are going to control :MOVE mini with a phone App over Bluetooth we need to code the microbit so that it responds in the right way when it receives Bluetooth commands.

on-even-block

All of our remote control code is going to be placed within an ‘on event’ loop, as shown above. You can find the on event loop by expanding the Advanced menu option, you can then find the loop in the Control menu.

This will ensure that the microbit knows to expect commands from the DPad controller and what to once it receives them. We are going use the A, B, C & D buttons in the App for driving, you can see how they are orientated on the App pads in the image below.

dpad-on-mobile-device

Our controls will be:

  • A – Forwards.
  • B – Backwards.
  • C – Left.
  • D – Right.

As well as writing our code to respond to a button press, we also need to write code for what to do when the button is released. For our code, button release will always equal stop.

example-movement-code

In the code above you can see how the code for the A button press works. When the A button is pressed, the buggy will drive forwards. When the A button is released, the buggy will stop.

We follow the same procedure for the other three button presses, just altering the drive command type for each.

We also want to write code to give some visual feedback via the microbits LEDs as to whether Bluetooth is connected or not. If the Bluetooth connection is dropped, ideally, we would want the buggy to stop regardless of the last command. The stop command acts as a failsafe to protect the system if control fails.

connected-not-connected-smileys

The code above will display a smiley face on the microbit when Bluetooth is connected, if for any reason the connection is lost then a sad face will display and the servos will stop turning.

In the screenshot below you can see the whole program. Once you grasp how the on event block works and how to define an on event value the code is uncomplicated to produce.

bluetooth code

 

Downloads & Information:

We used the Bitty Software game controller, you can find the links to the Apps in the list below.

You can download our code here.

Note: Unzip the file and either drag the HEX file into the PXT editor for editing or connect your microbit to your computer and drop the file directly onto your microbit via your file explorer. The microbit should show up as a removable drive.

Robox 3D Printer
← Previous Post Next Post →

Leave a Reply