wokwi / wokwi-cli

Wokwi Command Line Interface (for CI use cases)
MIT License
14 stars 5 forks source link

rp2040 (pico) bug in ADC, always read 0 in wokwi-cli #14

Closed rafaelcorsi closed 3 months ago

rafaelcorsi commented 3 months ago

Hi! I noticed there might be an issue with the ADC functionality when using it via the CLI. To facilitate reproduction of the bug, I've created an example project available at:

Description:

The project consists of a simple C program for the RP2040/Pico/PicoW that reads from the ADC and outputs the analog value to the UART/terminal. When simulating the circuit using the diagram simulation, everything works correctly. However, when executing the simulation through the Wokwi CLI with wokwi-cli --scenario test.yml, the ADC value is consistently reported as 0.

I've also tested connecting the ADC port on PICO to the VCC, to check if the problem is with the potentiometer, and it gives the same value, so I think that the problem is on the pico side.

Diagram works!

image

wokwi-cli erro

image

urish commented 3 months ago

Thanks for reporting! I believe the issue here is that since we don't have the UI, the initial value for the potentiometer is 0, and is not read from the diagram.json. Looking into this.

urish commented 3 months ago

Quick workaround: setting the pot value immediately after the simulation starts, e.g.

name: exe1
author: Rafael Corsi
version: 1

steps:
  - delay: 1ms
  - set-control:
      part-id: pot1
      control: position
      value: 0.5
  - delay: 300ms
  - wait-serial: 'adc 1: 2047'
urish commented 3 months ago

Fixed - the initial value of potentiometer should now match between wokwi.com and the CI.

Thanks again for the detailed report with a reproduction repo, it really helped in reproducing and solving the issue as quickly as possible.

rafaelcorsi commented 3 months ago

It worked! thanks!

By the way, I owe you a message on LinkedIn so we can talk, I want to show you how I integrated your tool into my course

Fixed - the initial value of potentiometer should now match between wokwi.com and the CI.

Thanks again for the detailed report with a reproduction repo, it really helped in reproducing and solving the issue as quickly as possible.

urish commented 3 months ago

Very curious to hear about that :)