AdafruitIna219

javadoc

This service to support the Adafruit INA219 board. It can be used to measure Voltage, Current and Power. 

Adafruit INA219 product page

Steps to use the INA219

1. Connect the GND, VCC, SCL and SDA pins to the corresponding i2c pins on the Arduino or Raspberry PI. 

2. Connect the GND to GND on the source that you want to measure.

3. Connctect V- and V+ in the circuit that you want to measure. For example you can connect V+ to the battery + and V- to the cable that you normally would have connected to the battery.

4. Start MyrobotLab and test the AdafruitIna219 service using the example script.


#file : /service/AdafruitIna219.py edit raw
#########################################
# AdafruitIna219.py
# description: Adafruit INA219 Voltage and Current sensor Service
# categories: [sensor]
#########################################
# This script shows how to use the AdafruitIna219 service
#
# config
port = "COM3"
# Code to be able to use this script with virtalArduino
if ('virtual' in globals() and virtual):
    virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)
# 
ina219 = Runtime.start("AdafruitIna219","AdafruitIna219")
#
# This section shows is if you use the Arduino i2c pins
# Comment three lines if you don't use the Arduino
arduino = Runtime.start("Arduino","Arduino")
arduino.connect(port)
ina219.attach(arduino,"1","0x40")
# 
# This section shows is if you use the GPIO i2c pins on the RaspBerry Pi directly
# Uncomment two lines if you use the RasPi
# raspi = Runtime.start("RasPi","RasPi")
# ina219.attach(raspi,"1","0x40")
#
# This sections shows how to get the values from the service
ina219.refresh()
print ina219.busVoltage," mV bus voltage"
print ina219.shuntResistance, "Ohms shunt resistance"
print ina219.shuntVoltage ," mV accross the shunt resistor"
print ina219.current, " mA current"
print ina219.power, " mW power"

 

 

 

Examples:


#file : service/AdafruitIna219.py edit raw
#########################################
# AdafruitIna219.py
# description: Adafruit INA219 Voltage and Current sensor Service
# categories: [sensor]
#########################################
# This script shows how to use the AdafruitIna219 service
#
# config
port = "COM3"
# Code to be able to use this script with virtalArduino
if ('virtual' in globals() and virtual):
    virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)
# 
ina219 = Runtime.start("AdafruitIna219","AdafruitIna219")
#
# This section shows is if you use the Arduino i2c pins
# Comment three lines if you don't use the Arduino
arduino = Runtime.start("Arduino","Arduino")
arduino.connect(port)
ina219.attach(arduino,"1","0x40")
# 
# This section shows is if you use the GPIO i2c pins on the RaspBerry Pi directly
# Uncomment two lines if you use the RasPi
# raspi = Runtime.start("RasPi","RasPi")
# ina219.attach(raspi,"1","0x40")
#
# This sections shows how to get the values from the service
ina219.refresh()
print ina219.busVoltage," mV bus voltage"
print ina219.shuntResistance, "Ohms shunt resistance"
print ina219.shuntVoltage ," mV accross the shunt resistor"
print ina219.current, " mA current"
print ina219.power, " mW power"