STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post here first, or if you can't find a relevant section!
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post by Orion1398 »

fredbox wrote: Tue May 04, 2021 11:06 pm Here is a nice picture of the data lines without pull-up resistors: https://electronics.stackexchange.com/q ... al-pullups. With the right pull-up, the signals are nice and square.
I will try use pullups)).
I turned off the screen sensor and everything worked (at least BME280 works).
I don't know if the 0-DOF IMU Sensor will work but tomorrow I'll try to connect it.
This is pins what I was use for Touch.
#define t_SCK PB3 // T_CLK
#define t_CS PB7 // T_CS
#define t_MOSI PB5 // T_DIN
#define t_MISO PB4 // T_DOUT
#define t_IRQ PB8 // T_IRQ

If I need a touchscreen then I think I will use other pins (like SPI2).

The result I got
https://drive.google.com/file/d/1T-d_6I ... sp=sharing

Code:

Code: Select all

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_Sensor.h"
#include "Adafruit_BME280.h"
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

#define SEALEVELPRESSURE_HPA (1015.92)
Adafruit_BME280 bme; // I2C

#define TFT_DC PD5
#define TFT_CS PD7
//#define TFT_RST PA3
#define TFT_RST -1
#define TFT_MISO PB14
#define TFT_MOSI PB15
#define TFT_CLK PB13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

#define PERIOD 5000
uint32_t timer = 0;

static const int RXPin = PA9, TXPin = PA10;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
bool errL = false;
bool errD = false;
bool errT = false;
void setup() {
  Serial.begin(9600);
  //Serial.begin(115200);
  ss.begin(GPSBaud);
  while (!Serial);
  unsigned status;
  status = bme.begin(0x76);
  //bme.begin();
  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.setCursor(72, 5);
  tft.print("Testing");
  tft.setTextColor(ILI9341_GREEN);
  tft.setCursor(102, 300);
  tft.print("STM");
  if (!status)
  {
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(20, 45);
    tft.print("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
    tft.setCursor(20, 65);
    tft.print("SensorID was: 0x");
    tft.print(bme.sensorID(), 16);
    tft.setCursor(20, 75);
    tft.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
    tft.setCursor(20, 95);
    tft.print("   ID of 0x56-0x58 represents a BMP 280,\n");
    tft.setCursor(20, 105);
    tft.print("        ID of 0x60 represents a BME 280.\n");
    tft.setCursor(20, 115);
    tft.print("        ID of 0x61 represents a BME 680.\n");
    tft.setCursor(20, 125);
    while (1) delay(10);
  }

}

void loop()
{
  if (millis() - timer >= PERIOD) 
  {
    funcBME280();
    do 
    {
      timer += PERIOD;
      if (timer < PERIOD) break;
    } 
    while (timer < millis() - PERIOD); 
  }


  while (ss.available() > 0)
    if (gps.encode(ss.read()))
    {
      displayInfo();
    }

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    tft.setTextColor(ILI9341_RED);
    tft.setTextSize(1);
    tft.setCursor(10, 35);
    tft.print(F("GPS NEO-7M"));
    tft.setCursor(10, 55);
    tft.print(F("No GPS detected: check wiring."));
    while (true);
  }
}

void funcBME280()
{
  tft.setTextColor(ILI9341_RED);
  tft.setTextSize(1);
  tft.setCursor(10, 165);
  tft.print("BME280");
  tft.setCursor(10, 185);
  tft.print("Temperature:");
  tft.fillRect(90, 185, 100, 7, 0x0000);
  tft.setCursor(90, 185);
  tft.print(bme.readTemperature());
  tft.setCursor(10, 195);
  tft.print("Pressure:");
  tft.fillRect(90, 195, 100, 7, 0x0000);
  tft.setCursor(90, 195);
  tft.print(bme.readPressure() / 100);
  tft.setCursor(10, 205);
  tft.print("Altitude:");
  tft.fillRect(90, 205, 100, 7, 0x0000);
  tft.setCursor(90, 205);
  tft.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  tft.setCursor(10, 215);
  tft.print("Humidity:");
  tft.fillRect(90, 215, 100, 7, 0x0000);
  tft.setCursor(90, 215);
  tft.print(bme.readHumidity());
}

void displayInfo()
{

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.setCursor(10, 25);
  tft.print("GPS NEO-7M");
  tft.setCursor(10, 45);
  tft.print("LOCATION");
  if (gps.location.isValid())
  {
    if (errL)
    {
      tft.fillRect(10, 55, 260, 7, 0x0000);
    }
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(10, 55);
    tft.print("LAT: ");
    tft.fillRect(35, 55, 60, 7, 0x0000);
    tft.setCursor(35, 55);
    tft.print(gps.location.lat(), 6);
    tft.setCursor(135, 55);
    tft.print("LGN: ");
    tft.fillRect(160, 55, 60, 7, 0x0000);
    tft.setCursor(160, 55);
    tft.print(gps.location.lng(), 6);
  }
  else
  {
    errL = true;
    tft.fillRect(10, 55, 260, 7, 0x0000);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(10, 55);
    tft.print("INVALID LOCATION");
  }

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.setCursor(10, 65);
  tft.print("DATE");
  if (gps.date.isValid())
  {
    if (errD)
    {
      tft.fillRect(10, 75, 260, 7, 0x0000);
    }
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(10, 75);
    tft.print("Month/Day/Year:");
    tft.setCursor(105, 75);
    tft.print(gps.date.month());
    tft.setCursor(110, 75);
    tft.print("/");
    tft.setCursor(115, 75);
    tft.print(gps.date.day());
    tft.setCursor(120, 75);
    tft.print("/");
    tft.setCursor(125, 75);
    tft.print(gps.date.year());

  }
  else
  {
    errD = true;
    tft.fillRect(10, 75, 260, 7, 0x0000);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(10, 75);
    tft.print("INVALID DATE");
  }

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.setCursor(10, 85);
  tft.print("TIME UTC");
  if (gps.time.isValid())
  {
    if (errT)
    {
      tft.fillRect(10, 95, 260, 7, 0x0000);
    }
    if (gps.time.hour() < 10)
    {
      tft.fillRect(10, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(10, 95);
      tft.print("0");
      tft.setCursor(16, 95);
      tft.print( gps.time.hour());
    }
    else
    {
      tft.fillRect(10, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(10, 95);
      tft.print(gps.time.hour());
    }

    if (gps.time.minute() < 10)
    {
      tft.fillRect(25, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(25, 95);
      tft.print("0");
      tft.setCursor(31, 95);
      tft.print(gps.time.minute());
    }
    else
    {
      tft.fillRect(25, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(25, 95);
      tft.print(gps.time.minute());
    }

    if (gps.time.second() < 10)
    {
      tft.fillRect(40, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(40, 95);
      tft.print("0");
      tft.setCursor(46, 95);
      tft.print(gps.time.second());
    }
    else
    {
      tft.fillRect(40, 95, 25, 7, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.setCursor(40, 95);
      tft.print(gps.time.second());

    }
  }
  else
  {
    errT = true;
    tft.fillRect(10, 95, 260, 7, 0x0000);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.setCursor(10, 95);
    tft.print("INVALID TIME");
  }
  Serial.println();
}
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post by AndrewBCN »

Usually these small BMP280/BME280 modules, as well as many other I2C modules, already have their own 4.7k or 10k pullup resistors. You can test with a multimeter, the resistance between SDA/SCL and Vcc.

table.png
table.png (20.36 KiB) Viewed 2253 times
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post by Orion1398 »

10 DOF IMU Sensor (D) didn't work.
I try connect too Arduino Duo but gyroscope and accelerometer don't work and I think I dont need them.
I replaced it with a QMC5883L I2C GY-271.
BME280 works correctly but QMC doesn't.
I connect QMC to PB6, PB7.
I use this pinout shem.
https://os.mbed.com/users/hudakz/code/S ... /shortlog/
In QMC5883LCompass.cpp I find this but I don't know what needs to change.

Code: Select all

// Set I2C Address if different then default.
void QMC5883LCompass::setADDR(byte b){
	_ADDR = b;
}
If I connect HMC to that same pins like BME then he works fine.
What can I do to make the two work?

Maybe someone has some ideas ?
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post by Orion1398 »

Heh :shock:
They work.
I don't know how but they work.
I just steamed the SDA and SCL outputs.
I know it's wrong but it work.
https://drive.google.com/file/d/10n4UB7 ... sp=sharing
Thanks Everybody. For now, that will be enough.
Escrich
Posts: 2
Joined: Mon Sep 06, 2021 6:55 pm

Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?

Post by Escrich »

Could you please share your code with me?, I'm interested on the accelerometer, I'm experiencing great problems to connect it and make it work, your code will be a great help.
Thanks
Post Reply

Return to “General discussion”