The micro:bit has a radio that works in Bluetooth LE and point-to-point ad-hoc mode, but at the moment it lacks WiFi connectivity. The solution is to use the low cost ESP8266 to make the connection via the micro:bit's serial port. 

Now On Sale!

You can now buy a print edition of micro:bit IoT in C.

You can buy it from:

USA and World


 The full contents can be seen below. 

Chapter List

  1. Getting Started With C/C++
    Anyone who wants to use the BBC micro:bit to its full potential as an IoT device needs to look outside the coding environments provided by its own website. As an mbed device, however, the micro:bit  is capable of being programmed in C/C++. Here we look at how to use the mbed online compiler for a simple demo program.

  2. Offline C/C++ Development  
    We have already discovered how to use the online editor to create a C/C++ program. Now we are going to move to the desktop with an offline approach. This has the advantage that we can use any tools we care to select and no Internet connection is needed.
  3. First Steps With The GPIO 
    The most basic task when working with the micro:bit is controlling the I/O lines. This isn't difficult if you use the framework provided but there some subtle points to watch out for. This chapter looks a the basics of using the GPIO.

  4. Working Directly With The Hardware - Memory Mapping. 
    The framework makes working with the GPIO and other devices as easy as it can be but there are many layers of software to go through before you get to the hardware. Writing directly to the hardware can make things up to ten times faster and give you access to things that their framework doesn't. It is also an educational experience to deal with the raw hardware directly.

  5. Pulse Width Modulation, Servos And More
    In this chapter we take a close look at pulse width modulation PWM including, sound, driving LEDs and servos.

  6. I2C
    The I2C bus is one of the most useful ways of connecting moderately sophisticated sensors and peripherals to the any processor. The only problem is that it can seem like a nightmare confusion of hardware, low level interaction and high level software. There are few general introductions to the subject because at first sight every I2C device is different, but here we present one.

  7. I2C Temperature Measurement
    Using I2C devices is fairly easy once you have successfully used one - and hence know what information you need and what to look for in a working system. In this chapter we use the HTU21D temperature and humidity sensor as a case study of I2C in action. It also happens to be a useful sensor.

  8. A Custom Protocol - The DHT11/22

  9. The DS18B20 - One Wire Bus

  10. The SPI Bus
    The SPI bus can be something of a problem because it doesn't have a well defined standard that every device conforms to. Even so if you only want to work with one specific device it is usually easy to find a configuration that works - as long as you understand what the possibilities are. 

  11. SPI MCP3008/4 AtoD   
    The SPI bus can be difficult to make work at first but once you know what to look for about how the slave claims to work it gets easier. To demonstrate how its done let's add eight channels of 12 bit AtoD using the MCP3008.

  12. Serial Connections
    The serial port is one of the oldest of ways of connecting devices together but it is still very, very useful. The micro:bit has a single serial interface but it can be directed to use any of the GPIO piins as Rx and Tx. 

  13. WiFi 
    The micro:bit has a radio that works in Bluetooth LE and point-to-point ad-hoc mode, but at the moment it lacks WiFi connectivity. The solution is to use the low cost ESP8266 to make the connection via the micro:bit's serial port. 

  14. LED Display 
    The micro:bit's LED display may only be 5x5 but it is very versatile. If you want to make use of it directly then you are going to have to master some lower level functions.



As we will make a lot of use of the micro:bit's serial port it is assumed that you know roughly how it works. In particular, it is assumed that you are familiar with the material in the previous chapter. Before we get on to the details of using the ESP8266 we need to find out what makes it special.

The Amazing ESP8266

The ESP8266 is a very odd and amazing device. It is remarkably low cost, $5 or less, but it is a full microprocessor with GPIO lines, RAM and built in WiFi. It is built by a Chinese company Espressif Systems but there are a number of copies on the market. The proliferation of devices and software revisions makes it difficult to work with, but it is well worth the effort. 

While you can set up a development system yourself and program the ESP8266 to do almost anything, it comes with built-in software that allows it to be used as a WiFi module for other processors. This is how we are going to use it to give the micro:bit a WiFi capability. 

The ESP8266 connects to the micro:bit using the serial port. The micro:bit controls it and transfers data using a system of AT commands. These were commonly used to control modems and other communication equipment and they still are used in mobile phone modems. 

The module that is used in this chapter is the ESP-01 which is widely available from many different sources but they all look like the photo:



There is another version, the ESP-07, which comes with a screen RF stage and other advantages and this should also work.    

A bigger problem is that there are new versions of the firmware and some of these might not work in exactly the same way. However it should be easy to make the changes necessary.

Connecting the ESP8266 ESP-01

There a number of minor problems in using the ESP8266. The first is that it comes with an eight-pin male connector which is not prototype board friendly.

The best solution to this is to use some jumper cables - female to male - to connect it to the prototype board or use female-to-female cables to connect directly to the micro:bit breakout board. 

A second problem is caused by the fact that the device is powered from a 3.3V supply. This might tempt you to try to power it from the micro:bit's 3.3V supply. 

This will not work.

The ESP8266 takes a lot of current, 300mA or so, when transmitting. The micro:bit cannot supply this much current. You need to use a separate 3.3V power supply. Of course you can use this to power both the ESP8266 and the micro:bit and in some situations this would be an advantage. 

You can use one of the many low cost prototyping board power supplies with no problems:

The pin out of the ESP-01 is usually shown from the component side, but in fact the pins that you want to connect to are on the other side. To make things easier the two views are given in the diagram:



The pin functions are:

1 Ground - connect to ground
2 TXO - the serial tx pin
3 GPIO2 - ignore
4 CHPD - chip enable connect to 3.3V
5 GPIO0 - ignore
6 RST - reset leave unconnected
7 RXI - the serial rx pin
8 VDD - Supply voltage connect to 3.3V

From the pinouts you should be able to work out the way the ESP8266 has to be connected to the micro:bit. If we use P0 as Tx from the micro:bit and P1 as Rx to the micro:bit we have to connect ESP-01 pin  7 to P0, pin 2 to P1 and ESP-01 pins 8 and 4 to the external power supply. To make it all work we also have to connect ESP-01 pin 1 to the ground of the external power supply ground and to the ground of the micro:bit, as shown: