Skip to main content

Posts

Showing posts with the label micropython

Hug Avoider 4 - micropython, Eggbot and speech

The last of the posts on the Hug avoider and the 4Tronix's Eggbit 4Tronix's Eggbit (in fact I bought three of them  https://shop.4tronix.co.uk/collections/bbc-micro-bit/products/eggbit-three-pack-special   :-) recently) is a cute add-on for the microbit. In three previous posts I looked at eggbit using microcode to  produce a hug avoider - warns when people at too close. - https://robotsandphysicalcomputing.blogspot.com/2021/12/hug-avoider-2-4tronix-eggbit.html -  4tronix Eggbit - cute and wearable - hug avoider Hug Avoider 3 - experiments with Python and 4Tronix Eggbit In this post using the buttons and adding (via Microbit V2 with its speaker) simple speech 1. Buttons Pins for the buttons pin8 - Green button pin12 - Red button pin14 - Yellow button pin`6 - Blue button     if pin12.read_digital()==1:         #Red Button         blank_it()     if pin8.read_digital()==1:         #Green but...

Dancing Kitronik's Game Zap - reacts to music

You will glad to hear this is only a short post.   In an earlier post, Build a Disco Cube:bit that reacts to music ; the vibrations of music, makes the cube sitting on a speaker with the volume pushed to 11 (just to test it of course) react to the music. The accelerometers values in the micro:bit, in the three axis, are feedback to change the neopixels colour. Simple but good fun. With some very minor (and I do mean minor) changes it works on the Kitronik's Game Zap - eight pixels are altered at a time instead of five but apart from that nothing more. The code in python is shown below: from microbit import * import neopixel, random np = neopixel.NeoPixel(pin0, 64) while True:     for pxl in range (3,64, 8):         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)   ...

Speech with EduBlocks on BBC microbit

The microbit is a great piece of kit, not least of which because of the range of programming languages and tools that can be used with it - officially JavaScript and Python and but there is also a range of third-party ones. A useful place to look for what languages/tools  are available is  http://microbit.org/code-alternative-editors/ ; listing both official and third-party tools (there was a few I wasn't aware of ). One I was aware and meaning to play with, is the brilliant Edublocks by Josh Lowe ( @ all_about_code ) or more   specifically in this post Edublocks for BBC Micro:bit  ( https://microbit.edublocks.org/ ). Edublocks for the microbit (and Edublocks in general) allows graphical blocks of code, in a similar way to languages such as Scratch, to be dragged and dropped into places. That in itself would be great, but the really useful thing here is though, whilst doing it you are actually producing a Python program (technically in th...

Radio controlled microbit Robot Unicorn

In a previous post a robot unicorn was built from a kit ( Do it Kits  https://doitkits.com/product/robot-unicorn/ ) and controlled to do a fixed sequence of actions. In this post a similar thing will be done, but this time the actions are not fixed within the robot itself, but in response to messages sent from another microbit via the radio module. Sending Sends out messages via the microbit's radio module, e.g. fwd for forward or tr for turn right; as well the name of the actions scrolls across the microbit. On the Unicorn Revieves messages via the microbits radio module, e.g. bwd for backward or tl for turn left; then carries out the action for 500ms. The time was selected to give the system enough time to finish the action before the next message is expected. All the code available at  Turner, S., 2017.  Robo_unicorn_python . Available at: <Robo_unicorn_python>  https://doi.org/10.6084/m9.figshare.5729583.v7 All opinions in this bl...

Micro:bit Robot Arm

In this post, I am discussing using a recently bought   CBIS BBC micro:bit RobotArm , but play with it using Python (or rather micropython). Set Up Not a lot to set up really. The base and the arm are separate and are attached with four screws (so you will need a screwdriver).  The most difficult bit is the wiring the arm to the circuit/breakout board on the base, but instructions are available through CBiS Resource portal  http://portal.cbis.education/teacher/hardware . You will need a log-in for this. Also on that site, there is an example Microsoft Blocks code which includes some instructions on inserting the microbit as well - the micro:bit goes in buttons side facing upwards. Code Taking the values from the instruction sheet for setting it - the micro:bit key bit - the following pins were selected. Base                     Pins 0 and 1 Shoulder    ...

kitronik :Move mini buggy (Python control of LEDs)

In two previous posts I looked at control the :Move buggy using JavaScript Blocks or Python . In this post we are going to look at controlling the LEDs using Python (or more accurately micropython). Pin 0 controls the LEDs, they are based on 5   NeoPixel compatible,  RGB, addressable LEDs; so the Neopixel protocols (and library for Neopixels) can be used.  Code First five colours of the rainbow. The array lig  holds the RGB settings for the rainbow colours (more details on the RGB colours can be found at  Lorraine Underwood 's Halloween Cloud project ). In the code below, the five LEDs have a different colour allocated to them. from microbit import * import neopixel np = neopixel.NeoPixel(pin0, 5) lig=[[255,0,0],[255,127,0],[255,255,0],[0,255,0],[0,0,255],[75,0,136],[139,0,255]] while True:     np[0] = lig[0]     np[1] = lig[1]     np[2] = lig[2]     np[3] = lig[3] ...

kitronik :Move buggy (Python controlled servos)

In a previous post I looked at controlling the Kitronik :Move buggy using Javascript based blocks . In this short post I will show  controlling the servos of the micro:bit based :Move buggy with Python. Control is via pin1(left motor) and pin2 (right motor) and the motors have to be driven in opposite directions to move forward or backwards. The direction of the motors is controlled by the analogue value written to the pins;   pinX.write_analog(180) - anticlockwise or  pinX.write_analog(1) - clockwise ( pinX.write_analog(0) - stops the motor). Setting the analog_period seems to work at 20ms; this was found by experiment, discussed in a previous post . So the initial code below sets up the moves for forward, backward, turn left, turn right all controlled with a move for so many milliseconds. Code  from microbit import * pin1.set_analog_period(20) pin2.set_analog_period(20) def forward(N):     pin1.write_analog(180...

CBiS Education Micro:Bit based Robot Car

At PiWars 2017 (1st-2nd April 2017), thanks to the generosity of CBiS Education , I now have one of their  BBC micro:bit RobotCar ™  . It is a sturdy bit of kit, encased in an aluminum chassis with a clear acrylic screen - it feels substantial when you pick it up.  It is based around fours motors, control by a Micro:Bit, via L298N based motor controller/shield. Batteries power, 8 AAs, the motors and a Lithium powerbank to power the Micro:Bit - all included.  More information about the technical details and example software can be found on their site  https://www.cbis.education/robotic-car-kit#  including further details on the  L298N based motor controller/shield, which I found useful for programming it.   I have experimented briefly with programming it in Python (micropython), getting it to it move forward, backward; to the right and left, using the Mu editor.  The code is shown below for those who want to try i...

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

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

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

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

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

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