wokwi-features icon indicating copy to clipboard operation
wokwi-features copied to clipboard

Resistor divider simulation

Open urish opened this issue 4 years ago • 17 comments
trafficstars

Resistor dividers are useful for connecting multiple buttons to a single analog input pin, as described here. This is particularly useful for MCUs with limited number of IO pins, such as the ATtiny85.

Currently, Wokwi includes a very basic analog simulation: You can connect a single part (e.g. a potentiometer or an analog temperature sensor) to one or more analog input pins. However, if you add any resistors to your analog circuit, the simulator will ignore them.

Let's simulate them!

urish avatar Oct 09 '21 18:10 urish

Great idea. I agree. I am not great on GiHub, but is there a formal way to vote?

MykolaKyrylenko avatar Oct 10 '21 04:10 MykolaKyrylenko

Thank you! The way the vote is on the features page, using VotePowers. You can vote for any feature as many times as you want. I'm still working on a more detailed FAQ that explains how this works, but here is a quick explainer.

urish avatar Oct 10 '21 07:10 urish

This would be great.

In the interim would it be possible to make the potentiometer have hot keys for values so we can simulate the same thing? At the moment Home = 0, End = 1023. It would be great to add other keys and mappings for that device, eg 1 = 100, 2 = 200 etc so we can simulate buttons on a voltage divider by just connecting the potentiometer and pressing one of the hot keys?

JCalvi avatar Jul 13 '22 12:07 JCalvi

In the interim would it be possible to make the potentiometer have hot keys for values so we can simulate the same thing?

Sounds like a good suggestion. There's also page-up/page-down that jump up/down, but not to a specific point. If anyone is interested in hacking on this, you can add a new keyboard event listener here, and then check if the key is 1, 2, 3, etc. and modify the value accordingly.

urish avatar Jul 20 '22 07:07 urish

While waiting for this, there's some workaround: you can achieve a similar functionality by implementing a custom chip (see #301 for details). Here's one example showing how to use a custom chip to simulate multiple analog buttons connected to a single analog input:

https://wokwi.com/projects/339700374803841619

urish avatar Aug 12 '22 06:08 urish

The custom chip works well BTW. Thanks for the suggestion.

JCalvi avatar Dec 12 '22 06:12 JCalvi

Oddball suggestion, but instead of implementing further simulation in the backend, maybe borrow the simulator from https://github.com/SEVA77/circuitjs1?

P.S. This is an awesome project. I'm so glad I found it.

kubark42 avatar Mar 03 '23 02:03 kubark42

Thanks for the suggestion @kubark42!

The funny thing about "circuitjs1" is that it's actually implemented in Java and compiled to JavaScript.

In any case, we already have a solution for the analog simulation part of this feature. The main challenge is how to integrate it into the existing simulation framework while keeping the performance high and not breaking existing projects which rely on the current behavior of resistors.

Right now, this feature is #8 in the requested feature list, let's see how long until it makes it to the top :-)

urish avatar Aug 01 '23 16:08 urish

2 years later, still not implemented

martinius96 avatar Sep 18 '23 19:09 martinius96

1.5 months later, and now it's number 6 on the list

urish avatar Sep 18 '23 19:09 urish

Prioritization should happen for important things and urgent things. It isn't a great optic when it takes 2 years to do something as simple as a resistor divider. Maybe it's a heck of a lot of work on the backend, and that's why it isn't happening. But if prioritization comes down only to votes, then low-hanging fruit never gets prioritized. Typos and documentation errors will endure effectively indefinitely if only the most highly voted features get implemented.

Looking at the prio list, some things are jaw-droppingly difficult, such as an offline simulator. Le'ts hope that resistor dividers are easy and can find their way into the queue before the devs tackle offline support and its almost infinite number of computer configurations.

kubark42 avatar Sep 18 '23 20:09 kubark42

I'm wondering - how much work time do you estimate the resistor divider would take?

urish avatar Sep 19 '23 04:09 urish

Nothing against you, but this functionality of voltage dividers is already in the worst simulator TinkerCAD... That does not have other important features for which I switched to Wokwi.

Dont know how simulation in Wokwi works, if it is not like "circuit" simulation, but more cpu only simulation with peripherals.

martinius96 avatar Sep 19 '23 07:09 martinius96