数码之家

 找回密码
 立即注册
搜索
查看: 1652|回复: 1

[Arduino] 自己鼓捣个电流表 可以显示10MA电流

[复制链接]
发表于 2020-3-30 19:43:41 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
普通的USB电流表多数都显示不了《10MA的电流

虽然我买了个贵的,但是贵了就不舍得用了。。。

于是TB了模块 搞个便宜的。。。

lgt8f328p -- 3.5
USB 公母头 1块钱
5块钱打板(5张)
INA219 5块
数码管 1.5

不到20块钱或者说10块钱左右。。。。。。

要我自己焊洞洞的话,肯定没这么小,虽然比USB的电流表还是要大不少。但是 我觉得够了。。。
要认同自己的能力:lol:

IMG_0324.JPG

  1. /*
  2. ReadAnalogVoltage

  3. lgt8f328p读取电压 Wemos TTGO XI 8F328P-U Board

  4. adafruit / Adafruit_INA219
  5. */
  6. // the setup routine runs once when you press reset:
  7. #include <math.h >

  8. #include "TM1637.h"
  9. #include <Adafruit_INA219.h>

  10. Adafruit_INA219 ina219;

  11. #define CLK 10//pins definitions for TM1637 and can be changed to other ports
  12. #define DIO 9
  13. TM1637 tm1637(CLK, DIO);
  14. unsigned char ClockPoint = 1;
  15. int sensorValue = 0;

  16. unsigned char hour = 0;
  17. unsigned char minute = 0;
  18. int8_t TimeDisp[] = { 0x00, 0x00, 0x00, 0x00 };
  19. //float shuntvoltage = 0;
  20. //  float busvoltage = 0;
  21.   float current_mA = 0;
  22. //  float loadvoltage = 0;
  23. // float power_mW = 0;


  24. void TimeUpdate(void) { int sensorValuesa=current_mA*10;


  25.         if (ClockPoint) {
  26.                  tm1637.point(POINT_ON);
  27.         //        Serial.println(sensorValuesa / 1);
  28.         //        delay(100);
  29.         //        tm1637.set(BRIGHT);
  30.                 TimeDisp[0] = sensorValuesa / 100 / 10;
  31.                 TimeDisp[1] = sensorValuesa / 100 % 10;
  32.                 TimeDisp[2] = sensorValuesa % 100 / 10;
  33.                 TimeDisp[3] = sensorValuesa % 100 % 10;
  34.         }



  35. }

  36. void setup() {
  37.         // initialize serial communication at 9600 bits per second:
  38.         //Serial.begin(9600);

  39.         uint32_t currentFrequency;

  40.         // Initialize the INA219.
  41.         // By default the initialization will use the largest range (32V, 2A).  However
  42.         // you can call a setCalibration function to change this range (see comments).
  43.         ina219.begin();
  44.         // To use a slightly lower 32V, 1A range (higher precision on amps):
  45.         //ina219.setCalibration_32V_1A();
  46.         // Or to use a lower 16V, 400mA range (higher precision on volts and amps):
  47.         ina219.setCalibration_16V_400mA();


  48.         tm1637.init();
  49.         tm1637.set(BRIGHT_TYPICAL); //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  50.         tm1637.point(POINT_OFF);
  51.         analogReference(INTERNAL2V56); //use internal 1.1v as Avref
  52.         //analogReference(EXTERNAL); //使用外部基准

  53. //analogReference(type)
  54. //描述
  55. //配置用于模拟输入的基准电压(即输入范围的最大值)。选项有:
  56. //DEFAULT:默认5V(Ocrobot控制板为5V)或3.3伏特(Ocrobot控制板为3.3V)为基准电压。
  57. //INTERNAL:在ATmega168和ATmega328上以1.1V为基准电压,以及在ATmega8上以2.56V为基准电压(Ocrobot Mega无此选项)
  58. ////INTERNAL1V1:以1.1V为基准电压(此选项仅针对Ocrobot Mega)
  59. //INTERNAL2V56:以2.56V为基准电压(此选项仅针对Ocrobot Mega)
  60. //EXTERNAL:以AREF引脚(0至5V)的电压作为基准电压。
  61. //参数
  62. //type:使用哪种参考类型(DEFAULT, INTERNAL, INTERNAL1V1, INTERNAL2V56, INTERNAL4V096 或者 EXTERNAL)。
  63. //返回
  64. //无

  65.         uint32_t guid = (GUID3 << 24) | (GUID2 << 16) | (GUID1 << 8) | GUID0; // 给guid赋值唯一ID
  66.         //Serial.println(guid); // 串口输出唯一ID
  67.         delay(2000);
  68. }

  69. // the loop routine runs over and over again forever:
  70. void loop() {
  71.         // read the input on analog pin 0:
  72.         //sensorValue = analogRead(A0);



  73.         //  shuntvoltage = ina219.getShuntVoltage_mV();
  74.         //  busvoltage = ina219.getBusVoltage_V();
  75.           current_mA = ina219.getCurrent_mA();
  76.         //  power_mW = ina219.getPower_mW();
  77.         //  loadvoltage = busvoltage + (shuntvoltage / 1000);

  78.         //  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  79.         //  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  80.         //  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  81.         //  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  82.           //Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
  83.         //  Serial.println("");

  84.           delay(200);



  85.         // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  86.         //float voltage = sensorValue * (2.56 / 4096.0);
  87.         // print out the value you read:
  88.         //Serial.print(sensorValue);
  89.         //Serial.print(' ');
  90.         //Serial.print(cbrt(sensorValue));
  91.         //Serial.print(' ');
  92.         //Serial.println(voltage);

  93.         //delay(1000);
  94.         TimeUpdate();
  95.         tm1637.display(TimeDisp);
  96. }
复制代码




打赏

参与人数 4家元 +80 收起 理由
寂静的春天 + 20 謝謝分享
xixia001 + 30
家睦 + 20
人艰不拆了 + 10

查看全部打赏

发表于 2020-3-30 23:10:36 来自手机浏览器 | 显示全部楼层
厉害啊你是个天才
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-17 02:40 , Processed in 0.265200 second(s), 14 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

快速回复 返回顶部 返回列表