Has anyone had success using ADC(3) / GPIO29 to read VSYS on the Pico W and still have WiFi working ?
The Pico has a really nice feature where you can read the voltage on VSYS to determine the battery state. The Pico W has the same but uses the pins for the SPI interface to the WiFi Chip. If you setup the pins to read VSYS, the WiFi no longer works. If you just read the ADC(3) it returns the wrong value.
I have found a work around; but the documentation has nothing other than the following two lines.
I check VSYS before importing the network library.
The pin definitions must be reset when the library loads. This works ok.
Power to the Pico W is controlled by a Makerverse Nano Timer. When it wakes I wanted to check the battery voltage and send a WiFi message saying “battery low”. If the battery is ok it reads a temperature sensor and sends that; then activates the next Timer cycle.
The program works nicely, messages are sent and received ok and using the Nano Timer a 120mAH LiPo lasts about 10 hours. Much longer than I was expecting.
Reading VSYS works nicely too and the voltage matches that measured with a multimeter, within 0.1V.
I understand the problems with trying to run a SPI clock and read an ADC value.
Probably both are not possible.
Anyway, can always use one of the external ADC pins. With appropriate voltage divider resistors of course.
Great write-up! I’ve used voltage dividers to measure 6S 26V LiPos before, on a Pico, and it worked quite well for a simple fuel gauge.
So what you’re saying is that driving the CS pin high (which I assume disables the SPI CLK on 29, allowing you to read the ADC?) doesn’t work?
I think the problem is assignment of GPIO29 pin as input to measure VSYS.
It is listed as a clock pin to the CYW43439 so setting it to output probably kills the clocking.
GPIO25 is chip select to the CYW43439; setting it to output does not really affect anything.
Reading ADC(3) without setting GPIO29 to input returns an incorrect value.
Setting GPIO29 to input returns the correct value, but the WiFi not longer works.
Also GPIO25 must be high for the value to be correct.
From Pico W schematic.
From Pico schematic.
There are a few differences. 200k/100k/1n cap, 20k/10k and placement of divider.
A number of times I think it solved it only for it to not work correctly after a power reset.
I think adding the WiFi has removed the ability to read VSYS in the Pico W. In my project I am now using ADC0 with a voltage divider to read VSYS. Can be done in normal program operation, so sending a battery low message works nicely.
I suspect Raspberry Pi brought WiFi to the Pico in a hurry to address other manufactures addons or board extensions. Maybe there is a way to stop the WiFi clock, measure VSYS then start the CLK again. But I cannot find anything documenting it.
Maybe there is a way to stop the WiFi clock, measure VSYS then start the CLK again. But I cannot find anything documenting it.
Hmmmm I wonder how they generate the clock in MPy, probably just a timer? PIO maybe? I’ll see if with my limited knowledge I can do some digging to see where this is set up in MPy.
I’m sure you could find this faster than me, but you’ve already solved your problem so there’s not much impetus for you to do so.
Reinforces some of my earlier statements in other posts regarding getting to market too early and depending on the end user to do the final test and trouble shooting.