Showing posts with label microbit. Show all posts
Showing posts with label microbit. Show all posts

Sunday 18 December 2016

4Tronix Bit:Bot - now there is a good idea.

When I first heard of this robot, my first thought was what a great idea; a robot with neopixels (I know I should be saying 'smart RGB LEDs' but neopixels is so much more snappier) controlled via a micro:bit.





A good starting point for learning more about this robot, is the details on the 4Tronix site/blog, which includes build guidance and programming instructions for micropython and PXT. Though for the micropython code you might need to change pinX.digital_write() to pinX.write_digital() where X is the pin number.

My play code was to randomly select which neopixels to light up, I didn't include code to turn them off so multiple ones can be on. The robot is driven forwards, waits, backward, waits, turns to the right and then the left; and then repeats. 

Code:
from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin13, 12)

def forward(n):
    pin0.write_digital(1)
    pin8.write_digital(0) 
    pin1.write_digital(1)
    pin12.write_digital(0)
    sleep(n*1000)
    
def halt(n):
    pin0.write_digital(0)
    pin8.write_digital(0)
    pin1.write_digital(0)
    pin12.write_digital(0)
    sleep(n*1000)
    
def backward(n):
    pin0.write_digital(0)
    pin8.write_digital(1) 
    pin1.write_digital(0)
    pin12.write_digital(1)
    sleep(n*1000)

def right_turn(n):
    pin0.write_digital(1)
    pin8.write_digital(0) 
    pin1.write_digital(0)
    pin12.write_digital(1)
    sleep(n*1000)

def left_turn(n):
    pin0.write_digital(0)
    pin8.write_digital(1) 
    pin1.write_digital(1)
    pin12.write_digital(0)
    sleep(n*1000)

while True:
    pxl=random.randint(1,11)
    rd=random.randint(1,32)
    gr=random.randint(1,32)
    bl=random.randint(1,32)
    t1=random.randint(10,100)
    np[pxl] = (rd, gr, bl)
    np.show()
    forward(1)
    halt(1)
    backward(1)
    halt(1)
    right_turn(1)

    left_turn(1)

The video below shows it in action, the code is simple but this is a lovely robot to program especially if the mu editor is used.




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

Monday 31 October 2016

Simple (and temporary) Halloween Hack


This really is a simple one. A Glowbug (or a NeoPixel) with the data in, Ground and 5v connected pushed into the neck of the balloon, then inflated the balloon. The neck of the balloon and wires are twisted tightly and insulating tape used to provide a bit of a seal.

The data in wire is connected to Pin 0 of a Micro:Bit and the other two wires are attached to the corresponding connections of the Micro:Bit. The code below randomly selects the colours and the length of the delay before changing colour.

from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin0, 1)

while True:
    rd=random.randint(1,254)
    gr=random.randint(1,254)
    bl=random.randint(1,254)
    t1=random.randint(200,2000)
    np[0] = (rd, gr, bl)
    np.show()
    sleep(t1)

The problem is a slow leak means it only stays inflated for a short while.


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

Monday 24 October 2016

Dancing pixels

In previous post I played with using the combination of the Proto-Pic Micro:pixel and Micro:Bit to react, using the accelerometer, to music through a computer speakers. The vibrations from the music shake the Micro:Bit enough to give measurable changes in three axis, and these values are used to change the pixels colour.



The latest version of this uses most of pixels.




Coded in micropython using the Mu editor.

from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin0, 32)

while True:
    for pxl in range (2,32, 5):
        rd=int(abs(accelerometer.get_x())/20)
        gr=int(abs(accelerometer.get_y())/20)
        bl=int(abs(accelerometer.get_z())/20)
        np[pxl] = (rd, gr, 0)
        np[pxl-1] = (rd, gr, 0)
        np[pxl+1] = (0, gr, rd)
        np[pxl-2] = (rd, 0, 0)
        np[pxl+2] = (0, gr,0)
        np.show()

Video of it action, using royalty-free music Electro Deluxe by My Free Mickey feat. Gurdonark. http://dig.ccmixter.org/files/myfreemickey/48180





As one of the reviewers on Proto-Pic site states, the box the Micro:pixel comes in does make a good diffuser.

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

Saturday 22 October 2016

Microbit + Micro:pixel reacting to music

This post discusses a simple way to get the Micropixel-Micro:Bit combination to change the Neopixels based on the music. Using the accelerometer on the Micro:Bit to provide x,y,z values to provide colour values for the neopixels; the micropixel sits over the speaker and vibrations are picked up. 

Simple but it roughly works (see the video at the end of the post).


Code
from microbit import *
import neopixel, random

# Setup the Neopixel strip on pin0 with a length of 2 pixels
np = neopixel.NeoPixel(pin0, 32)

while True:
    pxl=11
    rd=int(abs(accelerometer.get_x())/20)
    gr=int(abs(accelerometer.get_y())/20)
    bl=int(abs(accelerometer.get_z())/20)
    t1=10
    np[pxl] = (0, 0, bl)
    np[pxl-1] = (rd, gr, 0)
    np[pxl+1] = (0, gr, rd)
    np[pxl-2] = (rd, 0, 0)
    np[pxl+2] = (0, gr,0)
    np.show()
    sleep(t1)
    np[pxl] = (0, 0, 0)
    np[pxl+1] = (0, 0, 0)
    np[pxl-1] = (0, 0, 0)
    np[pxl+2] = (0, 0, 0)
    np[pxl-2] = (0, 0, 0)


Video of it action using Revolve by cinematrix available under Creative Commons Licence (http://ccmixter.org/files/hisboyelroy/430 ).





Always obey the safety advice provided by Micro:bit https://microbit0.blob.core.windows.net/pub/jedfednb/Parent-and-Teacher-micro-bit-safety-guide.pdf 



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

Disco micro:pixel


In a previous post Proto-Pic board, Microbit and Micropython I played with the Proto-Pic micro:pixel 4x8 NeoPixel board. 

This post is just a short description of a quick play with making it flashing blocks of different colours across the board. The routine produces five random numbers (three to define the colours, one for which pixel is selected and the last for the delay each iteration). The idea of being - a pixel is selected, but so are the ones either side of it, each one has a different combination of the colour values, but only two of the pixels are turned off after the delay.

from microbit import *
import neopixel, random

# Setup the Neopixel strip on pin0 with a length of 2 pixels
np = neopixel.NeoPixel(pin0, 32)

while True:
    pxl=random.randint(1,30)
    rd=random.randint(1,32)
    gr=random.randint(1,32)
    bl=random.randint(1,32)
    t1=random.randint(10,100)
    np[pxl] = (rd, gr, bl)
    np[pxl-1] = (gr, bl, rd)
    np[pxl+1] = (bl, rd, gr)
    np.show()
    sleep(t1)
    np[pxl] = (0, 0, 0)
    np[pxl+1] = (0, 0, 0)

The video below shows the routine in action. There is no connection between the pixels and the music on the video - but making the connection between music and the pixels would be an interesting project.




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

Thursday 20 October 2016

micro:pixel board, micro:bit and micropython

A new (or to me at least)  addition to devices you can attach a Micro:Bit to, is the Proto-Pic micro:pixel 4x8 NeoPixel board; essentially a board with 4 x8 grid of NeoPixels that you plug the Micro:Bit into. Following the advice of the website the  values of RGB are all set to 32 or below to avoid pulling too much power. Pin0 is used to write to. You will need to use the Mu editor for this.





Two tests were tried

Example 1: To get the pixels to appear to light up from the last to the first one.

from microbit import *
import neopixel

np = neopixel.NeoPixel(pin0, 32)


while True:

    for x in range(0, 32):
        for y in range(0, (32-x)):
            np[y] = (y, 32-y, 1)
            if (y>0):
                np[y-1]=(0,0,0)
            np.show()
            sleep(30)




Example 2: To randomly select a pixel and its colour.

from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin0, 32)

while True:

    pxl=random.randint(0,31)
    rd=random.randint(1,32)
    gr=random.randint(1,32)
    bl=random.randint(1,32)
    np[pxl] = (rd, gr, bl)
    np.show()
    sleep(500)
    np[pxl] = (0, 0, 0)




This is a good, fun board to play with; relatively easy to use.





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

Monday 3 October 2016

Playing with 4Tronix's Micro:bit Playground

As much as I like the simplicity and flexibility of Crocodile Clips connecting components to a Micro:Bit, it can get a bit of a rat's nest of wires (especially if you are as messy as I am!). 4Tronix's have released their Micro:Bit PlayGround (http://4tronix.co.uk/store/index.php?rt=product/product&path=89&product_id=580)which is a board that has 3.5mm jack plugs to connect to a range of Gizmos (their phrase not mine) to which the Micro:Bit is screwed into. The battery pack is integrated onto the board on its back (see image below)



The Micro:Bit screws into the PlayGround via five screws which also for the connection between the PlayGround and the 'bit'. 

Below via the three cables connecting 3.5mm plugs, I have attached a 'Dial' (a potentiometer ) and two Flames (neopixels) to change the LED/neopixel's colours by rotating the Dial. Pin 0 has the 'Dial' attached and Pin 1 has the two Flames (neopixels) attached the out from the first goes in as input of the second via one the cables. 





Code
Essentially vary the 'Dial' varies the R,G,B values going to the two Flames/neopixels and so varying their colours. The code used is shown below.

from microbit import *
import neopixel

# Setup the Neopixel strip on pin0 with a length of 2 pixels

np = neopixel.NeoPixel(pin1, 2)

while True:

    s1=int(pin0.read_analog()/5)
    np[0] = (255, s1, 255-s1)
    np[1] = (s1,255, 255-s1)
    np.show()





Video of it in action





Thoughts
I like the idea that the cable doing both the power and control for the Gizmos, it does simplify building a little, more importantly it does produce less clutter (not so many wires). The whole unit with the batteries installed is a little weighty but that does give it at the same a sense of sturdiness which is a positive feature for just playing around  - you wouldn't use it for wearables. Not using croc clips also avoids issues with the clips slipping off with rough handling. 

Nice little arrangement which I am enjoying playing - is for everyone? Probably not, but does provide a sturdy system to experiment with some standardised units.


Related Links
Micro:Bit Playground - Starter Kit
Traffic lights - Microbit, GlowBugs and 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

Saturday 17 September 2016

Python Junkbot - PyCon UK 2016

Poster presented at PyCon UK 2016, 17th September 2016.



Pyconuk16 junkbots from Scott Turner

DOI: 10.13140/RG.2.2.28682.67520

For more details on the three builds:






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

Sunday 11 September 2016

Do it yourself: Remote Controlled Micro:Bit Junkbot

In an earlier post, I showed how you could build a Micro:Bit controlled Junkbot. In 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.

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

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 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.

How to do it yourself: Microbit 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


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.

Friday 2 September 2016

Matthew takes control of robot research project

Taken from: http://www.northampton.ac.uk/news/matthew-takes-control-of-robot-research-project/




Matthew Hole
A sixth-form student has spent the summer at the University of Northampton investigating the possibility of controlling DIY robots with a computer half the size of a credit card.
Matthew Hole, who attends Wrenn Academy in Wellingborough, has been awarded a Nuffield Research Placement – a scheme which offers sixth formers the chance to work on university research projects during the summer.
During his time at the University, Matthew used a BBC micro:bit computer  to control a junkbot – a robot made from junk, such as a drinks can, powered by a kit.
Junkbots have previously been controlled by a Raspberry Pi computer, but the University’s Associate Professor in Computing and Immersive Technologies, Dr Scott Turner, saw the potential to harness the micro:bit.
“The micro:bit has been given away free to every Year 7 pupil in the UK, so it made sense to investigate how well it could control a junkbot.
“Matthew worked incredibly hard on the research project, overcoming several problems, and was successful in harnessing the micro:bit to control a junkbot.
“He used his experience to produce an action pack, which will be available for schools to refer to so that pupils can learn how to control a junkbot with the micro:bit – so Matthew’s research has the potential to benefit thousands of young people across the UK and beyond.”
Matthew said: “The project has definitely helped me to develop my problem solving skills: I’ve learnt how to break projects down into small pieces and work on them methodically, which has been really useful,” said Matthew, who has received a bursary to carry out his work.
“To be able to work on an action pack that will be available for schools to use is also a fantastic thing to have on my CV.”

To learn more about the junkbots project contact: scott.turner@northampton.ac.uk or go to http://robotsandphysicalcomputing.blogspot.co.uk/2016/08/creating-microbit-junkbot-for-use-in.html





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.

Friday 19 August 2016

Micro:bit Junkbot for use in schools


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.

Top posts on this blog in March 2024

The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots. Micr...