学物联网,来万物简单IoT物联网!!
INA219电压电流计可用于测量负载的电压、电流、功率等参数,可以用于服务器、电脑笔记本、电源、电池管理等电子电路设备提供电流电压值监测提供解决方案。
引脚定义
ina219Obj = INA219(i2cObj)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
i2cObj | I2C | 是 | 传入I2C对象 |
from machine import I2C,PIn # 驱动库
import ina219
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
ina219Dev = ina219.INA219(i2cObj)
print("ina219 inited!")
ina219 inited!
INA219.getVoltage()
from machine import I2C,PIn # 驱动库
import ina219
import utime
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
ina219Dev = ina219.INA219(i2cObj)
print("ina219 inited!")
while True:
print("Bus Voltage: %.3f V" % ina219Dev.getVoltage())
utime.sleep(1)
ina219 inited!
Bus Voltage: 4.872 V
Bus Voltage: 4.868 V
Bus Voltage: 4.868 V
Bus Voltage: 4.868 V
INA219.getCurrent()
from machine import I2C,PIn # 驱动库
import ina219
import utime
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
ina219Dev = ina219.INA219(i2cObj)
print("ina219 inited!")
while True:
print("Current: %.3f mA" % ina219Dev.getCurrent())
utime.sleep(1)
No OTA upgrade.
mount fs
==== python execute bootpy ====
==== python file check /data/pyamp/main.py ====
==== python execute from /data/pyamp/main.py ====
ina219 inited!
Current: 3.305 mA
Current: 3.402 mA
Current: 3.305 mA
Current: 3.195 mA
INA219.getPower()
from machine import I2C,PIn # 驱动库
import ina219
import utime
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
ina219Dev = ina219.INA219(i2cObj)
print("ina219 inited!")
while True:
print("Power: %.3f mW" % ina219Dev.getPower())
utime.sleep(1)
No OTA upgrade.
mount fs
==== python execute bootpy ====
==== python file check /data/pyamp/main.py ====
==== python execute from /data/pyamp/main.py ====
ina219 inited!
Power: 15.610 mW
Power: 16.098 mW
Power: 16.098 mW
Power: 15.610 mW
# Python代码
from machine import I2C,PIn # 驱动库
import ina219
import utime
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
ina219Dev = ina219.INA219(i2cObj)
print("ina219 inited!")
while True:
print("Bus Voltage: %.3f V" % ina219Dev.getVoltage())
print("Current: %.3f mA" % ina219Dev.getCurrent())
print("Power: %.3f mW" % ina219Dev.getPower())
utime.sleep(1)
No OTA upgrade.
mount fs
==== python execute bootpy ====
==== python file check /data/pyamp/main.py ====
==== python execute from /data/pyamp/main.py ====
ina219 inited!
Bus Voltage: 4.872 V
Current: 3.305 mA
Power: 15.610 mW
Bus Voltage: 4.868 V
Current: 3.402 mA
Power: 16.098 mW
Bus Voltage: 4.868 V
Current: 3.305 mA
Power: 16.098 mW
Bus Voltage: 4.868 V
Current: 3.195 mA
Power: 15.610 mW
Bus Voltage: 4.864 V
Current: 3.195 mA
Power: 16.098 mW
INA219传感器寄存器描述如下表所示:
序号 | 寄存器地址 | 功能说明 | 默认值 |
---|---|---|---|
1 | 0x00 | 配置寄存器 | 0x399F |
2 | 0x01 | 分流电压寄存器 | – |
3 | 0x02 | 总线电压寄存器 | – |
4 | 0x03 | 功率寄存器 | 0x00 |
5 | 0x04 | 当前寄存器 | 0x00 |
6 | 0x05 | 校准寄存器 | 0x00 |
从下图可以看到INA219内置I2C通信单元,与MCU进行数据交互。通过ADC采样输入到数据处理和线性化单元,同时带有校正储存器,处理环境对器件测量的影响。带警报引脚,可通过修改寄存器的值设定阈值,当测量的温湿度超过阈值时它会被置位。
引脚分布如下:
序号 | 引脚名 | 功能说明 |
---|---|---|
1 | Data | I2C数据线 |
2 | CLK | I2C时钟线 |
3 | GND | 地线引脚 |
4 | VCC | 电源输入引脚 |
5 | Vin- | 接负载低电压端引线 |
6 | Vin+ | 接负载高电压端引线 |
7 | A0 | 可编程地址线 |
8 | A1 | 可编程地址线 |
[1] INA219电压电流计传感器介绍
[2] INA219电压电流计购买链接