如何在LabVIEW中读取Adafruit INA 219?如何用LabVIEW从Arduino中获取串行数据?

问题描述 投票:-1回答:1

我尝试用Arduino读取Adafruit INA 219传感器的电压和电流,我得到了正确的结果。问题是我需要分析这些结果,我需要在LabVIEW中读取传感器的值,或者将结果从Arduino发送到Labview中。

Arduino的代码。

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;


void setup(void) 
{
  Serial.begin(115200);
  while (!Serial) {
      // will pause Zero, Leonardo, etc until serial console opens
      delay(1);
  }

  uint32_t currentFrequency;

  Serial.println("Hello!");

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

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void) 
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  loadvoltage = busvoltage + (shuntvoltage / 1000);

  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  //Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.println("");

  delay(500);
}

试着用LabVIEW读取Adafruit INA 219。

arduino labview adafruit
1个回答
0
投票

目前你的值被Arduino读取,并以字符串的形式发送到串口。

如果你想使用这种格式与LabVIEW通信,那么你不需要使用LINX工具包--你可以通过VISA节点使用串口。

然后,你需要将字符串转换为数值,以便能够用它们做一些 "有用 "的事情。你可以尝试使用类似 匹配模式匹配正则表达式.

这样的东西可能是你要找的。LabVIEW code to read Serial port

顺便说一句,虽然我喜欢StackOverflow,但对于LabVIEW相关的问题,你可能会在forum.ni.com上得到更快的回应(而且不太可能因为讨论相关而被关闭,或者重复)。

© www.soinside.com 2019 - 2024. All rights reserved.