淮南网站建设价格,富阳市建设局网站,短视频创作平台,网站层次之前的文章简要介绍了开源INA226电流计模块的功能特点#xff0c;本文将详细介绍INA226电流计模块的使用方法。
特性
感测总线电压范围#xff1a;0V - 36V高侧/低侧电流感测电压、电流、功率测量0.1% 增益误差10uV 偏移可配置测量平均值16个可配置I2C地址2.7V - 5.5V 电源…之前的文章简要介绍了开源INA226电流计模块的功能特点本文将详细介绍INA226电流计模块的使用方法。
特性
感测总线电压范围0V - 36V高侧/低侧电流感测电压、电流、功率测量0.1% 增益误差10uV 偏移可配置测量平均值16个可配置I2C地址2.7V - 5.5V 电源供电2路电源轨可选为负载电源作为 CH347高速USB桥接模块 扩展时为 3.3V 和 5VAlert指示灯非共地连接时可选远端电压感测引脚兼容CH347模块即插即用
硬件连接 P4为10*2 2.54mm插针是模块的电源和I2C接口兼容CH347模块接口可以直接插到CH347模块上使用。P4实际使用了加长排座这样INA226模块插到CH347模块上时不会影响CH347模块连接其他设备尤其是可以多个INA226模块同时插到CH347模块上使用测量多路电流。
INA226模块上实际连接的插针只有8个引脚1个5V电源1个3.3V电源1个SCL1个SDA4个GND。
INA226芯片实际使用3.3V电源CH347模块上有5V和3.3V两路电源所以在接口设计上这两路电源都接入INA226模块了其中5V电源连接到J13.3V电源除了给INA226芯片供电还连接到J2。J1和J2可以通过跳线帽选通为待测设备供电也就是P1端口。 注意 如果使用外部电源为待测设备供电一定要将J1和J2上的短路帽拔下来否则会损坏模块 J1和J2不能同时连接短路帽 当仅测量电流时可以像使用电流表一样将待测点断开然后将P1的1引脚和P2的2引脚也就是电路板上标注的的两个脚串入这样就可以测量电流了。当电流流向与板子上箭头相同时为正反向则为负。
当需要测量电压和功率时接线就稍微复杂一些既要测量电流又要测量电压此时需要将待测设备的电源接入P1待测设备接入P2注意极性“接电源正极”-接电源负极。如果待测设备为5V或3.3V电源供电电流小于500mA则可以通过短路帽选通J1或J2来为待测设备供电省去连接外部电源。如果待测设备电流较大为了精确测量功率则需要考虑远端测量电压此时要将J3、J4上的短路帽拔下来而使用杜邦线或其他导线将V和V-连接到设备端的电源引脚要注意极性不要接反这样可以测量远端电压从而排除电源线损耗对功率测量的影响。
J5 J6 J7 J8为电流计模块I2C地址设置单个模块使用时保持短路帽默认位置即可此时对应7位地址为0b1000000。多个模块同时使用时可以设置不同地址来区分各个模块。
LED为INA226芯片的Alert指示灯可以通过软件设置报警逻辑和阈值来触发报警。
INA226模块目前发货默认感测电阻为20mΩ对应电流测量范围为0 - 4A分辨率为125uA电压分辨率为1.25mV非常给力应对常规测量绰绰有余。并且可以编程自动化测量连续监测记录数据。
示例程序
之前示例测试ESP32模块的电压、电流、功率 代码如下
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from time import sleep
from i2c_devices.ina226 import INA226# Initialize the INA226 sensor
sensor INA226()def read_sensor_data():return [sensor.get_bus_voltage(), sensor.get_current(), sensor.get_power()]# Generator function to produce data from the sensor sensor
def generate_sensor_data():data_buffer []while True:data read_sensor_data()data_buffer.append(data)yield data_buffersleep(0.1)# Create a figure with 6 subplots for accelerometer and gyroscope data
fig, axs plt.subplots(3, 1, figsize(8, 12))# Initialize empty lines for the accelerometer and gyroscope data plots
lines [axs[i].plot([], [], lw2)[0] for i in range(3)]# Set the number of data points to be displayed on the plot
num_display_points 50def init():for line in lines:line.set_data([], [])return linesdef update(frame):data_buffer next(data_generator)# Generate the x-axis values (time steps) based on the number of data pointstime_steps np.arange(len(data_buffer))# Get the starting index to display a specific number of data pointsstart_index max(0, len(data_buffer) - num_display_points)# Update the plot data for accelerometer and gyroscopefor i in range(3):lines[i].set_data(time_steps[start_index:], [data[i] for data in data_buffer[start_index:]])axs[i].set_xlim(start_index, start_index num_display_points - 1)# Update the x-axis limits for scrolling effectaxs[0].set_ylim(0, 10000)axs[1].set_ylim(0, 100000)axs[2].set_ylim(0, 200)return lines# Create the generator for sensor sensor data
data_generator generate_sensor_data()# Create an animation for real-time plotting, update every 100 milliseconds (0.1 seconds)
ani animation.FuncAnimation(fig, update, framesrange(100), init_funcinit, blitTrue, interval100)# Add labels and title to each subplot
axis_labels [Voltage in mV, Current in uA, Power in mW]
for i in range(3):axs[i].set_title(f{axis_labels[i]})axs[i].set_xlabel(Time Steps)axs[i].set_ylabel(INA226 Data Value)plt.tight_layout()
plt.show()
sensor.close()公众号 | FunIO 微信搜一搜 “funio”发现更多精彩内容。 个人博客 | blog.boringhex.top