Interfacing BME280 display with PIC16F887

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ssssspremachandra@gmail.com
Posts: 2
Joined: 10 Jan 2024 10:47

Interfacing BME280 display with PIC16F887

#1 Post by ssssspremachandra@gmail.com » 10 Jan 2024 11:15

Hi, I encountered an error while interfacing BME280 sensor , I have downloaded the BME280.c file how can I include the file to my code


// define device I2C address: 0xEC or 0xEE (0xEE is library default address)
#define BME280_I2C_ADDRESS 0xEC

// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// end LCD module connections

#include <BME280.c> // include BME280 sensor driver source file

signed long temperature;
unsigned long pressure, humidity;
char buffer[19] = "PIC16F887 + BME280";

// main function
void main()
{
OSCCON = 0x70; // set internal oscillator to 8MHz
I2C1_Init(400000); // initialize I2C communication
delay_ms(1000); // wait a second
Lcd_Init(); // initialize LCD module
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD

lcd_out(1, 2, buffer);

// initialize the BME280 sensor according to the following settings:
// BME280_begin(mode, T_sampling, H_sampling, P_sampling, filter, standby_time)
if(BME280_begin(MODE_NORMAL, SAMPLING_X1, SAMPLING_X1, SAMPLING_X1, FILTER_OFF, STANDBY_0_5) == 0)
{ // connection error or device address wrong!
lcd_out(2, 2, "Connection error!");
while(1); // stay here
}

while(1)
{
// Read temperature (in hundredths C), pressure (in Pa)
// and humidity (in 1024 steps RH%) values from the BME280 sensor
BME280_readTemperature(&temperature); // read temperature
BME280_readHumidity(&humidity); // read humidity
BME280_readPressure(&pressure); // read pressure

// print data on the LCD screen
// 1: print temperature
if(temperature < 0)
sprinti(buffer, "Temp =-%02u.%02u%cC ", (unsigned int)(abs(temperature)/100), (unsigned int)(abs(temperature)%100), 223);
else
sprinti(buffer, "Temp = %02u.%02u%cC ", (unsigned int)(temperature/100), (unsigned int)(temperature%100), 223);
lcd_out(2, 1, buffer);

// 2: print humidity
sprinti(buffer, "Humi = %02u.%02u %%", (unsigned int)(humidity/1024), (unsigned int)(((humidity*100)/1024)%100));
lcd_out(3, 1, buffer);

// 3: print pressure
sprinti(buffer, "Pres = %04u.%02u hPa", (unsigned int)(pressure/100), (unsigned int)(pressure%100));
lcd_out(4, 1, buffer);

delay_ms(2000); // wait 2 seconds
}

}
// end of code.
Attachments
pic error.png
pic error.png (509.05 KiB) Viewed 162 times

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Interfacing BME280 display with PIC16F887

#2 Post by IvanJeremic » 15 Jan 2024 11:06

Hi,

BME280.c is not our example, so i am not sure if it will work properly if you implement it into our compiler.

If you want to add it to your project you will need to right click on your project and then add the file.
Untitled.png
Untitled.png (18.19 KiB) Viewed 104 times
You can also look at our example for our Weather click which uses the BME280 sensor:
https://libstock.mikroe.com/projects/vi ... ther-click

Regards,

Ivan.

Post Reply

Return to “mikroC PRO for PIC General”