PIC18F46K22 with BMP280 Sensor and Nokia 5110 LCD | mikroC Projects

This is an other simple PIC project that shows how to interface PIC18F46K22 microcontroller with BMP280 barometric pressure and temperature sensor from Bosch Sensortec.
The PIC18F46K22 MCU reads temperature & pressure values from the BMP280 sensor and print them (respectively in °C and hPa) on Nokia 5110 LCD (84×48 pixel resolution).
The compiler used in this project is MikroElektronika mikroC PRO for PIC.
The BMP280 sensor is used in I2C mode.

To see how to interface PIC18F46K22 MCU with Nokia 5110 LCD using mikroC compiler, visit this post:
Interfacing PIC MCU with Nokia 5110 LCD | mikroC Projects

and to see how to interface PIC microcontroller with BMP280 sensor using mikroC PRO for PIC compiler, take a look at this project:
PIC MCU with BMP280 temperature and pressure sensor | mikroC Projects

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 LCD screen
  • BMP280 sensor module (with built-in 3.3V regulator and level shifter)   —->  BMP280 datasheet
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • Breadboard
  • Jumper wires

PIC18F46K22 with BMP280 sensor and Nokia 5110 LCD

PIC18F46K22 with BMP280 Sensor and Nokia 5110 LCD circuit:
The image below shows project circuit diagram.

Hint:
The BMP280 chip works with maximum voltage of 3.6V (supply voltage range is from 1.71 to 3.6V) which means we’ve to use a 3V3 voltage regulator to supply it from a 5V source.
Also, if we’re working with a 5V system (development board, microcontroller …) like the PIC18F46K22 microcontroller, we’ve to use a voltage level shifter (level converter) which converts the 3.3V (comes from the BMP280 chip) into 5V (goes to the PIC18F46K22) and vice versa. This level shifter is for the I2C bus lines (clock and data).
The BMP280 module shown in project circuit diagram has a built-in 3.3V regulator and level shifter.

BMP280 PIC18F46K22 Nokia 5110 LCD circuit

All the grounded terminals are connected together.

The PIC18F46K22 microcontroller has 2 hardware I2C modules (MSSP1 and MSSP2 modules).
In this project I2C1 module is used with SDA1 on pin RC4 (#23) and SCL1 on pin RC3 (#18). SDA1 and SCL1 pins of the PIC18F46K22 MCU are respectively connected to SDA and SCL pins of the BMP280 sensor module.

The Nokia 5110 LCD module which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the AMS1117 3V3 voltage regulator, this regulator steps down the 5V into 3.3V (supplies the LCD controller PCD8544 with regulated 3V3).

All PIC18F46K22 microcontroller output pins are 5V, connecting a 5V pin to the Nokia 5110 LCD may damage its controller circuit!
To connect the PIC18F46K22 to the LCD module, I used voltage divider for each line which means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

So, the Nokia 5110 LCD pins are connected to PIC18F46K22 MCU as follows (each one through voltage divider):
RST (reset) pin is connected to pin RD0 (#19),
CE (chip enable) pin is connected to pin RD1 (#20),
DC (data/command) pin is connected to pin RD2 (#21),
DIN (data in)  pin is connected to pin RD3 (#22),
CLK (clock) pin is connected to pin RD4 (#27),

VCC and BL are connected to AMS1117 3V3 regulator output pin and GND is connected to circuit ground (0V).

In this project the PIC18F46K22 microcontroller runs with its internal oscillator @ 16 MHz, MCLR pin is configured as an input pin.

PIC18F46K22 with BMP280 Sensor and Nokia 5110 LCD C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

To be able to compile project C code, a driver for the Nokia 5110 LCD is required, its full name (with extension) is NOKIA5110.C, download link is the one below:
Nokia 5110 LCD library for mikroC compiler

Also, another library for the BMP280 sensor is required, its full name (with extension) is BMP280.c, download link is below:
BMP280 Library for mikroC compiler

after the download of the 2 library files, add both of them to mikroC project folder.

The connection of the LCD pins with the microcontroller are defined in the C code as shown below:

Driver files of the Nokia 5110 LCD and the BMP280 sensor are included in the code using the 2 lines below:

As any other I2C device, the BMP280 sensor has an I2C slave address which is 0xEC or 0xEE. This address depends on the connection of the SDO pin (used for SPI mode as serial data out, MISO), if the SDO pin is connected (directly or through resistor) to VCC (3.3V) the address will be 0xEE, and if it’s connected to GND the address will be 0xEC.

The default I2C address of the library is defined as 0xEE and my device I2C address is 0xEC.
In the code, the definition of the I2C slave address is as shown below:

The BMP280 sensor is initialized with the function BMP280_begin which returns 1 if ok and 0 if error. In the code the initialization of the sensor is as shown below:

The LCD displays “connection error!” if there was an error while initializing the device.

Reading the values of temperature and pressure is done as shown below.
Note that the library returns the temperature in hundredths °C which means we’ve to divide it by 100 and it returns the pressure in Pa, to get the pressure in hPa we’ve to divide it also by 100.

Temperature and pressure values are printed on the NOKIA 5110 LCD.

1 bar = 10000 Pa = 100 hPa. ( 1 hPa = 100 Pa)
Pa: Pascal
hPa: hectoPascal

Full mikroC code:

My hardware circuit was the same as the one shown in this video where PIC18F4550 microcontroller is used:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top