Showing posts with label micro:bit. Show all posts
Showing posts with label micro:bit. Show all posts

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

Thursday, 15 September 2016

Python Junkbot - PyCon UK 2016

Poster to be present at PyCon UK 2016



Pyconuk16 junkbots from Scott Turner

For more details on the three builds:




If you'd like to find out more about Computing at the University of Northampton go to: 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

Sunday, 21 August 2016

Miniproject: Micro:bit can now control a junkbot


A new direction has been developed for the junkbot project (
http://junkbots.blogspot.co.uk/); previously Raspberry Pis have been used to control the junkbot’s movement (http://robotsandphysicalcomputing.blogspot.co.uk/2016/01/python-junkbot.html) – but what about the recently released Micro:Bits; can it be used to control a junkbot?

Matthew Hole, a student from Wrenn Academy, Northamptonshire ; has been investigating this idea whilst on a Nuffield Research Placement (http://www.nuffieldfoundation.org/nuffield-research-placements) working with Dr Scott Turner, University of Northampton. The project was to look into developing junkbots controlled using a Micro:bit and also to produce some materials for schools to use with or without outside assistance.






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 above. More details on junkbots can be found at http://junkbots.blogspot.co.uk/


Approach used in the project.
A Micro:Bit was selected for two reasons. First, there was been a BBC supported project to give year 7 (or equivalent) students a Micro:bit (http://www.bbc.co.uk/programmes/articles/4hVG2Br1W1LKCmw8nSm9WnQ/the-bbc-micro-bit), so they are available in the schools. Secondly, 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 ). Using Micropython via the online editor https://www.microbit.co.uk to program the board and therefore the junkbot connected. The board with the Micro:Bit attached can be seen in the figure above carried on 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()



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


Related Links


           



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.If you'd like to find out more about Computing at the University of Northampton go to: 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

Friday, 8 April 2016

mini-projects: Play with micro:bit software - dancing bot (update)


The micro:bit (https://www.microbit.co.uk/about) has been in the press quite a bit recently - rightly so. 

At the moment I have not got my hands on an actual one, though someone generously (more in later posts on that) will be lending me one to play with. 


Luckily you do not need the device to start playing; the code editor (https://www.microbit.co.uk/create-code) has an emulator built in, so you can start playing. This post reports on my first go.

So, I am starting with experimenting with the editor, using Microsoft's Block Editor - which is similar to Blockly and Scratch as an interface.





What I built is simple but that is fine - A dancing bot - 3x3 box for the body, with two legs. I wanted to play with getting some interaction that uses the buttons (A and B) and shaking. So the functions for the idea were:


  • Button A - make it bob up and down;
  • Button B - makes it move to the left and right;
  • Shaking it - makes it appear to jump and land (see below);
  • Button A+B together makes it do one of the moves of up, down, left and right.




The video below shows it action. 


 

The other nice thing is go convert to the Microsoft touch Developer version (see below) with a click.








Now to be repeat most of this just using events.


So the functions for the idea were:


  • Button A - make it bob up and down;
  • Button B - makes it move to the left and right;






  • On shake - make it jump up and down.





 



Thanks to a loan of a Micro:Bit from Lancaster University I can experiment with an actual micro:bit ( )

Experiment  1 - Using the buttons

So the functions for the idea were:

  • Button A - Move to the left and then back to the starting position;
  • Button B - Move to the right and then back to the starting position;
  • Buttons A+B - Jump up and then back to the starting position;
  • Shake - 'Crouches' and then back to the starting position


On the Microbit

 







Experiment 2- To add left and right tilting to it.
So if the micro:bit is tilted to the right the 'bot'  moves to the right, and the same for the left.

The tilting operation here is essentially - when the x on the accelerometer is less than zero move the 'bot' to the left and when it greater than zero go to the right.

Video showing it in action






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.