UFO talks to Robot - part one

In previous posts (UFO has Landed and DIMM the OOD),  I started playing with the CBiSEducation's UFO consumable robots. Still using the Micro:Bit, in this two part post series, I am going to be playing with using Micropython to send messages between the two kits.

Stage 1 Wiring and Set up-UFO
Pins 0 and 1 are outputs to the LEDs
The black leads on the UFO go to GND.

Micropython, using the Micro:Bit's built in radio module (Bluetooth), is used to communication between the two kits.

Stage 2 Code -UFO
The code is set to flash the UFO's LEDs and then scroll a message "DIMM Calling" when it receives a message "dimm" via Bluetooth. 

Basic overview is
- Turn on the radio module - radio.on()
- If the message is received then turn the LEDs on and off and scrolls "DIMM calling" across the LED array.
- send a message via bluetooth "ufo" to whoever is listening (in the end the robot DIMM hopefully). The code is shown below. 

import radio
from microbit import pin0, pin1, display, sleep

def pulseLed1(duration):
def pulseLed2(duration):
def stopIt():


while True:
   incoming = radio.receive()
   if incoming == 'dimm':   
      display.scroll("DIMM calling")

To use the radio module you will need to switch to the mu editor (http://codewith.mu/).

Stage 3 Testing it
To test it, a second Micro:bit was used to send test signals (the code for this is shown below). When button A is pressed on the second Micro:Bit a message 'dimm' is sent followed by sending 'not'.

import radio
from microbit import button_a, button_b, sleep


while True:
   if button_a.is_pressed():
   if button_b.is_pressed():

The UFO does cycle through the sequence LEDs flash and the message scrolls. The slight bug is in repeats it several times before it stops; possibly a buffering issue somewhere.

Stage 4 
In the next post (http://bit.ly/2d3zlh0), I will be building the Robot DIMM part of the system - sending and receiving message and detecting light levels in micropython.

All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

No comments:

Post a Comment