MAX6675 & ST7735 Library Conflict

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mgiara
 
Posts: 18
Joined: Sat Aug 25, 2018 11:06 pm

MAX6675 & ST7735 Library Conflict

Post by mgiara »

Hello!

I'm building a DIY PCB Hotplate and discovered what I believe might be a bug in these libraries.

Here's my code:

Code: Select all

// this example is public domain. enjoy! https://learn.adafruit.com/thermocouple/

#include "max6675.h"

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

#include <WiFi.h>

int thermoDO = 4;
int thermoCS = 21;
int thermoCLK = 19;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

#define TFT_CS         14
#define TFT_RST        15 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         32

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  //tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
  //Serial.println(F("TFT Initialized"));
  
  Serial.begin(115200);

  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);

  
}

void loop() {
  // basic readout test, just print the current temp
  
  Serial.print("C = "); 
  Serial.println(thermocouple.readCelsius());
  Serial.print("F = ");
  Serial.println(thermocouple.readFahrenheit());
  
  // For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
  delay(1000);
}
My MAX6675 works fine, as does my ST7735 display, but when code for the two are combined, the MAX6675 stops working.

In an attempt to debug, I took the working MAX6675 sketch, and line by line, added code for the ST7735.

It was the initialization that broke the MAX chip:

Code: Select all

tft.initR(INITR_144GREENTAB)

User avatar
mgiara
 
Posts: 18
Joined: Sat Aug 25, 2018 11:06 pm

Re: MAX6675 & ST7735 Library Conflict

Post by mgiara »

Here's a video of my first attempt melting solder paste with the device: [HD is processing!]
https://youtu.be/ddgDMrP8MRA

I'm pretty optimistic thus far and will probably either try another library or switch to one of those SSD1306 screens.

As is, it'll work without the screen so not a huge deal. Just need to bump the reflow temp a couple degrees and maybe have it hold for 5-10 seconds longer.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: MAX6675 & ST7735 Library Conflict

Post by adafruit_support_mike »

Just to check: the MAX6675 and the ST7735 are both SPI devices. When using SPI you have to select the device you want to talk to using the CS pin. The device whose CS pin is low listens to signals on the MOSI/COPI line, and controls the signals on the MISO/CIPO line. Only one device's CS pin can be low at any given time.

Are you controlling the CS pins to select the device you want to use at each moment?

User avatar
mgiara
 
Posts: 18
Joined: Sat Aug 25, 2018 11:06 pm

Re: MAX6675 & ST7735 Library Conflict

Post by mgiara »

adafruit_support_mike wrote: Sun Aug 14, 2022 10:14 pm Just to check: the MAX6675 and the ST7735 are both SPI devices. When using SPI you have to select the device you want to talk to using the CS pin. The device whose CS pin is low listens to signals on the MOSI/COPI line, and controls the signals on the MISO/CIPO line. Only one device's CS pin can be low at any given time.

Are you controlling the CS pins to select the device you want to use at each moment?
I agree, I assumed the libraries were doing this automatically.

To verify, I added

Code: Select all

digitalWrite(therm_CS, LOW);
before sections of code that poll the MAX6675 and then

Code: Select all

digitalWrite(therm_CS, HIGH);
after assuming the CS pins follow the standard of active low.

This did not yield any success so I inverted the logic on the CS pin just to make sure it isn't active high.
Again, no change.

edit:
I also just now added a line to pull the ST7735's CS HIGH before attempting to communicate with the MAX6675. This also did not yield a change.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: MAX6675 & ST7735 Library Conflict

Post by adafruit_support_mike »

mgiara wrote: Tue Aug 16, 2022 5:12 pmI agree, I assumed the libraries were doing this automatically.
No, they don't do that.. it leads to subtle and difficult problems, and is basically impossible when code uses interrupts (which many SPI devices do). It's much easier and more reliable to handle CS selection in higher level code.

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”