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

  • VCC pin from both sensors to either 3.3V or 5V. If you are using an Arduino Uno, use the 5V pin.
  • GND pin from both sensors to the GND pin on Arduino.
  • SCK pin from both sensors to the I2C clock SCL pin 28 on Arduino nano. On the Arduino Uno that would be the pin A5.
  • SDI pin from both sensors to the I2C data SDA pin 27 on Arduino nano. On the Arduino Uno that would be the pin A4.
  • Leave the CS pin from both sensors unconnected.
  • Leave the SDO pin from only one sensor unconnected.
  • Connect the SDO pin from the other sensor to GND.

All tried, USB from PC, works only after reset or openning serial monitor.

12V 1A to the vin pins same situation.

I didnt know what Pullups are, I have taken a look and they make sense now! I think the bluedot board has them on.

SOLVED!

So I have placed a cap between rst and gnd, to be able to enter the serial monitor without triggering the reset that would restart and correct the issue. I have noticed that the correction value is calculated way too high. that was a direct pointer that at the moment of the calculation one sensor is way off. I have added a delay between the sensor reading and the calculation of the correction, and that solved it. I have accurate measurements and functionality on all power sources with power cycling of different intervals.

@Whandall Many thanks, I have learned from you what state machine programming is, I will convert my code to one, it will be simpler.

@TomGeorge Many thanks to you as well! you made me learn pullups and pulldowns. Very interesting.

Regards,
Rami

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.