Wednesday 22 March 2017

Mini project: Controllable (sort of) junkbots

What is a Junkbot?
It is basically, an electric motor that is unbalanced, so that is shakes and makes junk (e.g. a drinks can, a plastic cup) move. An example is shown below. As this blog is Computing in Northamptonshire it might be interesting to add-in some control (well sort of).

Three approaches to control it will be considered here:
- via Raspberry Pi;
- via Micro:Bit;
- via Crumble Controller.


1. Raspberry Pi based

One way is to combine a Raspberry Pi with a Junkbot in combination with Python and Pimoroni's Explorer HAT PRO to control it. 

First step, before the Explorer HAT can be used the appropriate library needs to be installed via the Terminal and the instructions below

curl get.pimoroni.com/explorerhat | bash

A simple bit of Python Code to control it is shown below.


import explorerhat
from time import sleep

def spin1(duration):
    explorerhat.motor.one.forward(100)
    sleep(duration)
    explorerhat.motor.one.stop()

def spin2(duration):
    explorerhat.motor.one.backward(100)
    sleep(duration)


    explorerhat.motor.one.stop()



2. Micro:bit
What about the recently released Micro:Bits, can it be used to control a junkbot?

2.1 Introduction
The project was to look into developing junk bots controlled using a Micro:Bit and also to produce some materials for schools to use with or without outside assistance.









2.2 Approach used in the project.
A Micro:Bit was selected for two reasons. 


An example piece of code is shown below. Press the buttons to spin the motor either anticlockwise or clockwise (depending on the wiring) and stop:

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()

2.3 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

3. Crumble



 The Crumble Controller, Redfern electronics, is an excellent board for this project; it is relatively cheap, it is programmable with it's own graphical language, and it has motor drivers built in. In the figure to the left the parts (apart from adhesive tape) used can be seen.


3.1. Wiring up
Using croc-clips ideally, but loops of wire if not, connect the battery to the controller and also the motors to the controller. Plug in the USB cable into the controller and the computer.

3.2. Running and Controlling
Make sure the Crumble software  (http://redfernelectronics.co.uk/crumble/) is installed on the computer. 

An example is shown below that drives the motor forward and then backward repeatedly. You might need to change the percentage values based on experiment, for the motor used. 




4. Future Directions

  • In all three approaches, a further motor can be driven so adding a second motor is one development.
  • Playing with a less well-featured motor driver board for the Micro:Bit or Raspberry Pi approaches may bring the cost down further.



Related Links



All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruon

No comments:

Post a Comment