the WOKWI-simulator offers quite a lot of hardware. But thinks like a limit-switch that can be (still virtual as it is a simulation) but virtual-physically connected to a steppermotor is not possible.
If it would be possible the limit-switch would really switch if the stepper-motor-axle rotates to a certain position. I guess lot's of developping-effort.
For testing the logic of code - in case all the hardware is working as expected - functions could be used.
For testing the code-logic it would be sufficient to write a function that takes the step-pulses as input and counts up/down depending on the direction-signal and if a certain number is reached change logic level of a simulated input-pin.
So what I am thinking about is to have macros that insert a
digitalRead(input_Pin);
for real hardware
or
when in simulation-mode a
digitalSimRead(simlation-function)
returning LOW / HIGH based on whatever input
As an example giving the framework how to realise it
You could create a component that is like the stepper motor or servo and add two outputs which would be your limit switch and parameters which would say when the switches trigger (angle)
Do you have to pay for this?
If yes how much?
Is it poorly documented the same way as the JSON-attributes or is it well documented how to create such extensions?
thank you for posting the link. At first glance it looked interesting.
Especially this sentence
enables running unit tests against the library without hardware present
So I started reading.
Though it is the same as with WOKWI
The documentation expects more knowledge than I have.
Now this sounds as I don't want to learn. Well if the documentation does start at a knowledge-level that is much higher as my own knowledge-level I turn away for practicial reasons.
If it would take me some weeks to learn the knowledge just to start with it for me this is too long.
I see this the same as using a computer or a microcontroller in general:
I want to use it without knowing
how the designing of the logical circuits is done
how the die manufacturing process of the die is done
how to design a PCB / a 4-layer or 8 layer-motherboard with whatever software
etc. etc. etc.
With a computer as the complete product you can just use it.
It is developed to a stage that is
easy to use.
Using the WOKWI-simulator on the level of
drag and drop components, click-move-mouse to add a wire, lookup button-contacts
is very easy.
This is not the case with WOKWI-elements nor with Arduino_CI
I can't blame anyone for whatever documentation because it is all voluntary.
Though if a community is interested in more contribution than
from a few nerdy-geeky-freaky experts the documentation must have a real high quality-level.
We use microcontrollers to run motors that MUMT OS's (like Windoze, Crapple, and Linux) CAN'T DO because their tasking is not finely grained enough. In Arduino terms. they block a lot.
So if I run a simulator with trick code on such an OS, it won't miss 10 millis here and there? I wouldn't bet much on that.
I don't think that WOKWI is going to get Arduino timing right. If you make the code synchronous then the order will be forced right but the timing will suffer and asynchronous code won't work the same on an Arduino. There's a limit to what WOKWI can test.
Just as pseudo-code
or even some kind of wrapper-functionality that does all
ifdefs internal
so from "outside" the code looks like
if (digRead(myIO_Pin) == HIGH) {
//...
}
and depending on a global flag that indicates real hardware or simulated hardware
digRead(myIO_Pin)
will be replaced by function-calls to
digitalRead(myIO_Pin)
or
mySimulatedIO(myIO_Pin)
This thread was inspired by this other thread
where a user works on a project that has three stepper-motors and a servo.
The machine has to do a lot of steps in a particular manner driving the three stepper-motors to different positions. Again and again in the same order.
For this state-machines are used. And now for testing the state-machines logic
it would be nice to have the possability to simulate the movement of the stepper-motors
by a software-mechanism as roughly described above
How would you write compiler-directives that would choose between making the compiler see and compile
the real digitalRead()
or a simulated
mySimulatedDigRead()
And how can this be done in the most compact way ?
well they do have "low latency" API (like Thread QoS) that are necessary for playing 8K videos with sound synchronisation etc... what they really lack is the pin interface.
All operations compete to use finite resources—CPU, memory, timers, and so on. if you want the system to remain responsive and efficient, you need to prioritise the various asks and make intelligent decisions about when to execute them. This is true as well for your arduino - if you saturate the interrupt system with higher priority interrupts than your PWM or have code disabling interrupts, you'll have issues too.
PS:
you forgot an S for linux — 'Linsux' — if you don't want to start a religion war
"Windblows, Crapple and Linsux" all in the same bag (and I happily depend on Crapple for typing this - not so crap in the grand scheme of things)
wokwi runs the code that the IDE toochain produces on an emulation of the processor that code runs on.
The wokwi can have trouble keeping up with real time. Usually on the desktop, however, I get reports of 100 perecent, meaning it is executing the same program at the same speed as real life.
I do wish there was a mechatronic wokwi version that had physical modeling for limit switches and stuff like that.
I have had some fun using leftover processor resources to model the physical conditions. Being able to use multiple Arduino boards would be nice.
And the custom parts look interesting. I looked then looked away - life too short.