I have built a little robot using the pi zero, explorer Phat, zumo chassis and ubec to regulate the voltage from the 4 AA batteries that the zumo chassis holds.
When battery powered the battery connects via one of the 5v headers on the explorer pHat.
I have just added an ultrasonic sensor to the robot and written some new code to analyse the readings and avoid obstacles. This works fine when connected to the raspberry pi power supply but if I power the robot up via the batteries nothing happens.
I have the script setup as a cronjob and if I connect my usb hub to the robot while its on battery power it suddenly continues with the script.
So it seems like a power issue when the new sensor is connected. I have connected the sensor to the second 5v header/ground and one of each of the input/output pins.
If someone can explain to me what is causing this and how to fix it that would be great. I am wondering if using a usb phone charger battery pack might make a difference?
what voltage do you read across the 5v pin on the Pi header and ground? I suspect you will be below 5v and possibly the operating minimum of the sensor.
motors run fine if for example I make a script just to run them forwards it sets off without delay.
I have been playing around and the robot does seem to come alive after a bit of time (a few minutes or so) with my script that includes the ultrasonic code.
It seems like it randomly manages to read the sensor and change the direction of the motors (perhaps a couple of times a minute)
P.S I have also tried this now with a 5v power bank and get the same issue. It still runs fine using the official power supply though.
This is my ultrasonic script.
import explorerhat
import time
explorerhat.output.one.off()
time.sleep(2)
while True:
explorerhat.output.one.on()
time.sleep(0.00001)
explorerhat.output.one.off()
while explorerhat.input.one.read() == 0:
sendTime = time.time()
while explorerhat.input.one.read() == 1:
endTime = time.time()
duration = endTime - sendTime
distance = duration * 17150
#print "Object distance: ",distance,"cm"
if distance < 20:
explorerhat.motor.one.backwards()
explorerhat.motor.two.forwards()
else:
explorerhat.motor.one.forwards()
explorerhat.motor.two.forwards()