Posted on

Using Micro: bit Radio to Transmit and Display Sensor Readings

Using Micro: bit Radio to Transmit and Display Sensor Readings
Tutorial

Description

In this short video, a demonstration of the micro:bit taking readings from a TMP36 then displaying the temperature on the LED display can be seen. Here the micro:bit then uses the inbuilt radio to transmit this to another micro:bit which both display the temperature and change the colour of a micro:pixel from blue to red depending on temperature. There is also a range test that runs at the end of the video to show real-world radio range.

Posted on

Temperature to Light on the BBC Micro:bit via Python

micro:bit with a temp sensor and some RGB LEDs

BBC Micro Bit Projects

In this short article we are going to be using micropython to change the colour of a micro:pixel depending on the temperature being read from a TMP36.

First up I’m new to python, in fact I’ve only recently started looking at programming again (I was 17 when I last did any) so if you think something could be done better you’re probably right – so why not let us know in the comments?

Firstly I hooked up the TMP36 to pin 1 on the micro:bit using one of our exhi:bit boards. I then used crocodile clips to hook up the micro:pixel to the exhi:bit.

Then with a little help from Drew I managed to cobble together this code which basically takes a reading from pin1 which the TMP36 is hooked up to, it then creates a new variable called temp which is the analogue reading from pin1  multiplied by 3300/1024 – 500 then divided by 10 to get the temperature in Celsius.

We then display the temperature on the LED matrix. After this we create another variable called tempcolour which is an int by taking temp and multiplying it by 3.6 to scale it from 0-30 Celsius up to a scale of 128 for the colour value of the neopixels.

We then need to display the colour so we set the R, G and B value with Red being tempcolour, green being zero and blue being 255- (tempcolour*2) then we show the colours.

Much to my surprise this seems to work, I’m sure more can be done to make it work better but that’s for another day.

You can download the code here: TempToLight

You can get the micro:bit here
You can get the micro:pixel here
You can get the TMP36 here
You can get the exhi:bit here

Posted on

Super Scary Halloween Pumpkin Using the BBC Micro:bit and Our Micro:Pixel

pumpkin

With Halloween on its way, its time to get your skills on with a Pumpkin again!.

But instead of using the traditional candle to light up the juicy pumpkin meat, why not stay ahead of the neighbours and use the latest tech in the form of our Micro:pixel add on for the BBC Micro:bit?

This piece of wonderment is a 4×8 array of WS2812B Neopixels all mounted to a Micro:bit compatible add on board.

Our tech guy, Drew,  has knocked out a piece of code that will cause the Micro:pixel board to light up with a most satisfying flickering candle vibe.

To show you just how nice this looks, our expert Goods In/Out girl, Sammy, spent the morning carving pumpkins out so we could take some cool pics and videos for you guys. She is the only responsible adult here at Proto-PIC and sharp things were involved. I think you’ll agree she did a great job!

Once we had two pumpkins carved out quite nicely, we downloaded Drews code and dropped it into the BBC Micro:bit

We then dropped the BBC Micro:bit with the Micro:Pixel add on connected up to a AAA battery cage into the pumpkins.

Drew has done two different Micro Python versions of the code for you to try. We have included links to the code and youtube videos of what you should see with each one below:

Version 1. Realistic Flame
This is a very realistic candle effect, very subtle colour changes and it looks great  when the light reflects around the inside of the pumpkin.
Download Realistic Flame Hex File (right click and Save Target As, then copy to your micro:bit)

Version 2. Spooky Halloween Colour Show
A little bit more disco – when you look at it cycling on the micro:pixel itself, it looks like it shouldnt REALLY look like a flame, more like a party. But when you drop it in the pumpkin and take a step back it looks really cool!
Download Spooky Halloween Colour Show Hex File (right click and Save Target As, then copy to your micro:bit)

Want to make it even better?

  • Why not addin a PIR sensor so your pumpkin lights up only when there are people around to see it!
  • Put the Micro:pixel inside one of our small packing boxes to diffuse the light – this creates a great effect
Posted on

Using the Micro:bit Radio to Send and Receive Sensor Data

microbit

In this blog post I’m going to demonstrate the micro:bits radio capability. Have you ever wanted to know how cold your fridge is? Well I thought it would be interesting to find out so we took the following parts and got tinkering!

2 x micro:bit
1 x micro:pixel
1 x 1000mAh LiPo
1 x 6000mAh LiPo
3 x Alligator cables
1 x TMP36 sensor breakout

We then got to the programming, we did this in python and I use mu for the coding. You can download the code here.

The transmitter:bit

In this code we read the voltage from the TMP36 and convert this into the temperature then display it on the LED display and if a micro pixel is attached to this unit it will also change the colour depending on the temperature. We then switch on the radio and send the temperature as a string to any listening micro:bits then switch the radio off.

TempSendColour.py

#   Read and display the temperature
#   and update the NeoPixel panel with 
#   a colour between Blue and Red, and
#   send the data to any listening node 
#   (The micro:pixel panel is not needed)
#   for WWW.PROTO-PIC.CO.UK by Drew Anderson

#   import the libraries required by the microbit
from microbit import *
#   import the libraries required by the micro:pixel and Radio
import neopixel
import radio

#   We have 8×4 pixels, 32 in total on pin 0
np = neopixel.NeoPixel(pin0, 32)

while True:
    # Read the RAW temperature
    tmp = pin1.read_analog()
    # Convert the RAW to a real Temperature
    temp = ((tmp * (3300.0/1024.0))-500.0)/10.0
    # Expand the scale for better display in micro:pixel
    tempcolour = int((temp * 3.6))
    # The next 4 lines constrain the colour value to 0 <> 127
    if (tempcolour < 0):
        tempcolour = 0
    if (tempcolour > 127):
        tempcolour = 127
    # Show the colour on the micro:pixel
    for pix in range (0 , 32):
        np[pix] = (tempcolour,0,(255-(tempcolour*2)))
    np.show()
    # Show the Temperature to one decimal place
    tempToShow = “{0:0.1f}”.format(temp)
    display.scroll(tempToShow)
    # Turn on the radio
    radio.on()
    # Send the temp as a string
    radio.send(str(temp))
    # Let the data finish
    sleep(50)
    # Turn off the radio to save battery
    radio.off()
sleep(50)

The receiver:bit

In this code we set up the micro:pixel then switch on the radio, once we’ve done this we listen for a signal and then take the string we receive and convert it to a float. Once we have that we do a little maths to increase the scale. We then display the temperature on the LED matrix and change the colour of the micro:bit depending on the temperature.

TempReceiveColour.py

#   Receive and display the temperature
#   and update the NeoPixel panel with 
#   a colour between Blue and Red
#   for WWW.PROTO-PIC.CO.UK by Drew Anderson

#   import the libraries required by the microbit
from microbit import *
#   import the libraries required by the micro:pixel board & Radio
import neopixel
import radio
#   We have 8×4 pixels – 32 in total on pin 0
np = neopixel.NeoPixel(pin0, 32)
#   Turn the radio transmitter on (Required)
radio.on()

while True:
    # Read any incoming Data
    inData = radio.receive()
    if inData is not None:
        # inData is a string – We want a float
        temp = float(inData)
        # A little bit of maths to extend the scale a bit
        tempcolour = int((temp * 3.6))
        # The next 4 lines constrain the value to between 0 and 127
        if (tempcolour < 0):
            tempcolour = 0
        if (tempcolour > 127):
            tempcolour = 127
        # Update the micro:pixel 
        for pix in range (0 , 32):
            np[pix] = (tempcolour,0,(255-(tempcolour*2)))
        np.show()
        # Show the temperature to 1 decimal place
        tempToShow = “{0:0.1f}”.format(temp)
display.scroll(tempToShow)

Hook up guide:

First up slide one of the micro:bits into your micro:pixel.

Next up connect the larger capacity LiPo to the micro:bit.

We then connect up the TMP36 up to the other micro:bit 3V to VCC, GND to GND and Pin1 to TMP.

Finally we plug in the small LiPo into this micro:bit and you’re all done!

In action video:

LINKS:

Mu micropython editor

Example code