Skip to content

Instantly share code, notes, and snippets.

@xiongyihui
Created March 31, 2015 06:53
Show Gist options
  • Save xiongyihui/9a9bb58a6e37ab6127fc to your computer and use it in GitHub Desktop.
Save xiongyihui/9a9bb58a6e37ab6127fc to your computer and use it in GitHub Desktop.
To test BeagleBone Green
'''
BeagleBone Green Test
apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
pip install Adafruit_BBIO
'''
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.ADC as ADC
from Adafruit_I2C import Adafruit_I2C as I2C
import subprocess
def check_voltage():
VOLTAGES = [['AIN0', 0.57, 0.63],
['AIN2', 0.85, 0.95],
['AIN4', 1.14, 1.26],
['AIN6', 1.42, 1.58],
['AIN1', 1.04, 1.16], # VDD_3V3B / 3
['AIN3', 1.58, 1.75], # VDD_5V / 3
['AIN5', 1.65, 1.69]] # SYS_5V / 3
ADC.setup()
for v in VOLTAGES:
ain = ADC.read(v[0])
if ain < v[1] or ain > v[2]:
print('%f (%s) is out of range: %f ~ %f.' % (ain, v[0], v[1], v[2]))
def check_io():
IO_GROUP1 = ['P8_3', 'P8_6', 'P8_7', 'P8_9', 'P8_12', 'P8_13', 'P8_15', 'P8_18',
'P8_21', 'P8_22', 'P8_25', 'P8_26', 'P8_27', 'P8_29', 'P8_31',
'P8_35', 'P8_36', 'P8_37', 'P8_40', 'P8_42', 'P8_43', 'P8_45',
'P9_13', 'P9_16', 'P9_23', 'P9_26', 'P9_27', 'P9_30', 'P9_31']
IO_GROUP2 = ['P8_4', 'P8_5', 'P8_8', 'P8_10', 'P8_11', 'P8_14', 'P8_16', 'P8_17',
'P8_19', 'P8_20', 'P8_23', 'P8_24', 'P8_28', 'P8_30', 'P8_32',
'P8_33', 'P8_34', 'P8_38', 'P8_39', 'P8_41', 'P8_44', 'P8_46',
'P9_11', 'P9_12', 'P9_14', 'P9_15', 'P9_24', 'P9_25', 'P9_28',
'P9_29', 'P9_41', 'P9_42']
IO_GROUP3 = ['P9_18', 'P9_22']
IO_GROUP4 = ['P9_17', 'P9_21']
EMMC_RESET = 'GPIO1_20'
# put eMMC in reset
GPIO.setup(EMMC_RESET, GPIO.OUT)
GPIO.output(EMMC_RESET, GPIO.LOW)
GPIO.setup(IO_GROUP1[0], GPIO.OUT)
for pin in IO_GROUP1[1:]:
GPIO.setup(pin, GPIO.IN)
GPIO.output(IO_GROUP1[0], GPIO.HIGH)
for pin in IO_GROUP1[1:]:
if not GPIO.input(pin):
# print('%s is not connected' % pin)
pass
def check_power_ex():
import powerstatus
powerstatus.show_reg(powerstatus.PGOOD, "PGOOD", powerstatus.PGOOD_LABELS)
status = powerstatus.query(powerstatus.PGOOD)
# display value of each bit in the register, along with its label
def describe_bits(val,labels):
for x in range(0,len(labels)):
if(not labels[x]): # skip None labels
continue
msk = 1<<x
print "%s = %d"%(labels[x],(val&msk)!=0)
def check_power():
STATUS_LABELS = ["Push Button", None, "USB Power", "AC Power"] # skip the rest
PGOOD_LABELS = ["LDO2 power-good","LDO1 power-good","DCDC3 power-good","DCDC2 power-good","DCDC1 power-good", "LDO4 power-good","LDO3 power-good"]
pgood = int(subprocess.check_output(['i2cget', '-y' ,'-f', '0', '0x24', '0xC']).strip(), 16)
status = int(subprocess.check_output(['i2cget', '-y' ,'-f', '0', '0x24', '0xA']).strip(), 16)
describe_bits(pgood, PGOOD_LABELS)
describe_bits(status, STATUS_LABELS)
if pgood != 0x7F:
return False
return True
if __name__ == '__main__':
check_power()
check_voltage()
check_io()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment