Commit 87cc0607 authored by James Pallister's avatar James Pallister

Added extra python scripts

parent 0bec2560
#!/usr/bin/python
# Output continuous data in CSV format
import pyenergy
from time import sleep
em = pyenergy.EnergyMonitor("EE00")
em.connect()
em.enableMeasurementPoint(1)
em.start()
print "energy, time, power, peak_power, peak_current, peak_voltage"
while True:
m = em.getMeasurement()
print "{}, {}, {}, {}, {}, {}".format(m.energy, m.time, m.energy/m.time, m.peak_power, m.avg_current, m.avg_voltage)
sleep(0.1)
......@@ -167,13 +167,14 @@ if __name__ == "__main__":
em.toggleLEDs()
em.enableMeasurementPoint(1)
# em.enableMeasurementPoint(3)
em.setTrigger("PA0")
em.enableMeasurementPoint(2)
em.setTrigger("PA0", 1)
em.setTrigger("PA0", 2)
print "*** Press the blue button to make a measurement"
em.start(1)
while True:
m = em.getMeasurement()
print m.energy, m.time
sleep(0.05)
while not em.measurementCompleted(): sleep(0.1)
print em.getMeasurement(1)
print em.getMeasurement(2)
#!/usr/bin/python
# Display each measurement, when triggered on PA0 (blue button)
import pyenergy
from time import sleep
# Display units nicer
def prettyPrint(v):
units = ['', 'm', 'u', 'n', 'p']
for unit in units:
if v > 1.0:
return "{:3.3f} {}".format(v, unit)
v *= 1000.
return "{}".format(v)
# Find and connect to the board
em = pyenergy.EnergyMonitor("EE00")
em.connect()
# Enable measurement point 1 and set PA0 as the trigger (blue button)
em.enableMeasurementPoint(1)
em.setTrigger("PA0")
while True:
# Wait for a measurement to complete
while not em.measurementCompleted():
sleep(0.1) # Need a delay, or we'll flood the board with USB requests
m = em.getMeasurement()
print "\nReceived measurement"
if m.time == 0:
print "\tError: zero time"
continue
print "\tEnergy: {}J".format(prettyPrint(m.energy))
print "\tTime: {:3.3f} s".format(m.time)
print "\tPower: {}W Peak power: {}W".format(prettyPrint(m.energy/m.time), prettyPrint(m.peak_power))
print "\tAvg current: {}A Avg voltage: {}V".format(prettyPrint(m.avg_current), prettyPrint(m.avg_voltage))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment