Arduino Nano V3 only runs sketch correctly after hitting reset or starting serial monitor

Should I remove the serial.xxx codes? but if that is true, why does the reset solve everything?

What is the output in the failing case?

If the BME's can not be found, but are found after a reset,
what happens if you try to init them a second time?

You could add an i2c scan function to the sketch.

All this:

can be replaced by

#include <printf.h>
#include <RF24.h>

and, because you don't use printDetails() even by

#include <RF24.h>

I glanced over your sketch and very much dislike its while structuring,
the blockiest thing I've seen for a long time.
A state machine should work much better.

The duplicate BME initializations deserve a function.

The whole sketch needs a clean-up and an auto-format.

Give me some credit man!! My first code ever! :smile: and it works, AND it os not merely a blink code, come on :sweat_smile:

Many many thanks for the feedback!! I will optimize it, definitely!

Some minus 3000 something! Waaay off point!

Oh wait!!! Do you think the sensors work, but some other function doesnt? Maybe the sqr formula?

Your first code? See me impressed.
Nevertheless your intuitive approach (while) is not a good way to go.
You have obvious states in your processing, handle them by a state machine.

I referred to the sketch output of the BME initialization after a power on, that leads to malfunction.

Will google what that is, so far i know if statements and whiles and some other conditions.

I wanted the while because i wanted to time the loop.

Please elaborate! I think i dont follow!

I don't have a state machine tutorial link at hand, but maybe some readers could supply that.

You should probably learn the switch statement,
which comes in handy to implement a state machine.

For the NRF part, you should probably use RF24_250KBPS,
which has a longer reach and higher error margin.

https://nrf24.github.io/RF24/classRF24.html#aeb9920e7a95699748b003c4a839b0814

According to the equations it gives a zero, when dynamic pressure increases it give an output

Am I going to be able to time my functions without delays? That is why i used the while function here thou it is bulky!

If you learn how to use millis() for timing, sure.
But that is very easy, for example like so

void loop() {
  static uint32_t lastSent;
  uint32_t topLoop = millis();
  if (topLoop - lastSent >= sendInterval) {
    lastSent = topLoop;
    send();
  }
}

Many thanks! First i jave to solve the reset issue! Its frustrating!

Hi,
Can you please post a full schematic?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Hi Tom,

Please ignore the nrf24, i have dettached it for debugging! Ignore it even in the code, consider it commented out.

By the way, I have ordered an original arduino, the three i have are clones with the CH320 chip! Maybe the ftdi handles the power sequence better.

Today I found a weird test result! So when I hit the reset button the code runs, but I noticed that this only works if I hit the reset after the code went past the setup loop already! To be more specific, i put a delay at the beginning of the setup loop, and hit the reset while in delay! That didnt get it to work correctly. I must wait till the void loop is reached, then i should hit the reset. And then it sets everything right and works.

Very weird indeed what happens here! Many people suffer the same issue, and no solution to be found, it sucks.

Hi,
I2C... SDI and SDA ????
I2C SCL SDA... Have you got 4k7 pullup resistors on the SCL and SDA lines.

Pins numbers on your circuit diagram will also help.
Where and what is your supply when the USB is unplugged?
Please include...

Tom... :smiley: :+1: :coffee: :australia: