使用Arduino和MAX31855x8读取循环

如何解决使用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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-