当前位置: 首页 > article >正文

INA3221和 ESP8266 6通道电流表

文章目录

    • 1.实际效果
      • 1.所用材料:
      • 2.原理图
        • 1. ina3221接线
        • 2.屏幕接线
    • 2.程序
      • 1下载链接
    • 3.注意事项
      • 1.电流精度0.4mA
      • 2.通过设定电阻值来调整准确度
      • 3.通过IIC的地址进行多个挂载ina3221
      • 4.ina3221 SPEC
      • 5.保留显示的小数位数

1.实际效果

ina3221只能达到0.4mA 的精度

在这里插入图片描述

1.所用材料:

(1).128x160 的st7735S 驱动芯片的屏幕
(2).nodeMCU
(3).2个ina3221

2.原理图

1. ina3221接线

例子中的地址是0x40 和0x41
在这里插入图片描述
spec中的地址配置在这里插入图片描述 在这里插入图片描述

2.屏幕接线

别忘了在user_setup.h中修改引脚以及其他选项
在这里插入图片描述

2.程序

程序有点乱

//电流传感器头文件
#include <Wire.h>
#include "SDL_Arduino_INA3221.h"//显示相关头文件
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h
//显示字体和坐标调整
int textsize =2;
int textsize1 =2;
int x =0;
int y =20;
int xx =30;
int xx1 =110;
int yy =24;// the three channels of the INA3221 named for SunAirPlus Solar Power Controller channels (www.switchdoc.com)
#define LIPO_BATTERY_CHANNEL 1
#define SOLAR_CELL_CHANNEL 2
#define OUTPUT_CHANNEL 3//两个电流传感器,地址分别是40和41,电阻是R100,即0.1ohm;SDL_Arduino_INA3221 ina3221=SDL_Arduino_INA3221(0x41, 0.1);SDL_Arduino_INA3221 ina32211=SDL_Arduino_INA3221(0x40, 0.1);void setup(void) 
{//-----------------电流监测初始化----------------Serial.begin(115200);Serial.println("SDA_Arduino_INA3221_Test");Serial.println("Measuring voltage and current with ina3221 ...");ina3221.begin();ina32211.begin();Serial.print("Manufactures ID=0x");int MID;MID = ina3221.getManufID();Serial.println(MID,HEX);//-----------------显示屏初始化----------------tft.init();tft.setRotation(2);tft.fillScreen(TFT_BLACK);tft.setTextSize(1);tft.setTextColor(TFT_RED, TFT_BLACK);tft.drawString(" CH", 0, 0, textsize); tft.drawString(" I(mA)", 30, 0, textsize);tft.drawString(" V(mV)", 80, 0, textsize);tft.setTextColor(TFT_GREEN, TFT_BLACK);}void loop(void) 
{//Serial.println("------------------------------");float shuntvoltage1 = 0;float busvoltage1 = 0;float current_mA1 = 0;float loadvoltage1 = 0;busvoltage1 = ina3221.getBusVoltage_V(LIPO_BATTERY_CHANNEL);shuntvoltage1 = ina3221.getShuntVoltage_mV(LIPO_BATTERY_CHANNEL);current_mA1 = -ina3221.getCurrent_mA(LIPO_BATTERY_CHANNEL);  // minus is to get the "sense" right.   - means the battery is charging, + that it is dischargingloadvoltage1 = busvoltage1 + (shuntvoltage1 / 1000);/*Serial.print("LIPO_Battery Bus Voltage:   "); Serial.print(busvoltage1); Serial.println(" V");Serial.print("LIPO_Battery Shunt Voltage: "); Serial.print(shuntvoltage1); Serial.println(" mV");Serial.print("LIPO_Battery Load Voltage:  "); Serial.print(loadvoltage1); Serial.println(" V");Serial.print("LIPO_Battery Current 1:       "); Serial.print(current_mA1); Serial.println(" mA");Serial.println("");*/float shuntvoltage2 = 0;float busvoltage2 = 0;float current_mA2 = 0;float loadvoltage2 = 0;busvoltage2 = ina3221.getBusVoltage_V(SOLAR_CELL_CHANNEL);shuntvoltage2 = ina3221.getShuntVoltage_mV(SOLAR_CELL_CHANNEL);current_mA2 = -ina3221.getCurrent_mA(SOLAR_CELL_CHANNEL);loadvoltage2 = busvoltage2 + (shuntvoltage2 / 1000);/*Serial.print("Solar Cell Bus Voltage 2:   "); Serial.print(busvoltage2); Serial.println(" V");Serial.print("Solar Cell Shunt Voltage 2: "); Serial.print(shuntvoltage2); Serial.println(" mV");Serial.print("Solar Cell Load Voltage 2:  "); Serial.print(loadvoltage2); Serial.println(" V");Serial.print("Solar Cell Current 2:       "); Serial.print(current_mA2); Serial.println(" mA");Serial.println("");
*/float shuntvoltage3 = 0;float busvoltage3 = 0;float current_mA3 = 0;float loadvoltage3 = 0;busvoltage3 = ina3221.getBusVoltage_V(OUTPUT_CHANNEL);shuntvoltage3 = ina3221.getShuntVoltage_mV(OUTPUT_CHANNEL);current_mA3 = ina3221.getCurrent_mA(OUTPUT_CHANNEL);loadvoltage3 = busvoltage3 + (shuntvoltage3 / 1000);/*Serial.print("Output Bus Voltage 3:   "); Serial.print(busvoltage3); Serial.println(" V");Serial.print("Output Shunt Voltage 3: "); Serial.print(shuntvoltage3); Serial.println(" mV");Serial.print("Output Load Voltage 3:  "); Serial.print(loadvoltage3); Serial.println(" V");Serial.print("Output Current 3:       "); Serial.print(current_mA3); Serial.println(" mA");Serial.println("");Serial.println("------------------------------33333333333333333------------------------------------------------");
*/ //-----------------------------------------------------------------------------------------------------------float shuntvoltage4 = 0;float busvoltage4 = 0;float current_mA4 = 0;float loadvoltage4 = 0;busvoltage4 = ina32211.getBusVoltage_V(LIPO_BATTERY_CHANNEL);shuntvoltage4 = ina32211.getShuntVoltage_mV(LIPO_BATTERY_CHANNEL);current_mA4 = ina32211.getCurrent_mA(LIPO_BATTERY_CHANNEL);loadvoltage4 = busvoltage4 + (shuntvoltage4 / 1000);float shuntvoltage5 = 0;float busvoltage5 = 0;float current_mA5 = 0;float loadvoltage5 = 0;busvoltage5 = ina32211.getBusVoltage_V(SOLAR_CELL_CHANNEL);shuntvoltage5 = ina32211.getShuntVoltage_mV(SOLAR_CELL_CHANNEL);current_mA5 = ina32211.getCurrent_mA(SOLAR_CELL_CHANNEL);loadvoltage5 = busvoltage5 + (shuntvoltage5 / 1000);float shuntvoltage6 = 00.00;float busvoltage6 = 0;float current_mA6 = 0;float loadvoltage6 = 0;busvoltage6 = ina32211.getBusVoltage_V(OUTPUT_CHANNEL);shuntvoltage6 = ina32211.getShuntVoltage_mV(OUTPUT_CHANNEL);current_mA6 = ina32211.getCurrent_mA(OUTPUT_CHANNEL);loadvoltage6 = busvoltage6 + (shuntvoltage6 / 1000);//--------------------------------负变正---------------------------------------------------------------------------if (current_mA1 < 0) current_mA1=-current_mA1;
if (current_mA2 < 0) current_mA2=-current_mA2;
if (current_mA3 < 0) current_mA3=-current_mA3;
if (current_mA4 < 0) current_mA4=-current_mA4;
if (current_mA5 < 0) current_mA5=-current_mA5;
if (current_mA6 < 0) current_mA6=-current_mA6;//--------------------------------串口输出---------------------------------------------------------------------------Serial.print(current_mA1); Serial.print("    ");Serial.print(current_mA2); Serial.print("    ");Serial.print(current_mA3); Serial.print("    ");Serial.print(current_mA4); Serial.print("    ");Serial.print(current_mA5); Serial.print("    ");Serial.print(current_mA6); Serial.print("    ");Serial.println("    ");//----------------------------------显示屏输出------------------------------------------------------------------tft.drawString("CH1", x, y, textsize1);  tft.drawFloat(current_mA1, 2,x+xx, y, textsize1);  tft.drawFloat(shuntvoltage1,2, x+xx1, y, textsize1);tft.drawString("CH2", x, y+yy, textsize1);  tft.drawFloat(current_mA2, 2,x+xx, y+yy, textsize1);  tft.drawFloat(shuntvoltage2,2, x+xx1,y+yy, textsize1);tft.drawString("CH3", x, y+2*yy, textsize1);  tft.drawFloat(current_mA3,2, x+xx, y+2*yy, textsize1);  tft.drawFloat(shuntvoltage3, 2,x+xx1, y+2*yy, textsize1);tft.drawString("CH4", x, y+3*yy, textsize1);  tft.drawFloat(current_mA4, 2,x+xx, y+3*yy, textsize1);  tft.drawFloat(shuntvoltage4,2, x+xx1, y+3*yy, textsize1);tft.drawString("CH5", x, y+4*yy, textsize1);  tft.drawFloat(current_mA5, 2,x+xx, y+4*yy, textsize1);  tft.drawFloat(shuntvoltage5, 2,x+xx1, y+4*yy, textsize1);tft.drawString("CH6", x, y+5*yy, textsize1);  tft.drawFloat(current_mA6, 2,x+xx, y+5*yy, textsize1);  tft.drawFloat(shuntvoltage6, 2,x+xx1, y+5*yy, textsize1);delay(500);//tft.fillScreen(TFT_BLACK);
}

1下载链接

百度云链接
提取码:8mer

3.注意事项

1.电流精度0.4mA

2.通过设定电阻值来调整准确度

//两个电流传感器,地址分别是40和41,电阻是R100,即0.1ohm;
SDL_Arduino_INA3221 ina3221=SDL_Arduino_INA3221(0x41, 0.1);
SDL_Arduino_INA3221 ina32211=SDL_Arduino_INA3221(0x40, 0.1);

3.通过IIC的地址进行多个挂载ina3221

在这里插入图片描述

4.ina3221 SPEC

链接

5.保留显示的小数位数

有时候我们需要显示2个精度的小数,但是当从显示19.88到9.88时候,因为刷新的问题会导致字符叠加,
解决方法:
1.可以设置在loop函数中增加tft.fillscreen(BLACK)
但是这样会使屏幕闪烁

2.可以通过控制整个显示的位数,比如
8.8000 18.800 188.00
这都是5个位的,因此不会存在字符叠加的问题
程序设计:
在上述程序中的drawfloat方法中,进行修改
方框中是我增加的几行数据,在tft_espi.cpp中修改的
在这里插入图片描述

http://www.lryc.cn/news/2416741.html

相关文章:

  • HTML自动暂停按钮,css 播放暂停按钮实现_html/css_WEB-ITnose
  • Linux命令及详解
  • c语言学习网站大全
  • 部署weblogic
  • 设计模式、设计模式的分类、作用、介绍
  • pushpop指令的操作数必须是字操作数_欧姆龙PLC(CPM1A)功能指令
  • VC++程序由Visual Studio 2003升级到Visual Studio 2005手记
  • (八)SQL SELECT INTO 语句和 INSERT INTO SELECT 语句
  • VS2010序列号(激活码)
  • Java的日期类说明Calendar、Data、日期转化格式化以及注意事项
  • 移动开发最新腾讯一面:请你分别谈谈SharedPreferences 和MMKV,2024年最新今日头条测试面试题
  • GNS3-1.3.10环境部署(新手必备,通俗易懂)
  • 虚拟语气用法总结及真题解析
  • 一键彻底清理!解密如何清理电脑C盘垃圾的绝佳方法
  • linux系统无线驱动在哪下载,在Linux系统中BCM4356无线网卡驱动问题的解决
  • java的递归详细讲解
  • 非常值得收藏的15个 Google 高级搜索技巧
  • Java ClassLoader getResources()方法与示例
  • 计算机毕设ssmSSM农村电商网站3252s(开题+源码)
  • 【个人学习笔记】统一网关gateway
  • 模板王-网页模板,网站模板素材免费下
  • 超详细的Springboot入门教程,看了必会
  • java filter mapping_Java可以从filter-mapping内部的url-pattern中排除一些具体的url吗?...
  • 数据库SQL入门教程
  • Ubuntu 安装教程
  • VB.NET水晶报表Crystal Reports学习(开发环境安装+程序示例+报表示例+客户端运行环境)
  • physxloader.dll x86_physxloader.dll
  • 关于0.99999999和1的问题
  • 性能测试工具Oprofile
  • Butterworth滤波器设计:构建高保真音频信号处理的利器