I'm building some telemetry thing for my RC plane.
I have this BME280 sensor connected to Arduino Pro Micro pins 2 and 3.
https://www.aliexpress.com/item/High-Accuracy-BME280-Digital-Sensor-Temperature-Humidity-Barometric-Pressure-Sensor-Module-GY-BME280-I2C-SPI-1/32672210336.html
Also 4-pin 4-digit LCD on pins 8 and 9.
https://store.qkits.com/4-digit-7-segment-led-display-with-colon.html
And some leds and Flysky FS-iA6B RC receiver on pin RX.
This receiver decoder works as is: GitHub - aanon4/FlySkyIBus: FlySky i-bus library for Arduino
This sensor library works as is: GitHub - Seeed-Studio/Grove_BME280
Also TM1607 lcd library is used and working.
So they work individually fine, but when I try to use them all at once, I get problems.
On the lcd display i get humidity correct at 27%, temperature wrong at 13C (should be 25) and altitude about 1760 (should be 0). Randomly the whole thing freezes.
Everything works if I comment out the lines that read the sensor values.
Are the I2C:s somehow interfering each other or what is going on?
#include "FlySkyIBus.h"
#include "Seeed_BME280.h"
#include <Wire.h>
#include <TM1637Display.h>
unsigned long strobo = 0, vilkku = 0, prevsens = 0;
const int strosin = 5;
const int strovih = 6;
const int stropun = 4;
const int punn = 10;
const int vihh = 16;
const int etuvalo = 14;
const int CLK = 9; //Set the CLK pin connection to the display
const int DIO = 8; //Set the DIO pin connection to the display
BME280 bme280;
int NumStep = 0; //Variable to interate
TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
float lahto = 0;
int alt = 1111, temp = 2222, humi = 3333;
void setup()
{
if (!bme280.init()) {
Serial.println("Device error!");
}
// Serial.begin(9600);
display.setBrightness(0x0a); //set the diplay to maximum brightness
lahto = bme280.calcAltitude(bme280.getPressure());
pinMode(stropun, OUTPUT);
pinMode(strosin, OUTPUT);
pinMode(strovih, OUTPUT);
pinMode(vihh, OUTPUT);
pinMode(punn, OUTPUT);
pinMode(etuvalo, OUTPUT);
IBus.begin(Serial1); //pro micron pinniin rx
}
void loop() {
IBus.loop();
vilkut();
naytto();
if (IBus.readChannel(4) == 1000)digitalWrite(etuvalo, HIGH);
else digitalWrite(etuvalo, LOW);
if (millis() - prevsens > 500) {
sensori();
prevsens = millis();
}
}
void sensori()
{
// float pressure = bme280.getPressure();
temp = bme280.getTemperature();
humi = bme280.getHumidity();
alt = bme280.calcAltitude(bme280.getPressure());
}
void naytto()
{
switch (IBus.readChannel(5)) {
case 1000:
display.showNumberDec(alt);
break;
case 1500:
display.showNumberDec(temp);
break;
case 2000:
display.showNumberDec(humi);
break;
}
}
void vilkut()
{
if (millis() - vilkku > 1600)vilkku = millis();
int jep = (millis() - vilkku) / 20;
switch (jep) {
case 1:
analogWrite(stropun, 0);
analogWrite(strovih, 0);
analogWrite(strosin, 0);
break;
case 2:
analogWrite(stropun, 255);
analogWrite(strovih, 255);
analogWrite(strosin, 255);
break;
case 8:
analogWrite(stropun, 0);
analogWrite(strovih, 0);
analogWrite(strosin, 0);
break;
case 9:
analogWrite(stropun, 255);
analogWrite(strovih, 255);
analogWrite(strosin, 255);
break;
}
if (millis() - vilkku < 800) {
digitalWrite(punn, HIGH);
digitalWrite(vihh, HIGH);
}
else {
digitalWrite(punn, LOW);
digitalWrite(vihh, LOW);
}
}