Tuesday, 27 September 2016

Mini Project: robot talks to UFO

CBiS Education generously sent me two of their new range of robotics development kits - Consumable Robotics (consumable-robotics.com) to try out. These are a range of cardboard based robotics kits (so far a robot named Dimm, and a UFO) with electronic components for example LEDs; sensors and buzzers,  depending on the kits. 

What makes the kits interesting though, is they are designed to be controlled by either a BBC Micro:bit or a CodeBug. In previous posts elsewhere (UFO has Landed and DIMM the OOD)  I started playing with the CBiSEducation's UFO and Dimm consumable robots separately. Still using the Micro:Bit, in this post, using Micropython to send messages between the two kits is considered.






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

Micropython and the use of  the Micro:Bit's built in radio module (Bluetooth) provides a route for communication between the two kits.



Stage 2 Code - UFO
The code is set to switch on and off the UFO's LEDs, followed by scrolling 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 send "DIMM calling"
- 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):
   pin1.write_digital(0)
   pin0.write_digital(1)
   sleep(duration)
   
def pulseLed2(duration):
   pin1.write_digital(1)
   pin0.write_digital(0)
   sleep(duration)
   
def stopIt():
   pin0.write_digital(0)
   pin1.write_digital(0)

radio.on()

while True:
   incoming = radio.receive()
   stopIt()
   if incoming == 'dimm':   
      pulseLed1(1000)
      pulseLed2(1000)
      stopIt()
      radio.send("ufo")
      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

radio.on()

while True:
   if button_a.is_pressed():
       radio.send('dimm')
       radio.send('not')
       
   if button_b.is_pressed():
       radio.send('ufo')
       radio.send('not')

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

 


Stage 5 Build

Now the focus moves to Dimm and the setting up the actions leading to the messages being passed.

Set-up is relatively easy. Using the Micro:bits port 0 (as part of the Dimm robot) for the input from the light sensor, which is included in the kit (Red lead going to 3v and the black lead going to GND), we now have light detecting ability . Just to note the less light there is the higher the value on the sensor.




Stage 6 Code
Micropython programmed through the Mu editor (see below)

If light levels are high then :
      scroll a message saying "calling UFO" 
      send the code "dimm" via bluetooth.
otherwise: 
      scroll a message saying "I can't see"
If it recieves "ufo" via bluetooth :
      display "Hello, UFO called me"

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

radio.on()

while True:
   incoming = radio.receive()
   if incoming == 'ufo':  
      display.scroll("Hello, UFO called me", 75)
   if pin0.read_analog()<175: font="">
        display.scroll("calling UFO")
        radio.send("dimm")
   else:
        display.scroll("I can't see")

Stage 7 Testing

Video below shows it in action.

  • When the light (in this case a torch) shines on the sensor connected to Dimm; a message is sent and picked up by the UFO kit (LEDs flash and the message saying "DIMM calling" scrolls  across the UFO LED array). A message is sent from the UFO kit and on Dimm's LED array scrolls the message "Hello, UFO called me").
  • If the light levels are too low, then the message "I can't see" scrolls across Dimm's LED array.









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

If you'd like to find out more about Computing at the University of Northampton goto: www.computing.northampton.ac.uk. All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with

No comments:

Post a Comment