A lot of things can impact the rate of toggling a pin in a loop. Or just running a loop by itself. Having additional peripherals enabled isnât one of them.
Let me ask you this; where is this loop you are running?
You see, the thing about arduino, is that a sketch is compiled into binary that runs directly on the bare metal. There is no kernel, there is no userspace, there is no security, no access controls, and no cpu scheduler. So your loop() basically represents everything its doing (yeah I know, its a bit more than that, but for the purpose of this discussion, its adequate).
But if youâre running it on a generic computer with a full blown operating system, like Linux, then there is a huge range of things that can impact it.
For instance, if you want to make a really SLOW loop, you might run this;
#!/bin/bash
for i in {1..384000}; do
echo $(($i % 2)) > direction
done
Just to give you an idea about the performance of that loop, even running on my laptop, if I put â/dev/nullâ in place of âdirectionâ, it takes over 5 seconds to run that.
If I run the same thing on my rk3399, it takes 9 seconds! If I write out to an led brightness, it jumps up to 21 seconds. Note that while an LED is technically a gpio, there is more overhead with the led driver and with interfacing with it like that.
If you write a similar program in C, it will be much faster than that.
If you take it another step and keep the file descriptor open, it will again be faster.
If you write it as a kernel module, which is the closest youâll get to the hardware and the closest youâll get to running âlike an arduinoâ, then it will knock the socks off the arduino.