Monday 26 September 2016

Microbit and junkbot?


What is a Junkbot?
For this project, it is a moving ‘bot’ made from waste materials, combined with an electric motor and a programmable device (in this case a Micro:Bit) to control (or try) it. An example is shown below. More details on junkbots can be found at http://junkbots.blogspot.co.uk/


Stage 1 - The start of a Junkbot
This stage is relatively simple. Tape some pens or straws to a drinks can.




Stage 2 - Physical arrangement of Microbit and motor control board

The control part is this via a Micro:bit (http://www.bbc.co.uk/programmes/articles/4hVG2Br1W1LKCmw8nSm9WnQ/the-bbc-micro-bit). Kitronik produce a motor driver board, and provide quite a bit of support for it, for the Micro:Bit (the latest version of the board can be found at https://www.kitronik.co.uk/5620-motor-driver-board-for-the-bbc-microbit-v2.html ). A 6v battery pack is connected (see on the left of the image) and wires going to a motor are attached to the first block on the front left (marked as motor A).



The overall arrangement is show below, including a broken propellor as an unbalanced load to make the motor vibrate - the propellor was to hand but if you can secure something a clothes peg this could be used.


Stage 3 - Built Junkbot
Now we just need to put them together by taping (or fixing somehow) the motor to the junkbot built in stage 1. A further possibility is to attach the Micro:Bit, motor driver board and battery pack to the junkbots; but this adds weight.








Stage 4 Code
 Using Micropython via the online editor https://www.microbit.co.uk to program the board and therefore the junkbot. 
An example piece of code is shown below:

from microbit import *

def startIt():
   pin8.write_digital(1)
   pin12.write_digital(0)
   pin0.write_digital(1)
   pin16.write_digital(0)    

def leftTurn(duration):
   pin8.write_digital(0)
   pin12.write_digital(1)
   sleep(duration)
   
def stopIt():
   pin8.write_digital(1)
   pin12.write_digital(1)
   sleep(2000)

while True:
   startIt()
   
   if button_a.is_pressed():
       leftTurn(100)
   
   if button_b.is_pressed():
       stopIt()

Unplug the Micro:bit from the motor driver board and download the code to the microbit. Unplug the download cable and plug the Micro:Bit back into the motorboard, with the battery pack attached there is enough power for the Micro:Bit and the motor - don't plug in any other power including the programming cable when it is in the motor driver board.


Stage 5 In action



Suggested Resource List
  • Small Electric Motor
  • Kitronik Motor Board
  • Battery Pack
  • BBC Micro:bit
  • Pens
  • Junk (Can or Bottle)
  • Wires
  • Tape
  • Scissors
  • Broken Propeller or un-balanced load
  • Screw Driver

Stage 6: More control
In the remained of this post I want to show a modification to it, to use one Micro:Bit to control the junkbot controlled by another Micro:Bit. A nice feature of the Micro:Bit using micropython, is it can send and receive simple messages via radio - so here is my take on it.

The first problem is the Python editor available on https://www.microbit.co.uk/ does not seem to work with the radio API. One solution to this is to change to the mu editor.


Two pieces of code are needed.

Stage 7 Sending Code for the 'remote' control:
Essentially it is set up to send two messages, via the built-in radio module, spinl or spinr depending on which button is pressed.

import radio
from microbit import button_a, button_b

radio.on()

while True:
   if button_a.is_pressed():
       radio.send('spinl')
   if button_b.is_pressed():

       radio.send('spinr')

Satge 8 Junkbot Code
This takes an adapted form of the previous Junkbot code to work by; on receiving spinl or spinr via the radio link; spin the motor clockwise or anticlockwise.
import radio
from microbit import pin8, pin12, sleep

def leftTurn(duration):
   pin8.write_digital(0)
   pin12.write_digital(1)
   sleep(duration)
   
def rightTurn(duration):
   pin8.write_digital(1)
   pin12.write_digital(0)
   sleep(duration)
   
def stopIt():
   pin8.write_digital(0)
   pin12.write_digital(0)

radio.on()
while True:
   incoming = radio.receive()
   if incoming == 'spinl':
        leftTurn(500)
        stopIt()
   if incoming == 'spinr':
        rightTurn(500)
        stopIt()







All views are those of the author and should not be seen as the views of any organisation the author is associated with.

Answers not on the Screen

  2.  The answers not on the screen Hill, G. ,  Turner, S. J.  and  Childs, K.  (2017)  Abstract:  Reflection from two areas on the issues...