(sorry for my english I'm not a native speaker)
I have a problem with connecting the BME280 sensor to the board.
Using standard libraries I cannot specify which pins I will use.
The only thing I could achieve was using begin (0x76); print incomprehensible data like (tft.print (bme.readTemperature ()); I get = -106.82).
Connected the BME280 sensor to pins PB9 - SDA, PB8 - SCL.
I have already connected the SPI TFT screen (ILI9341 controller and XPT2046 controller).
First I was try to use a combination of 10-DOF IMU sensors V2 from Waveshare.
But I could not do anything at all.
If I can manage with BME280, then in the future I wanted to use the module from Waveshare, which also has MPU9255 and do a compass.
Maybe someone have idea how to do it? (maybe someone knows some library where you can specify which pins you use)
Below I will throw the code which I use (there is a part where I test and calibrate the touch screen ) :
Code: Select all
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "URTouch.h"
#include "Adafruit_Sensor.h"
#include "Adafruit_BME280.h"
#include <Wire.h>
#include <SPI.h>
#define SEALEVELPRESSURE_HPA (1015.92)
Adafruit_BME280 bme; // I2C
#define TFT_DC PD5
#define TFT_CS PD7
#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 t_SCK PB3
#define t_CS PB7
#define t_MOSI PB5
#define t_MISO PB4
#define t_IRQ PB8
URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
void setup() {
Serial.begin(9600);
while (!Serial);
unsigned status;
status = bme.begin(0x76);
//bme.begin();
tft.begin();
tft.setRotation(0);
tft.fillScreen(ILI9341_BLACK);
ts.InitTouch(PORTRAIT);
ts.setPrecision(PREC_EXTREME);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(25, 5);
tft.print("Testing TouchTFT");
tft.setTextColor(ILI9341_GREEN);
tft.setCursor(45, 300);
tft.print("POWER OF STM");
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.setCursor(2, 300);
tft.print("X= ");
tft.setCursor(200, 300);
tft.print("Y= ");
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()
{
int x, y;
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1);
tft.setCursor(10, 165);
tft.print(bme.readTemperature());
tft.setCursor(10, 185);
tft.print(bme.readPressure() / 100);
tft.setCursor(10, 205);
tft.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
while (ts.dataAvailable())
{
ts.read();
x = ts.getX();
y = ts.getY();
tft.fillRect(13, 300, 20, 8, 0x0000);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.setCursor(13, 300);
tft.print(x);
tft.fillRect(213, 300, 20, 8, 0x0000);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.setCursor(213, 300);
tft.print(y);
if ((x != -1) && (y != -1))
{
x += 4;
y += 0;
int radius = 1;
tft.fillCircle(x, y, radius, ILI9341_YELLOW);
}
}
}