micro:bit Monday - pin:bit

This time we head over to Sheffield-on-the-sea to learn about a new product from the Pirates at Pimoroni

So what is it?



pin:bit is a micro:bit to breadboard breakout board. So you can use cheap / plentiful standard electronic components with the micro:bit without lots of crocodile clips.

How does it work?



Slot the micro:bit into the back of the board, then insert the board into a breadboard (from mini all the way up to monster sized) and start building circuits.



We have access to

  • Analog pins 0,1,2
  • Buttons A & B (Pins 5 & 11)
  • GPIO pins 0,1,2,5,8,11,13,14,15,16,19 and 20
  • SPI and I2C
  • 3V and GND connections that we can breakout on the breadboard

In order to test this I sat down at my ~~flaming garbage pile of a ~~desk and made a quick project. Using a temperature sensor and three male to male wires.

Super quick project!

For this project you will need

Connecting the hardware



So insert the micro:bit into the pin:bit, and then insert the pin:bit into your breadboard.

Then insert the TMP36 into your breadboard, with the FLAT side facing you.

On the TMP 36 we have three pins and they are connected as follows.

TMP36 Pin Wire Colour pin:bit Connection
1 Red 3v
2 Yellow pin 0
3 Black GND
Now plug the micro:bit into your computer and open the Mu editor. ###Coding the project

With Mu open, we need to make sure that we are in micro:bit mode, and in the bottom right of the Mu window we can see a cog, and just next to that is some text that can say Microbit, Adafruit CircuitPython, Python3 or PyGame Zero. Click on that text and change it to Microbit.

So lets start our code, there are only seven lines of code for this project and we start by importing all of the functionality found in the micro:bit library.

from microbit import * 

Then we use a loop to constantly run the code that we shall create within it.

while True: 

Next lets create a variable called raw and in there store the output of reading the voltage on pin 0 of the micro:bit, after we do a little maths to convert the raw data into something that the micro:bit can use.

    raw = pin0.read_analog() * (3300 / 1024.0)

This will spit out a value of something between 0 and 1023, which is what the micro:bit's 10-bit analog to digital converter can understand, and something we can use. So now lets convert that value into Celsius by taking the raw data, subtracting 500 from the value, and then divide the remainder by 10.

    temp_C = ((raw - 500) / 10)

Now lets print the temperature to the Python REPL (Read, Eval, Print, Loop) which is a shell interface that we can use to directly communicate with the micro:bit. In this case we use the round() function to round the temperature down to three decimal places, much easier for humans to understand.

    print(round(temp_C,3))

Lastly we tell the micro:bit to pause for one second at the end of every loop, this will stop the loop from running too fast.

    sleep(1000)

Complete code listing

from microbit import *  
while True:  
    raw = pin0.read_analog() * (3300 / 1024.0)
    sleep(500)
    temp_C = ((raw - 500) / 10)
    print(round(temp_C,3))
    sleep(1000)

Flashing the code

Mu has the handy option of flashing the code from the editor, just ensure your micro:bit is connected and click Flash

After a few seconds your micro:bit will be logging the temperature to the REPL...but we can't see it. So click on REPL and we can see the temperature, 27.021C at Biglesp Towers!

Conclusion

using cheap components with your micro:bit is a lot easier with pin:bit. Sure this isn't the first micro:bit to breadboard breakout board, but at £5 it is cheap, comes pre-soldered and enables us to start hacking with the minimum of fuss.

So where can I get one?



Directly from the Pimoroni website of course!