Using a BMP280 with the BBC Microbit V2 and Zephyr OS

I wanted to continue my investigation of the Microbit V2 and Zephyr by adding an external I2C device. The BMP280 module I chose is able to report back temperature and atmospheric pressure. I thought it would be nice to combine this with the earlier ST7789 example to produce a live reading of temperature and pressure on the display. This required a slight modification to the ST7789 setup as it is not possible to use both I2C1 and SPI1 in the same NRF52833 (microbit) project. This was easily fixed as the NRF52833 has SPI interfaces 0 to 2. I chose SPI1 which led me to write the following app.overlay file:

&spi2 {
 compatible = "nordic,nrf-spi";
 status = "okay";
 sck-pin = <17>;
 mosi-pin = <13>;
 /* Redirecting MISO to a pin that is not connected on the microbit v2 board */
 miso-pin = <27>;
 clock-frequency = <1000000>;
&i2c1 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = < 0x20 >; // P1.0 = pin reference 32+0 = I2c_EXT_SDA
	scl-pin = < 0x1a >; // P0.26 = pin reference 0x1a = I2C_EXT_SCL

Code is available over here on github.

Adding an ST7789 display to my Microbit V2 and Zephyr setup

I wanted to learn about using an external SPI device with the BBC Microbit V2. I ported my ST7789 library over to a Zephyr based program shown running on the Microbit and it is shown in operation above. The SPI interface runs at a fairly slow 8MHz which I believe (for now) is the maximum for this interface. As a result, screen updates are not super quick but probably good enough for a simple user interface.

The display library supports the following functions:

int display_begin();
void display_command(uint8_t cmd);
void display_data(uint8_t data);
void display_openAperture(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void display_putPixel(uint16_t x, uint16_t y, uint16_t colour);
void display_putImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t *Image);
void display_drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t Colour);
int iabs(int x); // simple integer version of abs for use by graphics functions
void display_drawRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t Colour);
void display_fillRectangle(uint16_t x,uint16_t y,uint16_t width, uint16_t height, uint16_t colour);
void display_drawCircle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t Colour);
void display_fillCircle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t Colour);
void display_print(const char *Text, uint16_t len, uint16_t x, uint16_t y, uint16_t ForeColour, uint16_t BackColour);
uint16_t display_RGBToWord(uint16_t R, uint16_t G, uint16_t B);

Code is available over here on github.