Skip to content

VL53L1X sensor "Timeout" when using stepper motor and the sensor simultaneously. #16

@mluthfialhadi

Description

@mluthfialhadi

Hi, I am working on STM32F1 Bluepill with VL53L1X and Stepper Motor NEMA 17 (DRV8825).
Has anyone know why my VL53L1X became "Timeout" when I use both stepper motor and sensor?
I could use the sensor or the stepper separately.

Sorry for my bad English.

Here is my code and screenshot of the circuit.
skematik fritzing
ss_serial_monitor

#define DIR PA8 #define STEP PB15 #include <Wire.h> #include <VL53L1X.h> #include <SparkFunIMU.h> #include <SparkFunLSM303C.h> #include <LSM303CTypes.h> LSM303C myIMU; VL53L1X sensor; long jarak = 0; int sudut = 0, angle = 0; float totalx = 0, totaly = 0, totalz = 0, xmag = 0, ymag = 0, zmag = 0; int steps = 0, stepmaks = 800; unsigned long tbefore = 0; boolean cond = 0; void setup() { // put your setup code here, to run once: pinMode(DIR, OUTPUT); pinMode(STEP, OUTPUT); //while (!Serial) {} Serial.begin(115200); Wire.begin(); Wire.setClock(400000); // use 400 kHz I2C sensor.setTimeout(1000); if (myIMU.begin() != IMU_SUCCESS) { while (1) { Serial.println("Failed to detect and initialize sensor!"); } } if (sensor.init() == false) { Serial.println("TIMEOUT"); } else { sensor.setDistanceMode(VL53L1X::Long); sensor.setMeasurementTimingBudget(200000); sensor.startContinuous(50); } int langkah = 0; //float angle=0; boolean kon = 0; while (xmag > 0.002) { kon = !kon; digitalWrite(STEP, kon); if (kon == 0) { langkah = langkah + 1; angle = map(langkah, 0, stepmaks, 0, 360); } xmag = myIMU.readMagX(); // Serial.print("\nMagnetometer:\n"); // Serial.print(" X = "); // Serial.println(xmag, 4); delay(10); } } void loop() { if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); } xmag = myIMU.readMagX(); if (micros() - tbefore >= 50000) { tbefore = micros(); steps += 1; cond = !cond; digitalWrite(STEP, cond); if (cond == 0) { jarak = sensor.read(); sudut = map(steps, 0, stepmaks, 0, 359); if (sudut > 359) sudut = 0; String dt = "<"; dt += String(jarak); dt += "+"; dt += String(sudut); dt += ">"; Serial.println(dt); } } if (steps > stepmaks) { steps = 0; } } 

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem right

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions