乐鑫技术交流
直播中

笑尽往事

9年用户 863经验值
擅长:可编程逻辑 电源/新能源
私信 关注
[问答]

max31855连接到wemos时,无法使用adafruit的示例代码serialtermocouple获得任何信号怎么解决?

我已经将 max31855 与 arduino 一起使用了一段时间,我认为是时候将项目迁移到 esp 平台了。我没有找到适用于 Wemos D1 的任何 max31855 防护罩,所以我的计划是自己制作一个。但是,当将模块直接连接到 wemos 时,我无法使用 adafruit 的示例代码 serialtermocouple 获得任何信号:
代码:全选/***************************************************
  This is an example for the Adafruit Thermocouple Sensor w/MAX31855K

  Designed specifically to work with the Adafruit Thermocouple Sensor

  These displays use SPI to communicate, 3 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
****************************************************/

#include
#include "Adafruit_MAX31855.h"

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.

//arduino nano
//#define MAXDO   4
//#define MAXCS   5
//#define MAXCLK  3

// esp8266
#define MAXDO   D6//12
#define MAXCS   D1//5
#define MAXCLK  D5//14

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Example creating a thermocouple instance with hardware SPI (Uno/Mega only)
// on a given CS pin.
//#define MAXCS   10
//Adafruit_MAX31855 thermocouple(MAXCS);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

void setup() {
  #ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif
  
  Serial.begin(9600);
  
  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   if (isnan(c)) {
     Serial.println("Something wrong with thermocouple!");
   } else {
     Serial.print("C = ");
     Serial.println(c);
   }
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFarenheit());

   delay(1000);
}

我搭建了一个只有max31855、一个arduino和一个wemos d1的面包板来对比定位问题。
我的设置照片:
arduino nano(左)通过逻辑电平转换器连接,因为它在 5V 上运行,而 max31855 需要 3.3V。esp 直接连接到模块。有点难看,但所有颜色都根据以下颜色编码:
5V 红色
3.3V 橙色
gnd 黑色
DO 蓝色
CS 紫色
CLK 黄色
它在 arduino 上工作得很好,但从 esp 我只得到零读数:
我已经为 wemos 测试了一些不同的引脚,但似乎没有任何区别。
根据我的阅读,将 esp 与 max 芯片一起使用应该没有问题。

回帖(1)

小组店小二

2023-9-25 10:07:31
首先,请确保你在正确的引脚连接上 max31855 模块。你需要确保 SCK、CS 和 DO 引脚都正确连接。

如果连接正确,可以尝试增加一些延迟时间。有时候,ESP8266 需要更多的时间来与 max31855 进行通信。你可以在代码中进行尝试更改以下行:

#define MAX31855_DELAY_MS 1000

将其更改为较长的延迟时间。

另外,请确保代码中引用的 SPI 库与你的 Wemos D1 兼容。有时,需要使用不同的 SPI 库。你可以尝试更改以下行:

#include

将其更改为以下内容:

#include
#include

如果这些方法都不能解决问题,可能需要考虑其他问题,例如你的硬件是否损坏,或者是否有错误的代码。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分