[2020] Using IPhone or IPad and Micro:bit Game Pad App to Control an RC Car

by hummingworks in Circuits > Remote Control

2841 Views, 9 Favorites, 0 Comments

[2020] Using IPhone or IPad and Micro:bit Game Pad App to Control an RC Car

Valenta App.png

Have you thought of using your iPhone or iPad for controlling your micro:bit?

Do you know Micro:bit Educational Foundation provides the iOS app in the App store? Search "micro:bit" in the App store and you can download the app for free. The app uses Bluetooth for pairing your iOS devices and micro:bits and it can transfer MakeCode files. What's more, the app lets your iPhone or iPad to become the Game Pad for your micro:bit!

Sounds fun? How can we enjoy it?

Why don't you try this project? You can remotely control your micro:bit powered RC car with the Game Pad app on your iPhone or iPad!

In this tutorial, we will present how to set up the iOS app on your iPhone or iPad, how to pair it with your micro:bit, and how to use the Game Pad controller in the app for controlling micro:bit powered RC car. We will provide the ready-to-play MakeCode sample file and its tutorial. We will examine each block of code and analyze how it works. You can also view this tutorial on YouTube.

Supplies

Devices and Apps

You will need an iOS device (iPhone or iPad) in this project. Make sure you've downloaded the iOS app in the App store. Please check your device compatibility with the app for using Bluetooth.

Electronics

You will need a micro:bit and an RC car in this project.

  • micro:bit x1
  • Valenta Off-Roader x1
  • 1.5V AA batteries x4 (for the car)

Valenta Off-Roader is a micro:bit powered Off-Road RC car. It is Lego Technic compatible and equipped with two (x2) micro gear motors on the rear wheels and (x1) built-in steering servo based on Roberval balance arm mechanism. Please refer to the tutorial for assembling the car. For batteries, we recommend using four (x4) new and single-use 1.5V AA batteries.

​Copying the MakeCode Sample File

Sample File PNG.png
Receiver Microbit Mount PNG.png

For this project, we have prepared the MakeCode sample file (Receiver.hex) so you can download. Since the sample file is ready to play, you can start playing immediately.

In this step, you can download the sample file to your computer. Connect your computer and the micro:bit via USB cable. Drag and drop the sample file to the micro:bit and use this as "receiver" micro:bit.

Once you've copied the sample file to the micro:bit, disconnect it from the computer. Then, mount the micro:bit on the Valenta Off-Roader and turn on the power switch on the motor controller board.

Downloads

Reviewing Micro:bit IOS App

App Top PNG.png

Have you downloaded the micro:bit iOS app to your iPhone or iPad? Go to the App store, search "micro:bit" and you can find the app provided by Micro:bit Educational Foundation.

When you open the app, you can see the top menu!

Tap Choose micro:bit button for pairing your micro:bit.

Pairing a Micro:bit

Pair New PNG.png

At this moment, you haven't paired any micro:bit to your iPhone or iPad. Click Pair a micro:bit yellow button.

Pressing the Buttons

Push Button PNG.png

In this step, you will need to do the following actions simultaneously.

  • Hold pressing the button A and the button B
  • Press and release the Reset button in the back

When the LED dots flash altogether, click Next button.

Tapping the LED Dots

LED match PNG.png

In this step, the app wants to identify the micro:bit that you want to pair. Tap each LED dot in the app just the way exactly as they are shown on the micro:bit LED matrix.

Pairing to the Device

Ready to Pair PNG.png

When you come to this step, click Next button.

Searching Via Bluetooth

Monitor and control PNG.png

During this step, please wait for a moment.

Check If Pairing Is Successful

Found PNG.png

Have you paired the micro:bit to your iPhone or iPad successfully?

Setting Up the Game Pad

Adding PNG.png

Let's set up the Game Pad controller!

Click Add (+) button and choose Game Pad in the list.

Playing With the Game Pad

Game Pad PNG.png

You've paired the micro:bit to your iPhone or iPad. The Game Pad controller is set up now.

Click Start button for playing!

Have you downloaded the MakeCode sample file to your micro:bit? Go back to the earlier step and copy Receiver.hex file to the micro:bit and use this as "receiver" micro:bit. It is ready to play and you can start driving the car immediately! Try these actions and master the road!

  • Pressing the button A -> the car going forward
  • Pressing the button B -> the car going backward
  • Pressing the button C -> the car turning left
  • Pressing the button D -> the car turning right

Removing the Micro:bit in the App

Removing PNG.png

The app allows you to set up multiple micro:bits simultaneously.

If you've paired too many micro:bits and if you want to remove one of them, go to the top menu and tap Choose micro:bit button. You can see the list of micro:bits you've paired previously. Tap Trash button to remove the micro:bit.

Removing the Micro:bit in the Bluetooth Setting

Setting Bluetooth PNG.png
Forget this device PNG.png
Forget OK PNG.png

We also recommend that you clean up the Bluetooth setting occasionally by removing the micro:bit(s) that you have saved previously.

To clean up the previously stored micro:bit(s) in the Bluetooth setting on your iOS device,

  • Go to Setting.
  • Go to Bluetooth.
  • Tap the micro:bit you want to remove.
  • Tap Forget This Device button.
  • Click OK button.

Reviewing the MakeCode Sample File

MakeCode PNG.png
Sample File PNG.png
Receiver PNG.png

Now we will examine how the block codes would work in this MakeCode sample file.

In the earlier step, you've downloaded the MakeCode sample file to your computer. Connect your computer and the micro:bit via USB cable. Open the MakeCode editor and click Import button. Open Receiver.hex file that you've copied to "receiver" micro:bit.

Checking If the Extensions Are Added

Extensions PNG.png
Extensions to add PNG.png
Bluetooth Ext PNG.png
Devices Ext PNG.png
Servos Ext PNG.png

In this project, we will need to include Bluetooth, Devices and Servos extensions in the editor. Click Extensions in the bottom of the menu. Click each extension one by one and add it to the menu.

Bluetooth extension

You will need to use bluetooth io pin service block in this extension. This block will allow other codes to work with digital and analog pins via Bluetooth communication.

Devices extension

You will need to use on gamepad button block in this extension. This block will let you assign an action to each Game Pad button in the iOS app.

Servo extension

You will need to use set servo range and set servo angle blocks in this extension. These blocks will allow a servo to define the rotation range of a servo, as well as to swing it to the desired angle.

On Start

On start PNG.png

on start block

This block is called initially at once when "receiver" micro:bit in turned on.

The block bluetooth io pin service will allow other codes to work with digital and analog pins via Bluetooth communication.

From the Functions extension, drag and drop call steer block inside on start block. It will call function steer block and the car's steering look straight ahead.

Function Steer

Steer PNG.png
Centering Servo PNG.png

Generally, the car's steering isn't always straight ahead because of its servo by default,. If you look at the car from above, the steering might be a little right or left. In the sample file, we will use this function for calibrating the servo angle to its central position, so that the car's steering look straight ahead.

Let's assume that the servo is attached to P2 pin on the motor controller. Let's configure that the servo swings from 0 to 180 degrees and its central angle is 90 degrees.

function steer block

In the Function extension, create a new function and call it function steer.

Create a new variable center in the Variables extension for setting the servo's central angle.

From the Servos extension, drag and drop this block such as set servo P2 range from 0 to 180 for setting the servo's rotation range from 0 to 180 degrees.

From the Servos extension, drag and drop another block such as set servo P2 to center.

Look at your car from above. How does it look?

  • If the steering is a little left, set center to 90 - 5 for offsetting -5 degrees to the right.
  • If its steering is a little right, set center to 90 + 5 for offsetting 5 degrees to the left.

Function Forward

Forward Block PNG.png

How can we set the direction and speed for the motors?

We have a micro gear motor M1 on the left rear wheel and another micro gear motor M2 on the right rear wheel.

How can we set a block in this function to let the car go forward?

function forward block

For the left rear wheel M1, we will use P13 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P13 to 0 so that M1 goes forward.

For the left rear wheel M1, we will use P12 for motor speed (max speed = 1023). From the Pins extension, drag and drop this block such as analog write pin P12 to 1023 so that M1 runs at its max speed.

For the right rear wheel M2, we will use P15 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P15 to 0 so that M2 goes forward.

For the right rear wheel M2, we will use P14 for motor speed (max speed = 1023). From the Pins extension, drag and drop this block such as analog write pin P14 to 1023 so that M2 runs at its max speed.

Function Backward

Backward PNG.png

How can we let the car go backward?

Simply copy all the blocks from the function forward and exchange the pin numbers used for direction and speed.

function backward block

For the left rear wheel M1, we will use P12 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P12 to 0 so that M1 goes backward.

For the left rear wheel M1, we will use P13 for motor speed (max speed = 1023). From the Pins extension, drag and drop this block such as analog write pin P13 to 1023 so that M1 runs at its max speed.

For the right rear wheel M2, we will use P14 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P14 to 0 so that M2 goes backward.

For the right rear wheel M2, we will use P15 for motor speed (max speed = 1023). From the Pins extension, drag and drop this block such as analog write pin P15 to 1023 so that M2 runs at its max speed.

Function Stop

Stop PNG.png

How can we stop the motors?

Simply copy all the blocks from the function forward and set the motor speed to 0 (no speed).

function stop block

For the left rear wheel M1, we will use P13 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P13 to 0 so that M1 goes forward.

For the left rear wheel M1, we will use P12 for motor speed (no speed = 0). From the Pins extension, drag and drop this block such as analog write pin P12 to 0 so that M1 stops.

For the right rear wheel M2, we will use P15 for motor direction. From the Pins extension, drag and drop this block such as digital write pin P15 to 0 so that M2 goes forward.

For the right rear wheel M2, we will use P14 for motor speed (no speed = 0). From the Pins extension, drag and drop this block such as analog write pin P14 to 0 so that M2 stops.

Assigning Actions to Button A

Game Pad PNG.png
Button A PNG.png

Now, let's define the actions for the button A on the Game Pad in the iOS app.

How about pressing the button A lets the car go forward, and releasing the button A lets the car stop?

on gamepad button A down block

From the Devices extension, drag and drop on gamepad button A down block.

From the Functions extension, drag and drop call forward block and put it inside this block.

on gamepad button A up block

From the Devices extension, drag and drop on gamepad button A up block.

From the Functions extension, drag and drop call stop block and put it inside this block.

Assigning Actions to Button B

Game Pad PNG.png
Button B PNG.png

Now, let's define the actions for the button B on the Game Pad in the iOS app.

How about pressing the button B lets the car go backward, and releasing the button B lets the car stop?

on gamepad button B down block

From the Devices extension, drag and drop on gamepad button B down block.

From the Functions extension, drag and drop call backward block and put it inside this block.

on gamepad button B up block

From the Devices extension, drag and drop on gamepad button B up block.

From the Functions extension, drag and drop call stop block and put it inside this block.

Assgining Actions to Button C

Game Pad PNG.png
Button C PNG.png

Now, let's define the actions for the button C on the Game Pad in the iOS app.

How about pressing the button C lets the car turn left, and releasing the button C lets the car stop?

Let's assume that the servo is attached to P2 pin on the motor controller.

on gamepad button C down block

From the Devices extension, drag and drop on gamepad button C down block.

From the Servos extension, drag and drop this block and set it such as set servo P2 angle to center + 10, so that the steering turns +10 degrees to the left from its central position.

From the Functions extension, drag and drop call forward block and put it inside this block.

on gamepad button C up block

From the Devices extension, drag and drop on gamepad button C up block.

From the Functions extension, drag and drop call steer and call stop block and put it inside this block. The car will look straight ahead and stop.

Assgning Actions to Button D

Game Pad PNG.png
Button D PNG.png

Now, let's define the actions for the button D on the Game Pad in the iOS app.

How about pressing the button D lets the car turn right, and releasing the button D lets the car stop?

Let's assume that the servo is attached to P2 pin on the motor controller.

on gamepad button D down block

From the Devices extension, drag and drop on gamepad button D down block.

From the Servos extension, drag and drop this block and set it such as set servo P2 angle to center - 10, so that the steering turns -10 degrees to the right from its central position.

From the Functions extension, drag and drop call forward block and put it inside this block.

on gamepad button D up block

From the Devices extension, drag and drop on gamepad button D up block.

From the Functions extension, drag and drop call steer and call stop block and put it inside this block. The car will look straight ahead and stop.