STM32F103 and BME280 Sensor

Post here first, or if you can't find a relevant section!
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

STM32F103 and BME280 Sensor

Post by jxid »

Hi to all
I have an STM32F103 (blue pill) and i want to connect with a BME280 sensor in order to develop a project.
I want to read temperature , humidity and pressure from the sensor.
I use I2C protocol for my sensor.
After some search i found that the sensor could connect to B8,B9 of the STM module (B8---SDA , B9---SCL)
I used Adafruit BME280 library.
But since now i can not get data from sensor.I get only zeros.
The project compiles OK with no errors.
I use Arduino IDE .
Here is my sample code:

Code: Select all

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() 
{
    Serial.begin(115200);
    bme.begin();        
}
void loop() 
{ 
    Serial.println(bme.readTemperature(),1);
    Serial.println(bme.readHumidity(),1); 
    Serial.println(bme.readPressure(),1);              
    delay(1000);
}
The sensor works fine with ESP32 , ESP8266 Arduino Nano and Arduino UNO R3 boards.
by jxid » Mon Apr 20, 2020 3:51 pm
After some test i made it work!
So my results:
The sensor can be found with ID 0x76 ony when is connected to pins PB7---SDA and PB6---SCL
I hsd to "set" the adddes to bme.begin() like bme.begin(0x76)
Then the sensor work fine.
This is my working code:

Code: Select all

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() 
{
    Serial.begin(115200);
    bme.begin(0x76);        
}
void loop() 
{
    Serial.print("Temperat: ");   
    Serial.println(bme.readTemperature(),1);
    Serial.print("Humidity: ");
    Serial.println(bme.readHumidity(),1);
    Serial.print("Pressure: ");     
    Serial.println((bme.readPressure()/100),1);              
    delay(1000);
}
Thank you for your help.
Yannis.
Go to full post
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32F103 and BME280 Sensor

Post by stevestrong »

Some basics: viewtopic.php?f=2&t=301

Which core do you use?
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

Re: STM32F103 and BME280 Sensor

Post by jxid »

I tried the scanner code from the above link.
It does not detect my BME280 sensor.
But when i connect an RTC module it finds it.
What am i doing wrong?
Any ideas?
My STM32 board is STM32F103C8T6
User avatar
fpiSTM
Posts: 1746
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32F103 and BME280 Sensor

Post by fpiSTM »

You didn't answer the question:

which core do you use?

https://github.com/stm32duino/Arduino_Core_STM32

or

https://github.com/rogerclarkmelbourne/Arduino_STM32

or other...

If you don't provide enough information you will not be able to get help from the community.
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

Re: STM32F103 and BME280 Sensor

Post by jxid »

fpiSTM wrote: Mon Apr 20, 2020 11:49 am You didn't answer the question:

which core do you use?

https://github.com/stm32duino/Arduino_Core_STM32

or

https://github.com/rogerclarkmelbourne/Arduino_STM32

or other...

If you don't provide enough information you will not be able to get help from the community.
Sorry for this.
I use https://github.com/rogerclarkmelbourne/Arduino_STM32
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: STM32F103 and BME280 Sensor

Post by mrburnette »

jxid wrote: Mon Apr 20, 2020 2:14 pm ...
I use https://github.com/rogerclarkmelbourne/Arduino_STM32
It has been years, but I did an I2C, SPI, GPS serial using a Maple Mini and all worked as expected:
https://www.hackster.io/rayburne/color- ... ock-a8b121

Recently, I used a Blue Pill for just the barometer/ILI9341, so no issues with I2C or SPI.

Have you implemented pull-up resistors for I2C? If the scanner sw cannot see the I2C device but detects another... well, it is something 'external' to the uC IMO. Some I2C device modules have integrated pull-up resistors on the breakout board.

Ray
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

Re: STM32F103 and BME280 Sensor

Post by jxid »

Thanks Ray.
I have used this with a M7N gps module and an TFT display with no problem.
But i have problem with BME280 sensor.
Is there any other library for BME280 to use or to do any modifications?
Also i see that in your barometer project you use 15,16 pin in STM32 for SDA and SCL.That means that you connect the sensor to A5 and A6 pins.
I use B6 and B7 or B8 and B9 pins.
Is this right?
I tried to connect the sensor to A5 and A6 pins with pull-up resistors.
The result is the same.Only zeros in serial monitor.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: STM32F103 and BME280 Sensor

Post by mrburnette »

The Master Pin Map will show which pins can be interchanged in the switch matrix fabric:
http://docs.leaflabs.com/docs.leaflabs.com/index.html go down page...

Blue Pill specifics: https://stm32duinoforum.com/forum/wiki_ ... _Pill.html
Is there any other library for BME280 to use or to do any modifications?
I cannot answer. Maybe a Google site-centric search?
Also, some of the nice color-coded graphic pinouts are nicely done:

Image

I am forgetful if any of the common libraries restrict pin substitution.
I use B6 and B7 or B8 and B9 pins.
Best to use full port name: PB6, PB7, etc.


Ray
Last edited by mrburnette on Mon Apr 20, 2020 3:36 pm, edited 3 times in total.
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

Re: STM32F103 and BME280 Sensor

Post by jxid »

I have this pin out diagram and i connect the sensor acording to this.
That's why i use PB6-PB9 pins , because as shown in the diagram is for SDA and SCL.
But no luck till now.
Anyway thanks for the help and usefull info.
jxid
Posts: 17
Joined: Sun Apr 05, 2020 12:27 pm
Answers: 1

Re: STM32F103 and BME280 Sensor

Post by jxid »

After some test i made it work!
So my results:
The sensor can be found with ID 0x76 ony when is connected to pins PB7---SDA and PB6---SCL
I hsd to "set" the adddes to bme.begin() like bme.begin(0x76)
Then the sensor work fine.
This is my working code:

Code: Select all

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() 
{
    Serial.begin(115200);
    bme.begin(0x76);        
}
void loop() 
{
    Serial.print("Temperat: ");   
    Serial.println(bme.readTemperature(),1);
    Serial.print("Humidity: ");
    Serial.println(bme.readHumidity(),1);
    Serial.print("Pressure: ");     
    Serial.println((bme.readPressure()/100),1);              
    delay(1000);
}
Thank you for your help.
Yannis.
Post Reply

Return to “General discussion”