Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7512

General • Re: Reading gpio returns incorrect value

$
0
0
I noticed something strange. If I keep read the value of gpio15 immediately after switching
gpio2 from low to high, gpio15 reports low. However if I keep reading gpio15 continuously
say like for 20 seconds it does report high as expected.
I would suggest the first thing to do is to add diagnostic reports to the on-Pico code so it can report back when it has set GPIO2 high or low, and what it thinks GPIO15 is then reading as. And diagnostic reports as to what GPIO15 is when it's being sent back. Do both by checking the physical hardware registers, not using any functions in the code. It will be worth checking any function returns do match what the physical status is.

That way you'll be able to better determine -
  • If GPIO15 is tracking GPIO2 when GPIO2 changes, whether there's a delay to setting GPIO2 when commanded to change
  • Whether the issue comes in setting the LED, what the host is being told, or in the host itself.
Perhaps make the diagnostics more understandable and obvious so those not familiar with USB can follow what is going on, and it may even help you identify the problem For example, where you have 'led = 1' which I incorrectly assumed set GPIO2 high, you could have something like ...

Code:

Got LED setting commandSelect LED 1 (GPIO2)GPIO2 is set lowReading GPIO2 shows output lowReading GPIO15 shows input low

Code:

Got SWITCH reading commandReading GPIO2 shows output lowReading GPIO15 shows input lowReplied indicating SWITCH ON
The anomaly in the last two would provide an instant pointer to where one might like to look.

I have seen USB be sluggish when sending serial data from a Pico to Thonny so it's probably worth adding timestamps as well so you can check it's not just a flood of things causing USB packet processing to grind to a halt under a backlog of packets or similar.

Statistics: Posted by hippy — Sat Sep 06, 2025 7:15 pm



Viewing all articles
Browse latest Browse all 7512

Trending Articles