使用Arduino和MAX31855x8读取循环

问题描述

我正在尝试改进此代码,以选择每个通道以进一步使用测得的温度和进行计算。在下面的代码中,我想使用特定的Therm Channel,例如从Therm 1测量温度,并计算空气密度,并与其他传感器的数据一起用于进一步计算。

热电偶多路复用器是来自刨花板通道地址背景的Max31855x8:

T2      T1      T0       THERM
L       L       L          0
L       L       H          1
L       H       L          2
L       H       H          3
H       L       L          4
H       L       H          5
H       H       L          6
H       H       H          7

能否请您推荐我如何在以下示例代码提取特定频道?

/*
 MAX31855 library example sketch
 
 This sample code is designed to be used on the MAX31855x8 breakout board.
 Look for the MAX31855 breakout boards on www.whizoo.com.
 
 This sample code corresponds to the MAX31855x8 board.  The board has a single MAX31855 IC on it,and uses a multiplexer
 to select the correct thermoucouple.  The MAX31855 takes around 100ms to take an accurate temperature reading,so 
 the best sample rate one can expect is to sample all 8 channels once-per-second.  If you are only sampling 2 channels
 then you can do it 4 times-per-second,and so on.
 
 There are 2 versions of the MAX31855x8 board: 3.3V and 5V.  There is a solder jumper on the board
 that can be changed to go from one voltage to the other.
 
 This sample code shows how to take a temperature reading:
 1. Set the multiplexer to the correct thermocouple channel
 2. Wait 125ms (0.125 seconds) for the MAX31855 to take an accurate reading
 3. Get the temperature from the MAX31855 

 In the MAX31855 library,there are 2 functions:
 1. float readJunction([CELCUIS|FAHRENHEIT])
 Returns the internal temperature of the MAX31855 IC
 
 2. float readThermocouple([CELCUIS|FAHRENHEIT])
 Returns the temperature of the probe connected to the MAX31855

 readJunction() and readThermocouple() will return the temperature,or one of these errors:
 #define FAULT_OPEN        10000  // No thermocouple
 #define FAULT_SHORT_GND   10001  // Thermocouple short to ground
 #define FAULT_SHORT_VCC   10002  // Thermocouple short to VCC
 #define NO_MAX31855       10003  // MAX31855 not communicating

 Note:  If you connect the thermocouple probe the wrong way around,the temperature will go up
 instead of down (and vice versa).  No problem,just reverse the terminals.
 
 Released under WTFPL license.
 
 27 October 2014 by Peter Easton
 
*/
#include <MAX31855.h>

// Pin connections to the MAX31855x8 board 
// The power requirement for the board is less than 2mA.  Most microcontrollers can source or sink a lot more
// than that one each I/O pin.  For example,the ATmega328 supports up to 20mA.  For convenience,the board
// is placed directly on top of a row of I/O pins on the microcontroller.  Power is supplied to the board by
// holding the GND pin low and the VIN pin high
#define GND  3
#define T0   4
#define T1   5
#define T2   6
#define VIN  7
#define MISO 8
#define CS   9
#define SCK  10

// Create the temperature object,defining the pins used for communication
MAX31855 temp = MAX31855(MISO,CS,SCK);

void setup() {
  // display temperatures using the serial port
  Serial.begin(9600);
  
  // Initialize pins
  pinMode(GND,OUTPUT);
  pinMode(T0,OUTPUT);
  pinMode(T1,OUTPUT);
  pinMode(T2,OUTPUT);
  pinMode(VIN,OUTPUT);
  
  // Power up the board
  digitalWrite(GND,LOW);
  digitalWrite(VIN,HIGH);
  delay(200);
}


void loop () {
  // display the junction temperature
  float temperature = temp.readJunction(CELSIUS);
  Serial.print("J=");
  printTemperature(temperature);
    
  // display the temperatures of the 8 thermocouples
  for (int therm=0; therm<8; therm++) {
    // Select the thermocouple
    digitalWrite(T0,therm & 1? HIGH: LOW);
    digitalWrite(T1,therm & 2? HIGH: LOW);
    digitalWrite(T2,therm & 4? HIGH: LOW);
    // The MAX31855 takes 100ms to sample the thermocouple.
    // Wait a bit longer to be safe.  We'll wait 0.125 seconds
    delay(125);
    
    temperature = temp.readThermocouple(CELSIUS);
    if (temperature == FAULT_OPEN)
        continue;
    Serial.print(" T");
    Serial.print(therm);
    Serial.print("=");
    printTemperature(temperature);
  }
  
  Serial.println();
}


// Print the temperature,or the type of fault
void printTemperature(double temperature) {
  switch ((int) temperature) {
    case FAULT_OPEN:
      Serial.print("FAULT_OPEN");
      break;
    case FAULT_SHORT_GND:
      Serial.print("FAULT_SHORT_GND");
      break;
    case FAULT_SHORT_VCC:
      Serial.print("FAULT_SHORT_VCC");
      break;
    case NO_MAX31855:
      Serial.print("NO_MAX31855");
      break;
    default:
      Serial.print(temperature);
      break;
  }
  Serial.print(" ");
}

我不知道如何更改此通话

  // display the temperatures of the 8 thermocouples
  for (int therm=0; therm<8; therm++) {
    // Select the thermocouple
    digitalWrite(T0,therm & 4? HIGH: LOW);

我尝试使用“反击时”,我尝试了每个频道的特定操作,但仍然迷路。请找到以下改进的代码

#include <MAX31855.h>

// Pin connections to the MAX31855x8 board 
// The power requirement for the board is less than 2mA.  Most microcontrollers can source or sink a lot more
// than that one each I/O pin.  For example,the board
// is placed directly on top of a row of I/O pins on the microcontroller.  Power is supplied to the board by
// holding the GND pin low and the VIN pin high
#define GND  3
#define T0   4
#define T1   5
#define T2   6
#define VIN  7
#define MISO 8
#define CS   9
#define SCK  10

int counter = 0;
// Create the temperature object,HIGH);
  delay(200);
}


void loop () {
  // display the junction temperature
//  float temperature = temp.readJunction(CELSIUS);
//  Serial.print("J=");
//  printTemperature(temperature);
    
  // display the temperatures of the 8 thermocouples
  for (int therm=0; therm<8; therm++) {
    // Select the thermocouple
    digitalWrite(T0,therm & 4? HIGH: LOW);
    // The MAX31855 takes 100ms to sample the thermocouple.
    // Wait a bit longer to be safe.  We'll wait 0.125 seconds
    delay(125);
    
   float temperature = temp.readThermocouple(CELSIUS);
    if (temperature == FAULT_OPEN)
        continue;
    Serial.print(" T");
    Serial.print(therm);
    Serial.print("=");
   // printTemperature(temperature);
    Storefile(temperature);

  }

}


// Print the temperature,or the type of fault
void printTemperature(double temperature) {
  switch ((int) temperature) {
    case FAULT_OPEN:
      Serial.print("FAULT_OPEN");
      break;
    case FAULT_SHORT_GND:
      Serial.print("FAULT_SHORT_GND");
      break;
    case FAULT_SHORT_VCC:
      Serial.print("FAULT_SHORT_VCC");
      break;
    case NO_MAX31855:
      Serial.print("NO_MAX31855");
      break;
    default:
      Serial.print(temperature);
      break;
  }

}


void Storefile(float therm){
    while(1){//while loop

    if(counter==0){
      float I0=therm;
      float ro0 = 352.6 / (I0 + 273.15);
      counter++;
      Serial.print(" T0");
      Serial.print("=");
      Serial.print(I0);
      Serial.print(" ro0= ");
      Serial.print("=");
      Serial.print(ro0);
      delay(125);
      break; }
    }//counter 0

    if(counter==1){
      float I1=therm;
      float ro1 = 352.6 / (I1 + 273.15);
      counter++;
      Serial.print(" T1");
      Serial.print("=");
      Serial.print(I1);
      Serial.print(" ro1= ");
      Serial.print("=");
      Serial.print(ro1);
      delay(125);

    }

    if(counter==2){
      float I2=therm;
      counter++;
      Serial.print(" T2");
      Serial.print("=");
      Serial.print(I2);
      delay(125);

    }

    if(counter==3){
      float I3=therm;
      float ro3 = 352.6 / (I3 + 273.15);
      counter++;
      Serial.print(" T3");
      Serial.print("=");
     Serial.print(I3);
      delay(125);

    }

    if(counter==4){
      float I4=therm;
      counter++;
     Serial.print(" T4");
      Serial.print("=");
      Serial.print(I4);
      delay(125);

    }

    if(counter==5){
      float I5=therm;
      counter++;      Serial.print(" T5");
      Serial.print("=");
     Serial.print(I5);
      delay(125);
 //     break; }
    }

    if(counter==6){
      float I6=therm;
      counter++;
      Serial.print(" T6");      
      Serial.print("=");     
      Serial.print(I6);
      delay(125);

    }

    if(counter==7){
      float I7=therm;
      counter++;
      Serial.print(" T7");
      Serial.print("=");
      Serial.print(I7);

    }

    if(counter==8){
      counter=0;//reset counter to 0
     Serial.println();
 }
    //}
    }

我将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...