DigitalWrite slows down

userHead Sc4r3Cr0w 2018-03-01 19:04:56 1042 Views1 Replies
Hi,

i want to controll a step motor with my lattepanda and have some trouble doing so ... Everything runs fine but after some iterrations the digitalWrite slows down. Here is my Code (I use C#):

Code: Select all

public static void SimpleStepMotorTest() { var arduino = new Arduino(UserSelectPort()); arduino.pinMode(10, Arduino.OUTPUT); Console.WriteLine("Press to start ..."); Console.ReadKey(); for (int i = 0; i < 1000; i++) { var watch = new Stopwatch(); watch.Start(); Thread.Sleep(5); arduino.digitalWrite(10, Arduino.HIGH); Thread.Sleep(5); arduino.digitalWrite(10, Arduino.LOW); Console.WriteLine($"Step {i} ({watch.Elapsed})"); } Console.WriteLine("Done"); Console.ReadKey(); } And here is the output on the Lattepanda ...
Image

as you see one iteration of swithing from LOW to HIGH is so slow that it takes up to 4 sec.
The delay is defnetly comes from calling _serialPort.Write in the Arduino class

Why is that ?
And how can i fix this ?