sorry for the inconvenience, I am now using the VL53L0X (but I had tried to lower the clock speed in VL6180X with no results).
I am using pololou library, the sketch is an example from the library:
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
// Wire.setClock(50000);
Wire.setClock(50000L);
Serial.begin(9600);
Wire.begin();
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1) {}
}
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor.startContinuous();
}
void loop()
{
Serial.print(sensor.readRangeContinuousMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
Indeed, now something happens ( i am measuring freq in the SCL of arduino).
Without the Wire.setClock the freq is 100KHz
using Wire.setClock(200000L); the freq is 200KHz
using Wire.setClock(50000L); it remains 100KHz
Probably arduino nano 33 iot does not allow lower than 100KHz clock speeds in I2C. Have you sth in mind to lower the I2C speed without changing the arduino?
As I mentioned previously, I am not at all knowledgeable on this subject. The fact that I was able to identify the problem with the order of the function calls was a bit of a fluke.
So far I have been fortunate enough to find that the Wire library worked just fine for my project without having to adjust the clock.
Fortunately some of the other helpers here on the forum are very knowledgeable on the subject of I2C and the Wire library so I'm sure they'll be able to advise you.
I didn't incorporate the pull-ups because I will use a quick endpoint (adafruit) to immunise the I2C from noise when I will add the stepper.
Now, the circuit has failed to function properly, so I am going back to implement it again by scratch. It is a really mesh... I think that if I could decrease the clock speed, this would help a lot to function properly.
That only makes the noise problem worse.
As I already said, keep all wires and connections to the motor and driver far away from the I2C wires and connections. Make sure everything is properly grounded. Don't use the same supply for the motor and nano
Jim-p, you were right, the problem was initiated from the fat that I used the same power supply both for the stepper and electronic (through a 3V3 voltage regulator).