Has anybody a collection of functions or framework that can be used for replacing real hardware?

Hi everybody,

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

  • with some kind of a wrapper-function
  • #ifdef precompiler macros

best regards Stefan

More detail is needed, but it sounds like an application for a class.

Wokwi is extensible

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?

best regards Stefan

You might be interested in this project:

depends how knowledgeable you are with the various technologies used

see GitHub - wokwi/wokwi-elements: Web Components for Electronics and IoT Parts

and also youTube if you are a visual learner

Hi @ptillisch

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.

best regards Stefan

you could always try to ask nicely there

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.

I agree 100% with that. Really timecritical things can only be tested on real 1 to 1 hardware.

My initial question was more into the direction of having some kind of a framework that makes it easier to write code like

#ifdef realHardware
  if( digitalRead(myIO_Pin) == HIGH) {
//...    
  }
#endif

#ifdef SimHardware
  if( mySimulatedRead(myIO_Pin) == HIGH) {
    //..
  }
#endif

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

best regards Stefan

So as a related but somehow different question:

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 ?

best regards Stefan

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 :slight_smile:

"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)

2 Likes

lol lmao rofl :smiley: :grin: :laughing: :sweat_smile: :rofl: :joy:

Yeah nowadays you gotta stay politically correct =)

What about FreeBSD?

I'm sure I don't know what you mean.

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.

a7

do you mean FreeZzzzBSD?

I get really depressed now, because I use all of them.

:wink:

I use Apple and Linux - the other not so often but they are out there for a reason, so some people must use them

I feel like we could go on longer, but I realize it's a thread 'bout something else :upside_down_face:

Sorry threadcreator! :hibiscus:

On an OS that slices tasks thicker than a whole millisecond where Arduino can task 10's of times each.

In the case of a virtual stepper, it won't see the blocking either!