コード例 #1
0
ファイル: testrig.py プロジェクト: scottyallen/EightByEight
	def __init__(self):
		GPIO.setmode(GPIO.BCM)
		GPIO.setwarnings(False)

		for pin in self.leds.itervalues():
			GPIO.setup(pin, GPIO.OUT)
			GPIO.output(pin, GPIO.LOW)

		for pin in self.powerModes.itervalues():
			GPIO.setup(pin, GPIO.OUT)
			GPIO.output(pin, GPIO.LOW)

		for pin in self.digitalPins.itervalues():
			GPIO.setup(pin, GPIO.IN)

		self.dutCurrent = ina219.INA219()

		#self.adc0 = Adafruit_ADS1x15.ADS1015(address=0x48)
		#self.adc0 = Adafruit_ADS1x15.ADS1015(address=0x48)
		#self.adc0 = ads1015.ADS1015(address=0x48)
		#self.adc1 = ads1015.ADS1015(address=0x49)

		GPIO.setup(self.usbPin, GPIO.OUT)
		GPIO.output(self.usbPin, GPIO.LOW)

		GPIO.setup(self.startButtonPin, GPIO.IN)
コード例 #2
0
ファイル: ina219_sensor.py プロジェクト: fpvMarkS/RotorHazard
 def __init__(self, name, addr, i2c_helper, config={}):
     I2CSensor.__init__(self, name, i2c_helper)
     max_current = float(config['max_current']) if 'max_current' in config else None
     self.device = ina219.INA219(0.1, address=addr, max_expected_amps=max_current)
     self.device.configure()
     self.device.sleep()
     self.readData()
コード例 #3
0
 def __init__(self, name, addr, i2c_helper, config={}):  #pylint: disable=dangerous-default-value
     I2CSensor.__init__(self, name, i2c_helper)
     max_current = float(config['max_current']) if 'max_current' in config else None
     self.device = ina219.INA219(0.1, address=addr, max_expected_amps=max_current,
                                 busnum=i2c_helper.get_i2c_busnum())
     self.device.configure()
     self.device.sleep()
     self.readData()
コード例 #4
0
 def __init__(self, _location, _w1_device_id_list):
     self.location = _location
     self.id = f'urn:dev:ops:{self.location}-vorraum-node'
     self.name = f'{self.location}-node_functions'
     self.w1_device_id_list = _w1_device_id_list
     Thing.__init__(self, self.id, self.name, ['EnergyMonitor'],
                    'A web connected node')
     self.ina219 = ina219.INA219(busnum=0, address=0x40)
     self.power = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-power',
                  self.power,
                  metadata={
                      '@type': 'InstantaneousPowerProperty',
                      'title': f'{self.name}-Power',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the power used by this node',
                  }))
     self.volt = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-voltage',
                  self.volt,
                  metadata={
                      '@type': 'VoltageProperty',
                      'title': f'{self.name}-Voltage',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the voltage used by this node',
                  }))
     self.current = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-current',
                  self.current,
                  metadata={
                      '@type': 'CurrentProperty',
                      'title': f'{self.name}-Current',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the current used by this node',
                  }))
     self.temperature = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-Temperature',
                  self.temperature,
                  metadata={
                      '@type': 'TemperatureProperty',
                      'title': f'{self.name}-Temperature',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the temperature in the case',
                  }))
     self.timer = tornado.ioloop.PeriodicCallback(self.get_sensors, 300000)
     self.timer.start()
コード例 #5
0
def main():
    ina = ina219.INA219(shunt_ohms=0.1, max_expected_amps=3, address=0x40)

    ina.configure(voltage_range=ina.RANGE_16V,
                  gain=ina.GAIN_AUTO,
                  bus_adc=ina.ADC_128SAMP,
                  shunt_adc=ina.ADC_128SAMP)

    return ina.current()
コード例 #6
0
def main():
    ina = ina219.INA219(SHUNT_RESISTANCE_OHMS, MAX_EXPECTED_CURRENT_AMPS)
    ina.configure(
            voltage_range = ina219.INA219.RANGE_32V,
            bus_adc = ina219.INA219.ADC_16SAMP,
            shunt_adc = ina219.INA219.ADC_16SAMP)

    while True:
        voltage, current, power, shuntVoltage = read(ina)
        print("Voltage: %f V, Current: %f A, Power: %f W" % (voltage, current, power))
        time.sleep(SLEEP_TIME_SEC)
コード例 #7
0
 def __init__(self, name, addr, i2c_bus, config={}):
     super().__init__(name=name, i2c_addr=addr, i2c_bus=i2c_bus)
     self.description = 'INA219'
     max_current = float(
         config['max_current']) if 'max_current' in config else None
     self.device = ina219.INA219(0.1,
                                 busnum=i2c_bus.id,
                                 address=addr,
                                 max_expected_amps=max_current)
     self.device.configure()
     self.device.sleep()
     self._readData()
コード例 #8
0
 def __init__(self,
              interval,
              addr,
              i2c_device_num,
              calibrator=ina219.INA219_CALIB_32V_2A,
              sample=1):
     """
     Runs as a concurrent thread to read from an ina219 device attached to local i2c (SMBus).
     :param interval: float in seconds. Read interval for ina219
     :param addr: int - i2c bus address of ina219 device
     :param i2c_device_num: int - bus number of i2c device ina219 is attached (e.g /dev/i2c-n where n
                                  is i2c_device_num
     :param number of samples to use for current measurement. See ina219.INA219 for details
     """
     PowerMonitor.__init__(self)
     self._meter = ina219.INA219(addr, i2c_device_num)
     self._meter.setCalibration(calibrator, sample)
     self._monitor = False
     self._interval = interval
     self._last_timestamp = None
コード例 #9
0
import subprocess

results = {}
results['pass'] = 0
results['fail'] = 0

SHUNT_OHMS = 0.1

def read_power():
    results = {}
    results['voltage'] = ina.voltage()
    results['current'] = ina.current()
    return results

# Current sensor
ina = ina219.INA219(SHUNT_OHMS)
ina.configure()

# VTarget enable
vtarget_en = gpiozero.LED(13)
vtarget_en.off()
time.sleep(1)

# buffered UART
uart = serial.Serial("/dev/serial0", 115200, timeout=.2)


# Test that no voltage is present while off
val = read_power()
print(val)
if (val['voltage'] > .05):
コード例 #10
0
# Micropython ID Matrix
# ======================
# I2C IDS:   0  1
# ---------------
# SCL GPIO: 18 25
# SDA GPIO: 19 26
# ---------------

NAME = "blueshunt"
I2C_ID = 1  # SCL: GPIO25, SDA: GPIO26
LED_GPIO = 2  # GPIO2 is wired to LED1 (blue)
RSHUNT = .1  # shunt resistor value
MAXVOLTS = 16
MAXAMPS = .1

pin = machine.Pin(LED_GPIO, machine.Pin.OUT)  # initially zero (led off)
i2c = machine.I2C(I2C_ID)
ina = ina219.INA219(i2c, rshunt=RSHUNT, maxvolts=MAXVOLTS, maxamps=MAXAMPS)
ble = bluetooth.BLE()
blue = BLEUART(ble, NAME)

print("V,mA,mW")
while True:
    pin.value(not pin.value())
    buf = "{:.2f},{:.1f},{:.1f}".format(ina.bus_voltage(),
                                        ina.current() * 1000,
                                        ina.power() * 1000)
    print(buf)
    blue.write(buf)
    time.sleep_ms(1000)
コード例 #11
0
ファイル: main.py プロジェクト: MNahad/manc-iot-nodes
import ina219 # Modified ina219 driver
import usocket as socket
import ujson as json
import utime as time

start = time.ticks_ms() # Start measuring time delta
sensor = ina219.INA219(scl_pin=26, sda_pin=27) # Create sensor obj
energy = 0 # Initialise energy counter


def res():
""" Function to return REST API response """
    data = {
        "current(A)": current,
        "voltage(V)": voltage,
        "power(W)": power,
        "totalEnergy(J)": energy,
    }
    return json.dumps(data)


# Store server address data
addr = socket.getaddrinfo('192.168.4.1', 80)[0][-1]
# Create websocket obj
sock = socket.socket()
# Set socket timeout
sock.settimeout(0.01)
# Bind to server
sock.bind(addr)
# Start listening
sock.listen(1)