BME280 problem

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);

  }

}

Also if I comment out the lines handling RC receiver, the sensor and display are working fine.

Please post a schematic.

Are the I2C:s somehow interfering each other

By "I2C:s" do you mean you have more than one i2c device? One is the bme280, what is the other?

Well yes the 4-digit display is an I2C device also, but I actually meant "Are the interrupts somehow interfering each other". BME280 I2C uses interrupts and so does the Flysky RC library, I'm quite sure.

Schematic in a text way..:

Arduino pins on the left.
2 - BME280 pin SDA
3 - BME280 pin SCL
8 - 4-digit display DIO
9 - 4-digit display CLK
10, 14, 16 - LEDs
RX - Flysky receiver

Grounds to the ground and positive voltage is taken from Arduino's VCC-pin.

No, your display is not i2c. Its based on TM1637 driver chip. This requires two dedicated pins. I2c devices can share the same two pins with other devices, because each device has its own address on the "bus". If it was i2c, you would have to connect it to the same two pins as the bme280. You should complain to the vendor that their description is inaccurate, and ask for a refund.

As for interrupts, what do you mean? You do not mention an interrupt connection between the bme280 and an Arduino interrupt pin or between the FlySky and an Arduino interrupt pin. So do you mean timer-interrupts?

Okay, i need to look into the display specs more closely. Thanks.

I'm not very experienced in interrupts... I know the basic principle and I remember from my 486 times that two devices having the same interrupt number is a bad thing.

I'm quite sure that I2C library uses interrupts and I suppose the flysky library uses interrupts too, because it is decoding some kind of pwm signal.

So basically my interrupt interference incompatibility was a wildish quess. I hope I'm wrong and there's just a typo or other stupid mistake.

Arduino interrupts and PC interrupts are two very different things.

I2C uses interrupts indeed, but it's also a bus designed to have many devices connected to.

I still can't figure out this problem. Any help? :frowning:

Remind us all which combinations of components work ok together, and which don't. FlySky, bme280 sensor, tm1607 display: draw a 3x3 grid and put ticks (checks) or crosses in each square as you test each pair.

A circuit diagram can also be very enlightening. No Fritzing, no omissions please. Especially how the power is supplied to the Arduino and the different sensors is of interest, that's a potential problem point. As the sensors work individually the data lines appear to be fine.

Finally I have time to get back to this a bit.
Thanks for the resposes!

Lenskari.JPG

Here is attached a schematic. It is not 100% accurate because there wasn't Pro Micro in Fritzing so I chose the closest one. Arduino is powered by USB.

-Pins for rgb led have wrong numbers
-Couln't find BME280, used BME180 instead, pins from left to right: SDA SCL GND VCC
-The servo is representing the Flysky receiver output. It is powered by the rc plane's ESC, not from Arduino.

Then for the 3x3 grid for the compatibility.
A= receiver
B= display
C= BME280

  A B C
A   V X
B V   V
C X V

That's a bit confusing actually. The display works with everything, rc receiver and BME280 don't work together.

ps. how do I show the attached image inside my post? edit: got it, thank you!

Lenskari.JPG

Sivonen:
Here is attached a schematic. It is not 100% accurate because there wasn't Pro Micro in Fritzing so I chose the closest one.

That's just one of the reasons we don't like Fritzings. Hand drawn diagrams are usually more accurate and more readable than Fritzings. Even the diagram view of Fritzing (not the colourful spaghetti view) is worse than a halfway decent hand drawn diagram...

To insert your image, you attach it and post, as you have done, then right-click on the link to the image and copy the address. Then modify the post, use the insert image icon and paste the link. Its a bit of a pain.
Lenskari.JPG

Even the diagram view of Fritzing (not the colourful spaghetti view) is worse than a halfway decent hand drawn diagram...

I think you mean "schematic view" but I wouldn't agree with that in every case. We've seen some badly done ones, yes, but I think we can mostly blame the users, not the tool, for those.

In this case, however, the OP has two important components (Pro Micro, FlySky) for which there is no Fritzing equivalent, so maybe hand drawn would be better.

Pro Micro pinout:


So for those not familiar with Pro Micro, SCL & SDA really are pins 2 & 3, and pins 0 & 1 are hardware serial pins, but not the ones used for sketch upload & serial monitor (Pro Micro emulates a second serial port over USB for that).

Maybe this one is a Pro Micro Fritzing part?

It is the first result using a search engine.

I didn't care if the picture wasn't 100% perfect, but I do believe it is 100% understandable though.
If there is something that needs explanation, I will answer any questions.

Sivonen:
I didn't care if the picture wasn't 100% perfect, but I do believe it is 100% understandable though.

It's not. Far from that, even. The fact that you already started giving text explanations tells me you KNOW it's not 100% understandable.
Blue and yellow - presumably SDA/SCL (ambiguity: which one is which? Can't tell from the image it's even SDA/SCL!) appear to be connected to pins 2 & 3, not A4 and A5 as they should (that's apparently a difference in components - and where the image doesn't match reality).
The LED: four wires, but what do those wires do? Not shown in the image. I'm guessing it's an RGB LED, and that those purple wires are for the three colours, but that doesn't tell which colour is which.
No power to the Arduino (text says USB - it's not in the image).
No power to the servo. How is this powered?
Text talks about an "RC receiver". I don't see this in the image. Oh, looking back at the text that's this servo thing. More ambiguity. Can't read from the image what pin it's connected to. That requires cross reference with another image - apparently it's TX.
So that display is a 4x7-digit one; how much power does it draw?

Sivonen,
I believe that you can add some Serial.print since the board are you using has the usb serial connected to PC free.
I don't have this board so I don't know how to print to the right serial.
I suspect that there is some noise, maybe the servo but I am not sure. Interrupt conflict may be a good reason but unfortunately most library doesn't have clear wich intterrupt they eventually use.

zoomx:
I suspect that there is some noise, maybe the servo but I am not sure. Interrupt conflict may be a good reason but unfortunately most library doesn't have clear wich intterrupt they eventually use.

Servo library uses Timer1, with related timer interrupt.
I2C has its dedicated hardware, has its own interrupts if it uses interrupts at all.
A display normally doesn't need any interrupts, and no conflicts there in the first place.
By the way: servo? What servo? Oh, that's probably just you getting confused by OP's flawed Fritzing... a servo that's in reality an RF module

Serial.print() prints to and Serial.read() reads from serial monitor, for compatibility with other types of Arduino. Serial1.print() prints to and Serial1.read() use pins 0 & 1 IIRC.

There is no servo in the actual circuit. The OP has substituted that part for the FlySky control module because Fritzing does not have the correct part in is it's library.

wvmarle, I'll explain this to you as good as I can:

-The part in the picture that has the text "BME180" is actually BME280 in real life. The pins are from left to right: SDA SCL GND VCC. The blue wire is SDA and the yellow wire is SCL.
-The led is indeed an rgb led. The order of the colors is actually not very important because they all are turned on/off all at once. It's just a test and I added it to show what components are drawing current.
-The Arduino is actually getting power from it's built in USB connector.
-There is no power to the servo, because there is no servo. Actually the servo is representing the Flysky receiver output. It is powered by the rc plane's ESC, not from Arduino.
-The text says "rc receiver" but you don't see it because the servo in the image is representing the Flysky receiver. It is connected to Arduino pin labeled RX.
-The display would draw roughly 25mA when all segments are lit, but this is just an educated guess.

Please ask more, I'll try to answer. :o

PaulRB:
Thanks! I didn't know about Serial1.print() in this model, I knew it is in Mega.
I can indeed read the Flysky data and simultaneously* do Serial.print() and view it in pc.

*(for wvmarle, I'm aware that it is not actually simultaneous, but english isn't my first language, so I didn't know a better word. Apologies.)