Re: STM32 F407VET6 and BME280 I2C how to choose SDA and SCL pins?
Posted: Wed May 05, 2021 12:17 am
I will try use pullups)).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 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();
}