User avatar
micksulley
Posts: 166
Joined: Sat Mar 03, 2012 11:48 am
Location: Melton Mowbray, England

Under Voltage Detection - Early Pi - Resolved

Fri Mar 17, 2017 7:39 pm

I used some code I found here - viewtopic.php?f=29&t=82373&hilit=under+ ... l&start=75

Code: Select all

#!/usr/bin/python

#from https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=82373&hilit=under+voltage+via+terminal+terminal&start=75

import RPi.GPIO as GPIO , time
from subprocess import call
import shlex
import sys

import signal

def handler(signum, frame):
#   call(shlex.split("echo -ne '\e[u''\e[0m'"))
   sys.exit()

signal.signal(signal.SIGINT, handler)

redLED=35
GPIO.setmode(GPIO.BCM)
GPIO.setup(redLED, GPIO.IN)

powerlow=0
#call(shlex.split("echo -ne '\e[s'"))
while True:
   if(GPIO.input(redLED)==0):
      call(shlex.split("echo -ne '\e[s''\e[1;56H''\e[1;31m'POWER dipped below 4.63v'\e[u''\e[0m'"))
      powerlow += 1
   else:
      powerlow = 0
      call(shlex.split("echo -ne '\e[s''\e[1;78H''\e[1;31m'ON'\e[u''\e[0m'"))

   if (powerlow  > 3):
      break
   
   time.sleep(1)

#call(shlex.split("echo -ne '\e[u''\e[0m'"))
print "Low power for " + str(powerlow) + " seconds"

to detect under voltage. It works fine on my newer Pi's but I have just added a hard drive to an older one (UK board (c) 2011.12) and it detects under voltage (POWER dipped below 4.63v). I have a genuine 2.5A Pi supply, and when I measure the voltage it is 5.01 +/-0.02
Is there a problem using this code with an older Pi? If so is there some code that will work?
Last edited by micksulley on Fri Mar 17, 2017 11:07 pm, edited 1 time in total.

User avatar
rpdom
Posts: 16112
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 8:04 pm

The very early Pi had no voltage detection circuit. There is no code that will work on them. The earliest Pi that had that circuit was the A+/B+

User avatar
micksulley
Posts: 166
Joined: Sat Mar 03, 2012 11:48 am
Location: Melton Mowbray, England

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 8:32 pm

Thanks for the reply. Out of interest how can I tell which model it is? cpuinfo has this-

Code: Select all

processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000e
Serial		: 0000000026047082

User avatar
DougieLawson
Posts: 37109
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 8:39 pm

Easiest is cat /sys/firmware/devicetree/base/model which tells you in nice words rather than the strange arcane coded value from cat /proc/cpuinfo.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rpdom
Posts: 16112
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 8:43 pm

You can look on here for some models http://www.raspberrypi-spy.co.uk/2012/0 ... d-version/

Your 000e revision says that it is a Raspberry Pi B rev 2 with 512MB RAM, which came before the B+.

You can also get the version with this command

Code: Select all

cat /sys/firmware/devicetree/base/model;echo

fruitoftheloom
Posts: 21644
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 8:47 pm

micksulley wrote:Thanks for the reply. Out of interest how can I tell which model it is? cpuinfo has this-

Code: Select all

processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000e
Serial		: 0000000026047082
000e model B 512MB

http://elinux.org/RPi_HardwareHistory
Retired disgracefully.....
......to a more gentile life !

User avatar
micksulley
Posts: 166
Joined: Sat Mar 03, 2012 11:48 am
Location: Melton Mowbray, England

Re: Under Voltage Detection - Early Pi

Fri Mar 17, 2017 11:06 pm

Just in case anyone else is interested I have modified the code to check the revision and exit if it does not have the capability to detect voltage, based on revision must be more than hex 000f

Code: Select all

#!/usr/bin/python

#based on code from https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=82373&hilit=under+voltage+via+terminal+terminal&start=75

import RPi.GPIO as GPIO , time
from subprocess import call
import shlex
import sys

import signal

# Voltage detection only available after revision code 000f
rev = ''
searchfile = open('/proc/cpuinfo', "r")
for line in searchfile:
    if "Revision" in line: 
        rev = line.split(':')[1]
searchfile.close()
if int(rev,  base = 16) < 16:
    print 'Voltage detection not available on this model'
    exit()


def handler(signum, frame):
#   call(shlex.split("echo -ne '\e[u''\e[0m'"))
   sys.exit()

signal.signal(signal.SIGINT, handler)

redLED=35
GPIO.setmode(GPIO.BCM)
GPIO.setup(redLED, GPIO.IN)

powerlow=0
#call(shlex.split("echo -ne '\e[s'"))
while True:
   if(GPIO.input(redLED)==0):
      call(shlex.split("echo -ne '\e[s''\e[1;56H''\e[1;31m'POWER dipped below 4.63v'\e[u''\e[0m'"))
      powerlow += 1
   else:
      powerlow = 0
      call(shlex.split("echo -ne '\e[s''\e[1;78H''\e[1;31m'ON'\e[u''\e[0m'"))

   if (powerlow  > 3):
      break
   
   time.sleep(1)

#call(shlex.split("echo -ne '\e[u''\e[0m'"))
print "Low power for " + str(powerlow) + " seconds"

Thanks for your help
Mick

Return to “Troubleshooting”