PIC Weather Station using BME280 Sensor & Nokia LCD | mikroC Projects

This PIC project shows how to build a weather station using PIC18F46K22 microcontroller and BME280 barometric pressure, temperature and humidity sensor from Bosch Sensortec.
The PIC18F46K22 MCU reads temperature & humidity & pressure values from the BME280 sensor and print them (respectively in °C & RH% & hPa) on Nokia 5110 LCD (84×48 pixel resolution).
The compiler used in this project is MikroElektronika mikroC PRO for PIC.
The BME280 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 BME280 sensor using mikroC PRO for PIC compiler, take a look at this project:
PIC MCU with BME280 pressure, temperature and humidity sensor | mikroC Projects

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 LCD screen
  • BME280 sensor module (with built-in 3.3V regulator and level shifter)   —->  BME280 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 MCU with Nokia 5110 LCD and BME280 sensor

PIC18F46K22 Weather station circuit:
The image below shows project circuit diagram.

Hint:
The BME280 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 BME280 chip) into 5V (goes to the PIC18F46K22) and vice versa. This level shifter is for the I2C bus lines (clock and data).
The BME280 module shown in project circuit diagram has a built-in 3.3V regulator and level shifter.

BME280 Nokia 5110 LCD PIC18F46K22 weather station 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 BME280 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 Weather station 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 BME280 sensor is required, its full name (with extension) is BME280.c, download link is below:
BME280 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 BME280 sensor are included in the code using the 2 lines below:

As any other I2C device, the BME280 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 BME280 sensor is initialized with the function BME280_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, humidity 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, it returns the humidity in relative humidity percent (rH%) in 1024 steps which means we’ve to divide it by 1024 and it returns the pressure in Pa, to get the pressure in hPa we’ve to divide it by 100.

Temperature, humidity 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:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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