I have some basic code that starts the Pico, turns on the regulator to switch 5v to the SENS0208 and then triggers the SENS0208 at 5s intervals. I’ve measured 5v at the SENS0208 and see the regulator switching. I can see the LED on same blink with each cycle but the code just returns the default 200mm distance.
If I take the reg out of circuit and power the SENS0208 directly from VSYS (5v) it works a treat.
I have a Fluke 77 from last century that measure 5v across the SENS0208 but it won’t measure mA that low so I can’t see what’s happening but to my mind, the regulator must be limiting the current.
This series is still a current model. Cost well over $600 to purchase now.
As with any DMM you cannot reliably measure current on the mA ranges at the lower voltages such as 5V. There is an effect called “voltage burden” which is the voltage actually dropped by the meter itself due to the relative high internal resistance. As with most meters the current is measured by measuring the voltage dropped by this “shunt” resistor then calculated and in the case of most DMMs could be 1 or 2 volts. This will reduce the voltage applied to the “Device Under Test” (DUT) so affecting the operation of this DUT often to the point that it will no longer operate.
For current measurement in these circumstances the 10A (or 20A) ranges must be used where the internal resistor value is very low. If the meter reads to 3 decimal places that is still a resolution of 1mA which for most purposes is adequate.
To establish if the regulator is current limiting you could measure the sensor voltage (5V) but if only on instantaneously the DMM might not be fast enough in which case an oscilloscope would be a better instrument. But you probably don’t have one of those.
An alternative would be to measure the current while powered from a steady 5V supply (on the 10A range) then look up the specs for the regulator and determine if it will do the job.
Cheers Bob
Another alternative. If you are triggering at 5Sec intervals you are probably not saving much in the way of power so you might as well leave the sensor powered if that works.
Hi Mark
When you are considering the power requirement you have to consider the conversion.
If for instance your sensor requires 500mA @ 5V the current input @ 3.7V (Lipo nominal voltage) will be somewhat higher.
500mA @ 5V = 2500mW
2500mW @ 3.7V = 676mA
There will be a conversion factor loss. This conversion factor could be as high as 85%
considering 85% the required current at 3.7V will be 795mA. A notable amount of current higher than the 500mA required at 5V.
This is a fact of life often not considered
Example. I have a power bank rated at 15000mAhr. This is AT THE BATTERY (3.7V)
By the time this gets converted to 5V it becomes about 11000mAhr. I have confirmed this by measurement.
Cheers Bob
I had a quick look for some specs; please verify.
Pico 2W 3.3V pin out should be capped at 300mA (or less).
3.3V x 0.3A = 0.99 watts
(not inc. loss as per @Robert93820 comments) 0.99 watts @ 5V = 198 mA (so less when you add in conversation loss)
Best I can tell is the SENS0208 only should need 30mA to run and no real boot time before you can grab an accurate measurement.
I think the upconverter you are looking at can run up to 1Amp (or a little over). So in theory everything should be able to work to run what your trying to run.
My only thought would be around an inrush current on power up of the converter … but I could not see any specs on that.
I had not considered that. Michael is quite correct This inrush could be quite high. There could be quite a lot of capacitance to charge up.
An alternative here would be to leave the converter powered at all times and switch the 5V when needed.
Although at 30mA I don’t know if it would be worth it when you are switching every 5 Sec.
If you are concerned about battery longevity it might be worth considering leaving the converter on and doubling battery capacity by adding another cell in parallel with the existing one.
Cheers Bob
I’ve set up the Pico to run my test program from boot. The code runs to:
log onto Wi-fi
switches on the reg to power the SENS0208
runs a while loop to take 10 readings at 5s intervals
Turn off the reg.
With an AT085 on the Pico’s USB socket the load is a consistent ~70 to 80mA from start to finish. The Fluke 77 (on DC volts) shows the reg turn on (with a quick blip up to 90mA), stepping up the Pico’s 3v3 to 5v, the SENS0208 doing its cycle of 10 and the code then switching off the the 5v.
If I take the reg out of circuit and power the SENS0208 from VSYS 5v, I see the same load without the blip.
What I don’t have is the recommended capacitor across the voltage reg.
How are you measuring 90mA with the DMM on volts range. Any DMM is pretty slow so that “blip” could be anything
Are we talking across the input or output of the regulator. I don’t know that there is a “recommended” one for the output but I do see a mention of about 33µF across the input supposedly to kill any input spikes above the max input (5.5V).
Could you clarify where and how you are measuring please.
Cheers Bob
Yes that is what I saw. this one is to try and smooth out any input spikes that might damage the regulator.
I think the extra current at switch on is probably inrush current charging up some caps until the regulator does its thing. An extra 33µF at the input will increase this s bit. The AT085 is a digital measuring device and as such will have a bit of a delay so the 90mA could be a little conservative. I don’t think the AT085 would catch all of the inrush current. I don’t know how quick this device is to catch everything. This sort of thing is where an oscilloscope comes in very useful. Nice and quick.
If this sort of thing is going to give trouble as I think it will I still think you could consider powering the sensor from your 5V Vsys which you apparently have and switch that. Core have a switch which should do the job. Have a look at it SKU: CE09733
Cheers Bob
URGENT edit
Sorry, that switch is a LOW side switching device. I think what you need is a HIGH side switch using p-ch Mosfets.
The one that should work is the POLOLU-2810. Leave the slide switch to OFF and apply a logic control signal to “ON”, logic HIGH active.
Hi Mark.
Just re visited your diagram in first post where you don’t show the timer hat.
Correct me if I am wrong here.
It looks as if you have a battery connected to the hat which looks after charging with a solar cell.
The hat removes power from the Pico, re powering it when required.
The 3.3V is taken from the Pico 3.3V output (limited current) as VIN for the 5V converter only when Pico is powered.
You also control the inverter via the SHDN (Shutdown) input.
Coupled with any inrush current problems this poor old regulator might nor know what it is up to at any given time and might be getting a bit confused.
I was going to suggest that regulator VIN be connected to the BATTERY before Pico switching and the regulator turned OFF when not sensing and d talking to Pico. This would leave VIN present at all times and get rid of any inrush confusion. The regulator has only 0.1mA quiescent current which you should be able to absolve.
However on further investigation it seems that SHDN is internally pulled high with 100kΩ and has to be driven LOW to switch off. This would mean that the Pico would have to be alive to do this and if the Hat removes Pico power the regulator could not be controlled in this manner.
If you have enough battery capacity to have the regulator and sensor ON continuously and just switch the Pico (with the Hat) you could still connect the regulator permanently to the battery to give you a steady 5V without switch on inrush problems.
Cheers Bob
PS:
If you wanted to risk it you could hack the regulator and connect R6 to ground instead of VIN. That would mean that SHDN would have to be driven HIGH to switch the device ON.There might be a problem with the Pico only providing a logic high of 3.3V (might not be enough to switch) but you would have to check data sheets and possibly experiment.
If this worked you could then enable the regulator and switch power to the sensor after Pico has started up.
The schematic of the complete project is below and includes all components and yes, has the battery supply the hat via the PV charger but………..
I was having issues with the SENS0208 working so I simplified things so I could test the Pico turning on/off the supply to the SENS0208 via the Pololu regulator. The cut down, test code below.
Running the code (Thonny via USB to the Pico) I measure 5v across the 5v & Gnd pins of the SENS0208 and see it switching on/off as is meant to happen. The code cycles the distances readings as required (and the onboard LED on the SENS0208 blinks each cycle) but the distance returned is always ~250mm.
Leaving everything else as is but moving the SENS0208 5V jumper from the Reg VOUT to the Pico’s VSYS, running the code gives correct distances that vary as I point the sensor around the room. This is why I think there’s something odd about the Pololu regulator supply to the SENS0208.
# Revision table:
# r1 - Connects to Wi-Fi. Blinks the Pico LED at startup. Ultrasonic Sensor. Prints the temp and distance.
# r1-1 - Testing - As above but with a loop to test various distances.
# r1-2 - Testing - Adds the pololu U1V11F5 5v regulator to operate the ultrasonic sensor.
from PiicoDev_Unified import sleep_ms
from machine import Pin, Timer
import ntptime
import time, utime
import machine
import socket
import math
import urequests # Network Request Module
from do_connect import signal_strength, ip_add, wifi_sta
# Connect to the internet via do_connect.py, which with secrets.py must be on the pico.
from do_connect import *
do_connect() # Connect to wifi and print the connection details to the shell.
print("main.py says ------------------------------------------------------------")
# Define the pins for the Ultrasonic Sensor.
trigger = machine.Pin(2, machine.Pin.OUT)
echo = machine.Pin(3, machine.Pin.IN)
# Define the 5V reg control
shdn = machine.Pin(21, machine.Pin.OUT) # The ON trigger to the 5v regulator.
# Define and blink the Pico LED.
Picoled = Pin("LED", Pin.OUT) # Define the Pico LED.
print("Pico LED on...")
Picoled.value(1) # Turns on the Pico LED for 2s to show life.
sleep_ms(2000)
Picoled.value(0)
# On board temp sensor. This will read higher than ambient because the sensor is inside the RP2040 chip. So what's being read is the IC temp.
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
t_reading = sensor_temp.read_u16() * conversion_factor
pico_temp = 27 - (t_reading - 0.706) / 0.001721 # Formula from RP2040 documentation
# Turn on the regulator
shdn.value(1)
print("Wait 10s for US to settle....")
sleep_ms(10000)
def reboot(): # Reboots the Pico when called.
print("Reboot called")
machine.reset()
def get_distance(): # Code for the Ultrasonic sensor.
# Pulse the trigger each 10us with a pause of 2us. Must be >= 10us.
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(500) # This also dictates the time the LED is ON, as it is ON when the trigger signal is active. LED is hard to see at shorter intervals.
trigger.low()
start_time = 0 # Initialize variables
end_time = 0
while echo.value() == 0:
start_time = utime.ticks_us()
while echo.value() == 1:
end_time = utime.ticks_us()
if start_time and end_time: # Measure the time betwwen a trigger and an echo, the convert to distance.
duration = end_time - start_time
print("Duration = " +str(duration))
distance = (duration * 0.343) / 2 # Convert time to distance in mm. Use 0.0343 for cm, 0.000343 for m.
return distance
else:
return None # Return None if no valid reading
def read_format_distance():
distance = get_distance() # Call the get_distance function.
if distance is not None:
print("Distance = " +str(distance)) # Print the distance to 0 decimal place. Dec places maybe required if working in units > mm.
else:
print("Failed to get distance")
utime.sleep(1) # Controls the frequency of the reading and so the red LED on the PCB.
x=0
while x < 10:
print(f"RP2040 Temperature: {pico_temp:.2f}°C")
read_format_distance()
print("X = " +str(x))
sleep_ms(2000)
x=x+1
print("Triggering shutdown......")
print("Pico LED on...")
Picoled.value(1) # Turns on the Pico LED for 2s to show life.
sleep_ms(5000)
Picoled.value(0)
shdn.value(0)
The short answer to this would have to be the regulator is not built for this job. Some of these sensor etc modules use the voltage supply as a voltage reference if such a thing is required. Any irregularities on this supply could play havoc with readings. I am not versed enough in the operation of these particular units to have many ideas.
More confused than ever. That is not a schematic. Where is the Hat. There is nothing on that image (Fritzing sketch ???) that resembles the hat you linked.
I can guess what the modules are except the one on the bottom middle of the breadboard. What do the dashed red lines represent and what does the dashed pink one do.
The screen print is pretty difficult to read with any certainty.
You say you don’t have access to Vsys when in situ. Looks like you do from where I sit
Sorry the code means not a lot to me. For reasons apparent here I try to avoid all things 3.3V and limit my playing to 5V.
You have pretty much pinned down a problem using this regulator. You could investigate further but you would need test instruments I don’t think you have
Sounds like the regulator might not be supplying enough current, even if the voltage reads 5V. Have you tried adding a capacitor at the sensor or checked the sensor’s max current draw to see if the regulator can handle it?
I’m surprised that you have trouble at 3.3V.
I have the equivalent sensor that had been running at 3.3V with an ESP8266 quite accurately until the storm over the weekend killed it.
The rest of my environment is actually HomeAsssitant and ESPHome, so not directly comparable.
I see you have a delay in your software to allow the power supply to stabilise, but I think there may be something else in there. e.g. you are using a 500uS trigger which is way over the 10uS needed and I’d be inclined to use an interrupt to catch the echo.
Bob, its schematic…ish. The drawing is done in an old copy of Visio I have. Very easy to snip an image of a device/module/sensor/whatever, add some connectors and make it a group that I can use later.
Fritzing I find is great but a pain when there’s a device I need that it doesn’t have.
I didn’t show the timer hat as it is under the Pico and…I was being lazy. Now added.
The total load of the project when running is ~70 to 80mA. That’s the Pico and the SENS0208. My reading of the data for the regulator is that it should be good for 1000mA. If it were maxing out I’d expect VOUT to fall.