About this project

 

We end our 'ten projects' series with a very simple exercise that demonstrates how to make two BBC micro:bit devices communicate with each other.

 

What you'll need

 

2 x BBC micro:bit devices

1 x Micro USB

1 x Computer or tablet

2 x AAA Batteries & Battery Holder

4 x Crocodile Clips

 

 

Project walkthrough

 

 

  • Select two 'if/do' tiles from the Logic commands menu, add an 'else' option to both by clicking the blue cog icon, and connect them in a 'forever' loop.

 

BBC micro:bit

  • The first 'if/do/else' tile will be used to send a message from your BBC micro:bit to the device it's connected to.

 

  • Drag in a 'button [A] is pressed' tile from the Input commands menu and attach it next to 'if'.

 

  • For 'do', got to the Pins menu and attach a 'digital write (0,1) [1] to pin [P0]' tile. Set the pin to [P1] in the right dialog box.

 

  • Add a second 'digital write...' tile next to 'else', also changing the pin to [P1] and setting the value in the left dialog box to [0], like so...

 

BBC micro:bit

 

 

  • When you press button A now, your device will send a current through pin P1. Otherwise, there will be no current through this pin. When your device is connected to your partner's BBC micro:bit via the crocodile clips, this is how they will communicate.

 

  • Next you need to tell your device what to do when it receives a message from your partner's BBC micro:bit, in the form of the aforementioned current. For the purposes of this project, we're just going to create a simple telegraph - meaning that when your BBC micro:bit receives the message from the connected device, it will flash up a light on the LED.

 

  • In the second 'if/do/else' block, attach a '[0] = [0]' tile from the variables menu.

 

  • In the left dialog box, attach a 'digital read pin (0,1) [P0]' tile and set the dropdown to P2.

 

  • Change the value in the right dialog box to 1.

 

BBC micro:bit

 

  • Your device now knows that when it receives an active current through pin P2 - via the second BBC micro:bit - it needs to perform an action.

 

  • From the LED commands menu, attach a tile that reads 'plot x [0] y [0]', attach next to 'do' and change value in both of the dialog boxes to [2].

 

  • Next to 'else' attach a tile that reads 'unplot x [0] y [0]' and also set the values in both dialog boxes to [2]

 

BBC micro:bit

 

  • Now, when your device receives a current through pin P2, it will flash the LED at co-ordinates X2, Y2.

 

  • Make sure this code is compiled and downloaded to both BBC micro:bits.

 

  • To connect the two BBC micro:bits, take your first pair of crocodile clips and attach each end to the GND pin on both devices.

 

  • Attach your second pair of crocodile clips to the 3V pin on each device.

 

BBC micro:bit

 

  • Take your third pair of crocodile clips and attach one end to Pin 1 on your first BBC micro:bit. Connect the other end to Pin 2 on the second device.

 

  • Do the reverse with your fourth and final pair of crocodile clips. attaching one end to Pin 2 on the first device, and the other to Pin 1 on the second.

 

  • Your devices are now ready to communicate! Make sure your code is downloaded to both devices, and hit button A to start communicating!

 

BBC micro:bit

 

Once your students have completed this project, what can they do to make communication between the two devices more interesting? Can they figure out how to trigger sound effects, or to build two-player arcade style games similar to the falling sprite challenge from day five? Let us know what ideas they come up with in the comments section below.