Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:36 01 Mar 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Enhancing Pi Pico Voltage measurement

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1037
Posted: 04:57am 01 Mar 2026
Copy link to clipboard 
Print this post

I want to get a Pi Pico to accurately measure voltages on an analog input. I have been using the attached input circuit to auto range by outputting a ground from a dig out pin to alter the voltage divider hence the range for the measured voltage.




R1=1M0
R2=10K
R3=100K
R4=1M0 (R4 is always grounded)
D1=Schottky Diode

Here is a snippet of code I was using for the F4 ArmMite.


  ' Autoranging here
  Vm=Pin(PA0): Pause 100
  Volts=103.05*Vm                            'CALIBRATION EQUATION

  If Volts < 20 Then
   Pin(PA1)=1:Pin(PA2)=0                     '20V setting
   Vm=Pin(PA0): Pause 100
   Volts=12.05*Vm                            'CALIBRATION EQUATION
   BL=1:BEEP
  EndIf
  If Volts < 2 Then
   Pin(PA1)=1:Pin(PA02)=1                    '2V setting
  ' Pin(PA3)=0
   Vm=Pin(PA0): Pause 100
   Volts=2.05*Vm                             'CALIBRATION EQUATION
   BL=1:BEEP
  EndIf

  If Volts > 9.999 Then V$=Str$(Volts,2,2) Else V$=Str$(Volts,1,3)
  Text MM.HRes/2, MM.VRes/2 - 30,V$ , CM, 6, 2, RGB(white)
'  This code to emulate decimal point not available on first fonts
'   If Mid$(V$,2,1)="." Then Offset=95
'   If Mid$(V$,3,1)="." Then Offset=155
'   Circle Offset, 130, 6, 0, 1, 0, RGB(white)
  Text 150, 160, Date$, CM, 2, 1, RGB(Green)
  Text 150, 190, "UTC "+Time$, CM, 2, 1, RGB(Green)
  Offset=0

  DrawButton 0, 0, 0, 210, 90, 30, RGB(Red), "EXIT"
  DrawButton 1, 0, 110, 210, 100, 30, c.ghosttext, "HOLD"
  DrawButton 2, 0, MM.HRes-90, 210, 90, 30, c.ghosttext, "LOG V"
'   CheckButtonRelease btn
  If LogV=1 Then           'Log every 10 seconds
    If Right$(Time$,1)="0" Then Print "UTC,";Date$;",";Time$;",";V$
    Pause 800
  EndIf
  If LogV=2 Then           'Log every minute
    If Right$(Time$,2)="00" Then Print "UTC,";Date$;",";Time$;",";V$
    Pause 500
  EndIf
  If LogV=3 Then           'Log every hour
    If Right$(Time$,4)="0:00" Then Print "UTC,";Date$;",";Time$;",";V$
    Pause 500
  EndIf
 Loop
WatchDog 4000
End Sub


Can anyone help with suggestions to improve accuracy with the input circuit or the software?

OA47
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6479
Posted: 06:30am 01 Mar 2026
Copy link to clipboard 
Print this post

The Pico doesn't do Open collector DOUT.

Jim
VK7JH
MMedit
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3042
Posted: 06:47am 01 Mar 2026
Copy link to clipboard 
Print this post

  Quote  The Pico doesn't do Open collector DOUT.
Yes, a bit annoying that.
In some situations you can simulate it with a diode, cathode to the pin (Schottky is best).

In this case the non-linearity of a diode would affect accuracy so you need to do it with SetPin commands.

PIN(x) = 0 : SETPIN x, DOUT 'switch to ground
SETPIN x, OFF 'open collector (drain)
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026