如何使用MCP342x库读取4个通道?

时间:2019-04-25 17:10:49

标签: arduino arduino-c++

我将Arduino Mega2560和MCP3424与以下库(https://github.com/stevemarple/MCP342x)结合使用,以从热电偶读取数据。它非常适合一个频道。但是,当我尝试添加第二个通道时(实际上我需要所有4个通道),我得到了错误的数据。 我怎么了?

我试图用相同的地址创建2个MCP342x对象,并分别对其进行配置,但这没用。

下面是库中略有改动的GeneralCallConversion示例

uint8_t address = 0x6E;
MCP342x adc_ch1 = MCP342x(address);
MCP342x adc_ch2 = MCP342x(address);
// Configuration settings
MCP342x::Config config1(MCP342x::channel1, MCP342x::oneShot,
           MCP342x::resolution18, MCP342x::gain8);
MCP342x::Config config2(MCP342x::channel2, MCP342x::oneShot,
           MCP342x::resolution18, MCP342x::gain8);
// Configuration/status read back from the ADC
MCP342x::Config status1;
MCP342x::Config status2;
//some code here
// Configure the device with the desired settings. If there are
// multiple devices you must do this for each one.
adc_ch1.configure(config1);
adc_ch2.configure(config2);
// some code here

void setup(void)
{some code here}

void loop(void)
{
  long value1 = 0;
  long value2 = 0;
  uint8_t err1;
  uint8_t err2;
  if (startConversion) {
    MCP342x::generalCallConversion();
    startConversion = false;
  }
  err1 = adc_ch1.read(value1, status1);
  err2 = adc_ch2.read(value2, status2);
  if (!err1 && !err2 && status1.isReady() && status2.isReady()) { 
    Serial.print("Value: ");
    Serial.print(value1);
    Serial.print("  ");
    Serial.println(value2);
    startConversion = true;
  }
  delay(5000);
}

输出读数大约比应该小两个数量级。

0 个答案:

没有答案