background image

BME280 Environmental Sensor 

   

 

WORKING WITH ARDUINO 

1.

 

Open Arduino folder (from the one we download), Copy folder BME280-Arduino-

Library to Libraries directory of IDE, which locates on installation directory of 

Arduino IDE. 

2.

 

Open Arduino IDE, Choose File->Examples-> BME280_Libreay->bme280test to 

open the demo code. 

3.

 

Connect BME280 to Arduino according to 

Interfaces

 

- By default, communication interface is I2C with device address 0x77 

- If you want to use SPI interface, you need to change USEIIC to 0 on demo code 

 

4.

 

  If you want to change the device address to 0x76, you could connect ADDR to 

ND, and change the BME280_ADDRES value on Adafruit.h of demo code: 

 

Summary of Contents for BME280

Page 1: ...S Support I2C interface I2C device address could be set by changing I O or welds Supports SPI interface Default I2C you can change to SPI by change I O Integrated Level convert circuit compatible with 3 3V 5V Provide examples and user guide Raspberry Pi Arduino STM32 SPECIFICATION Operating voltage 5V 3 3V Interface I2C SPI Temperature range 40 85 C Resolution 0 1 C tolerance 1 C Humidity range 0 ...

Page 2: ... PB6 SCL I2C Clock ADDR NC GND NC GND NC GND Address Select High by default High address is 0x77 Low address is 0x76 CS NC NC NC NC SPI PIN Arduino STM32 RASPBERRY Description VCC 3 3V 5V 3 3V 5V 3 3V 5V Power GND GND GND GND Ground MOSI D11 PA7 MOSI SPI Data input SCK D13 PA5 SCK SPI Clock input MISO D12 PA6 MISO SPI Data output CS D10 PB6 27 SPI chip select Low active ...

Page 3: ... you need to first install WiringPi library or it could be be used normally About how to install WiringPi library you can visit the page Libraries installation for RPi for details EXAMPLE DOWNLOAD Visit Our Wiki and find the page of BME280 Environmental Sensor download the demo code Extract it to get the folders as below ...

Page 4: ... open configuration page with the command sudo raspi config 2 Enable the interface separately For SPI Choose Interfacing Options SPI Yes For I2C default Choose Interfacing Options I2C Yes 3 After configuring reboot your Raspberry Pi sudo reboot 4 After rebooting you can check if I2C or SPI module has been enabled with command If there are I2C or SPI information printed modules are started lsmod ...

Page 5: ... connect ADDR to GND 7 Install I2C tools tool for I2C devices detecting sudo apt get install i2c tools 8 You can query I2C devices with command i2cdetect y 1 If there is 77 printed 76 if you change the address it means that BME280 has connected to Raspberry Pi normally Note Please make sure that there are not other I2C devices which has the same address as BME280 For SPI connection you can refer t...

Page 6: ...which is included in the folder we copied before cd BME280 Environmental Sensor Demo Code 3 Open and edit file main c vim main c If you use I2C connection which is default setting you should set the USEIIC define to 1 Then check the address of I2C device on the code the address used on code should be same as the one we detected before ...

Page 7: ...USEIIC define to 0 on main c 4 Save and exit Then re compile the demo code sudo make clean sudo make 5 Running the demo code sudo bme280 Note if there are not any data outputted after running the demo code or get wrong data please check the hardware connection and address used ...

Page 8: ...en Arduino IDE Choose File Examples BME280_Libreay bme280test to open the demo code 3 Connect BME280 to Arduino according to Interfaces By default communication interface is I2C with device address 0x77 If you want to use SPI interface you need to change USEIIC to 0 on demo code 4 If you want to change the device address to 0x76 you could connect ADDR to ND and change the BME280_ADDRES value on Ad...

Page 9: ...ure of local sea level and then change the define of SEALEVELPRESSURE_HPA 6 Then compile and download to your Arduino board 7 Open Serial monitor and set the baud rate to 11520 Note if there are not any data outputted after running the demo code or get wrong data please check the hardware connection and address used ...

Page 10: ...ange to SPI you need to change the USEIIR define to 0 of main c If you want to use I2C and change its address you can connect ADDR to GND and discommend statement dev dev_id BME280_I2C_ADDR_SEC 4 Compile and download the demo code to STM32 board the examples we provide is based on STM32F103RBT6 Use UART2 to print sensor data You can connect UART to PC by TTL to UART module then open Serial assista...

Page 11: ...BME280 Environmental Sensor default 115200 8N1 Note if there are not any data outputted after running the demo code or get wrong data please check the hardware connection and address used ...

Page 12: ... dev write user_spi_write dev delay_ms user_delay_ms rslt bme280_init dev For I2C its initial code struct bme280_dev dev int8_t rslt BME280_OK dev dev_id BME280_I2C_ADDR_PRIM dev intf BME280_I2C_INTF dev read user_i2c_read dev write user_i2c_write dev delay_ms user_delay_ms rslt bme280_init dev bme280_dev is BME280 device structure provided by official library could be used to initialize and obtai...

Page 13: ...I void user_delay_ms uint32_t period Return control or wait for a period amount of milliseconds int8_t user_spi_read uint8_t dev_id uint8_t reg_addr uint8_t reg_data uint16_t len int8_t rslt 0 Return 0 for Success non zero for failure The parameter dev_id can be used as a variable to select which Chip Select pin has to be set low to activate the relevant device on the SPI bus Data on the bus shoul...

Page 14: ...w to activate the relevant device on the SPI bus Data on the bus should be like MOSI MISO Chip Select don t care don t care HIGH reg_addr don t care LOW reg_data 0 don t care LOW LOW reg_data len 1 don t care LOW don t care don t care HIGH return rslt int8_t user_i2c_read uint8_t dev_id uint8_t reg_addr uint8_t reg_data uint16_t len int8_t rslt 0 Return 0 for Success non zero for failure The param...

Page 15: ... rslt int8_t user_i2c_write uint8_t dev_id uint8_t reg_addr uint8_t reg_data uint16_t len int8_t rslt 0 Return 0 for Success non zero for failure The parameter dev_id can be used as a variable to store the I2C address of the device Data on the bus should be like I2C action Data Start Write reg_addr Write reg_data 0 Write Write reg_data len 1 Stop return rslt ...

Page 16: ... functions pointer to bme280_dev structure as publics then transfer the pointer of structure to initialization function int8_t bme280_init struct bme280_dev dev Initialize BME280 device Step3 Calling int8_t stream_sensor_data_forced_mode struct bme280_dev dev or int8_t stream_sensor_data_normal_mode struct bme280_dev dev to get data of BME280 sensor and print them to console or PC ...

Reviews: