Weather:bit - microPython code examples needed

I recently purchased the SparkFun Weather:bit shield. I can program the Weather:bit using the make online portal using both the block and javascript, but I’m still not happy with all the functionality.

Ideally I would like to program the Weather:bit using micro python. As long as I can capture the temperature, humidity, atmospheric pressure, wind speed and wind direction data I can use the radio function in micro python to transmit this information in a classroom of students.

When I use Javascript to send information using the radio.sendString method, I end up with irregular outputs on BBC Microbits receiving the signal. I think this has something to do with the Javascript code.

Any example micro python code would be a great help. Thanks


basic.forever(() => {
item = 0
temp = weatherbit.temperature()
t = temp.toString()
t = “Temp” + t
t = “”
led.toggle(0, 0)

Hi @Edmond34442,

Sounds like a great project underway! What you are seeing might be due to how MakeCode cannot handle floating point numbers.

From Sparkfun’s reference guide: MakeCode cannot handle floating point numbers (numbers with decimal points) yet. Which can be troublesome for getting really accurate readings from the BME280 with a single variable block. So, to get as accurate of values as possible you have to do some math in the programming environment. We know, not fun! But, hey now you might pay attention in math class a bit more now.

Here’s the math represented visually:

Let me know how you get on with it!

I made a correction above - just creating this reply so you’ll get a new notification.

Hi Graham,

Thanks for your reply - this is Edmond Lascaris from the City of Whittlesea.

Just would like to be able to write some code directly in micropython from a mu editor. Can easily do the calculations and even write and upload code using Javascript - but it doesn’t do all that I want.

Just need some example code in micropython to get temp, humidity, atmospheric pressure, wind speed and wind direction. Once I have some example code I can broadcast this in a classroom setting for students to receive using the radio.send() instruction in micro python. uses a Weatherbit library which I don’t have access to in micropython.



Hi Graham,

I’ll attach some files to give you some clarity. THe file - Weatherbit micropython garbage shows the output of a BBC Microbit receiving a radio transmission from a BBC Microbit attached to the Weather:bit.

I can’t understand why there are some extra funny characters before the sensor data (Temp, Hum, etc)?

I’ve attached an excerpt of the BBC Microbit transmitter code. The Javascript example code is only for temperature.

IN Python I can easily remove the extra characters, but I was wondering if something in my code was not correct.

Hope you can help. I can be reached on 0412 978 633



What happens if you do this (pseudo code warning - I haven’t tried it):

while True:
        incoming = radio.receive()
        if incoming is not None:

I’m curious if this removes some erroneous data.

There’s also some

HI Graham,

I’ve used this in the past and I tested it again.

Unfortunately all this code does is get bypassed because incoming does contain text based information.

I use this code to manage the gaps in radio transmissions.

I found a workaround. I just use some python code to look for certain key statements that I know will be in the radio transmissions. So I look for the “Temp” keyword in transmittions that contain temperature data. It works well.

I’m not experienced enough to create my own library in micropython to interface directly with the Sparkfun Weatherbit - but the inclusion of a micropython library with this board would be great. With the students I teach we always use the mu micropython editor on Raspberry Pi computers.

Really appreciate your time and help. I’m just trying to create less complicated code for students - hence the push for a library or other interface for using the Weatherbit.

The Weatherbit will be used in conjunction with the CSIRO Chameleon soil moisture sensor in kitchen garden programs in schools. Bringing some useful technology to the garden to give kids both gardening experience and a useful connection with coding.

Working with Richard from CSIRO we’ve now found a way to use the BBC Microbit Motor Driver boards to measure soil moisture - rather than Arduino boards. Because schools have limited funds (and us too) - its sometimes better to try to maximise the use of one computing, hardware and software platform. Its easier for teachers to also become familiar with one system.

CSIRO Chameleon soil moisture project and sensors.

Also - recently got in touch with Joe and Julie from the School Amateur Radio Club Network. They are based in Melbourne. You may get a call from Joe because he is helping us with LoRa. They are a great knowledge base.



This is the same code as above - but modified so the BBC Microbit can re-transmit the data to the class on a different radio channel/group. The class will pick this up and then do further manipulation of the data. The aim is for them to use the serial connections on their BBC Microbit to send the data to Python on their Raspberry Pis and then use the data in Minecraft-Pi.


    February 23

What happens if you do this (pseudo code warning - I haven’t tried it):

>         while True:
> incoming = radio.receive()
> if incoming is not None:
> print(incoming)