I am using NR to help control my astrophotography barn door star tracker. The set up currently consist of a RPi 3b running astroberry that's controlling a 28byj48 stepper motor.
I'm having issues with timing accuracy/latency. For example, If I set the Motor to run at a certain speed for 10 mins, it will actually end up finishing about 1 min later than it should have. The end result is images full of star trails...
So my question is: what is the best way to achieve precise timing that is relatively cheap and doesn't require anything more than basic skills?
So far I've considered
- Using an analogue motor and PWM
- Adding a micro controller to the set up specifically to drive the stepper motor
Are there any other options I should consider? If not, which of the above would result in better accuracy?
10% timing inaccuracy seems a bit suspect
Can you post a flow what shows the problem
Or just run it for 9 mins .......
As neither Linux nor Node.js (and hence Node-RED) are real-time services, some level of error is to be expected and is hard to quantify since it depends on so many other things.
My recommendation would be to use a dedicated microcontroller which IS typically a real-time system. Then you can drive that from a Pi with Node-RED.
@TotallyInformation Yes you're completely correct and this is something I wish I knew beforehand - but thats the fun of learning as you go. But this error is too significant for this project.
@cymplecy Agreed. It seems to be pretty consistent at 10% too, but not consistently inconsistent enough to be reliable.
Not really a viable solution. The flow basically turns human friendly input parameters (RPM, duration of run and direction) into arguments that are appended to the execution of a python script. As a result of running for slightly too long, the stepper motor also runs too slowly - and this is the biggest issue. If I can't get accurate speed out of the stepper motor then I'll end up with unwanted star trails.
Here is the flow. This is only responsible for starting the stepper motor - there is no ongoing activity while the motor is running. When the motor IS running, the CPU usage on the Pi remains low (less than 25%). I wasnt able to upload the code to this post as it exceeded the character count.
If I were to go down this route, which micro controller would you recommend?
What is the level of timing accuracy you are looking for?
If you only pass parameters to the codes to run the motor, then a C program can provide micro seconds level accuracy for RPI 3b. An easy to use C library is pigpio, which has hardware timed PWM functions for Pi GPIOs.
To add to what @davidz says - the pigpio library is accessible from Python so no need to go down into engine room and use C
But I've not used Pipgpio to drive 28BY steppers so wouldn't know what facilities the library has to do this myself
But as davidz says, it uses hardware timing so it should be absolutely accurate on timing so worth investigating before switching over to a microcontroller
 If you can't find some easy to use code from googling - I'd go and ask about this on the Pi forum
Well, the ESP devices have the advantage of WiFi built in and they are still very cheap. The ESP32 in particular has RTOS on board and has dual processor cores so is excellent for real-time processing. You can still connect them over a wire should you prefer that.
In addition, they have excellent firmware variations so you may not even need to go too far down the C++ rabbit hole. The ESPHome firmware for example supports many sensors out of the box but still lets you add custom code as you need to.
I put a call out on twitter and got this link tweeted at me
Try it out and let us know if it does the job