VL53L0X how to use in same time?

Hi, I have a question, how can I use my laser sensor(VL53L0X) in same time with the stepper motor, the motor and the sensor needs to work independent each other, I think I need to use the milis function, becasue when I use separate the motor and the sensor, it's works fine, but when I use the code for together module, nothing

Where in your sketch are you controlling a stepper motor?

yes,a Nema 17

It works fine I tried it

Well, if it works fine, I guess we're done here.

Noo, the laser sensor not working together, this is the problem

And I will ask once more and be done: where in your sketch are you controlling a stepper motor? I don't see any code to do that.

So I controlling the motor with tone function,but the motor controlling and the laser sensor needs to work separate.

For your stepper to work it must receive "step" commands. Somehow you are using the PWM of tone() to step your stepper... but you need to NOT use tone because this blocks any other functions. You must learn to give the stepper motor a step pulse at its required interval. Doing this with your stepper motor will allow you to read your VL53L0X at its required interval.

All this is based on using the easy-to-use "millis()" function. Using millis() you will start a timer, determine if your timer has run a pre-programmed time, then make the device (stepper, VL53) do its job, then go back to reading the timer.

You can find many examples of "millis() stepper motor" and "millis() vl53" ... have fun.

I still don't see anywhere in your code where it's controlling a stepper motor.

Nowhere do you send pulses to the step pin to presumably make your mystery motor driver step.

All you do is tell the aforementioned mystery motor driver to reverse direction 300 times a second near the end of setup(). Why you would do that is beyond me.

Then you sabotage even that by hammering the direction pin to 0 every time through loop().

I'm throwing in the towel on understanding this one.

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