Interfacing SPI Sensor with ESP32 Lora Module

Hey Guys,

I am trying to read a k-thermocouple from my esp32 lora module but can't figure out if this is possible or not through SPI. It seems that there is some connectivity between the Lora and usual SPI pins (DO,CS,CLK) that the thermocouple would need.

Is it even possible to interface a MAX6675 and esp32 Lora module if these pins are being used by Lora radio? I usually use max6675 to interface with k thermocouple, because it is cheap. But if there is another approach, I would be interested. I do know that you can buy/make a pcb to convert thermocouple data to analog output, but these are typically more expensive than just MAX6675. A picture of the ESP32 board is attached.

Thanks

SPI devices generally share the common MOSI, MISO and SCK signals. Each SPI device has a separate chip select signal. If you have a spare pin you can use that as the CS pin for the thermocouple.

markd833:
SPI devices generally share the common MOSI, MISO and SCK signals. Each SPI device has a separate chip select signal. If you have a spare pin you can use that as the CS pin for the thermocouple.

These pins are physically unoccupied, but they have put a warning saying not to use these pins unless "you know what you are doing". So I feel like there has to be a reason why they put this warning.
I plan to use pins: GPIO 18 (CLK), GPIO 19 (DO), GPIO 5 (CS) will the LORA module still be able to communicate?

Edit: After doing some more reading I think I understand the previous post better. That is I can use the same MOSI, MISO, and SCK as the Lora module. But I need a unique CS pin. Can any of the SPI pins be used (light blue)?

If I use the same MISO and SCK pins as the LORA module, that is GPIO 19 and 5 respectively. Which pin can I use for CS since it has to be unique? Could I use GPIO15 for CS?

Any spare digital i/o pin can be used as the CS signal. You need to tell whichever library you are using for the SPI device, which pin you are using and you should be good to go.

markd833:
Any spare digital i/o pin can be used as the CS signal. You need to tell whichever library you are using for the SPI device, which pin you are using and you should be good to go.

I appreciate the suggestion, I followed the advice but cannot get this to work on ESP32 Lora. I tested and can get temperature readings fine on Arduino UNO SPI, but cannot get to work for my ESP. I just get crazy readings 1000C+
My set-up on ESP: MAX6675: MISO to GPIO 19, CS to GPIO 23 (also tried GPIO 15), SCK to GPIO 5.

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

#include "max6675.h"

int thermoDO = 19;
int thermoCS = 23;
int thermoCLK = 5;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

void setup() {
  Serial.begin(9600);

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

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(3000);
}

Does anyone understand what could be causing the issue? From the comments I feel like this should be working.

I would first test the MAX6675 on an ESP32 that does not have the LoRa module connected.

I also note that you do not appear to be disabling the LoRa device, CS.

I'm not sure how relevant this is as I don't have an ESP32 module ...

I took a quick look at the Adafruit library and although it uses the acronym SPI, it is not using the SPI hardware. It's doing a software version of it. I don't know why they are doing that.

I also saw other examples of using a MAX6675 that used the shiftIn() function to achieve the same thing as the Adafruit library.

Have you tried using the actual SPI hardware pins and SPI library to talk to it?

markd833:
I'm not sure how relevant this is as I don't have an ESP32 module ...

I took a quick look at the Adafruit library and although it uses the acronym SPI, it is not using the SPI hardware. It's doing a software version of it. I don't know why they are doing that.

I also saw other examples of using a MAX6675 that used the shiftIn() function to achieve the same thing as the Adafruit library.

Have you tried using the actual SPI hardware pins and SPI library to talk to it?

The MAX6675 is not an SPI device, it only claims to have a 'similar' interface.
So presuambly the library writers to decided to use a shift out type interface which could then use any choise of pins.

srnet:
I would first test the MAX6675 on an ESP32 that does not have the LoRa module connected.

I also note that you do not appear to be disabling the LoRa device, CS.

My end goal is to have the lora module working and the thermocouple reading. I do not have a standard esp32 to perform a test.

markd833:
I'm not sure how relevant this is as I don't have an ESP32 module ...

I took a quick look at the Adafruit library and although it uses the acronym SPI, it is not using the SPI hardware. It's doing a software version of it. I don't know why they are doing that.

I also saw other examples of using a MAX6675 that used the shiftIn() function to achieve the same thing as the Adafruit library.

Have you tried using the actual SPI hardware pins and SPI library to talk to it?

Thanks for taking a look, I appreciate your advice thus far! I believe based on the pin diagram I attached in the first post, that I am using the actual SPI hardware pins, except for CS pin.
MAX6675: MISO to GPIO 19, CS to GPIO 23 (also tried GPIO 15), SCK to GPIO 5.

If you are using the actual SPI hardware pins, then I would suggest that you use the SPI library to drive the SPI hardware. The SPI transfer() function should get you the data via the hardware.

The ESP32 has 2 SPI busses VSPI and HSPI, from the last post it looks like the VSPI SPI buss should be the first choice of use of the ESP32 being used.

The HSPI SPI buss on a ESP32 deserves a warning to not use unless it is known what you are doing. because those GPIO_NUM_14, GPIO_NUM_12, and GPIO_NUM_13 are shared with the TMS, TDI, and TDK signals. Those signals must not be changed by an externail device during program load into flash. Otherwise the HSPI buss is good to go.

HSPI uses MISO GPIO_NUM_19, CS to GPIO_NUM_5, SCK to GPIO_NUM_18, MOSI GPIO_NUM_23. The SPI driver module can control 3 SPI devices per SPI buss.

feynman137:
My end goal is to have the lora module working and the thermocouple reading. I do not have a standard esp32 to perform a test.

Good luck on your journey then.

Your software appears to be calling the MAX6675 in software (as in non hardware SPI) mode. So I cannot see its relavent which are the respective hardware SPI port pins.

Read the library documentation.

Idahowalker:
The ESP32 has 2 SPI busses VSPI and HSPI, from the last post it looks like the VSPI SPI buss should be the first choice of use of the ESP32 being used.

The HSPI SPI buss on a ESP32 deserves a warning to not use unless it is known what you are doing. because those GPIO_NUM_14, GPIO_NUM_12, and GPIO_NUM_13 are shared with the TMS, TDI, and TDK signals. Those signals must not be changed by an externail device during program load into flash. Otherwise the HSPI buss is good to go.

HSPI uses MISO GPIO_NUM_19, CS to GPIO_NUM_5, SCK to GPIO_NUM_18, MOSI GPIO_NUM_23. The SPI driver module can control 3 SPI devices per SPI buss.

Okay this makes sense! I do see both HSPI and VSPI labeled on the pin diagram. But it looks like you may have meant VSPI bus uses: MISO GPIO_NUM_19, CS to GPIO_NUM_5, SCK to GPIO_NUM_18, MOSI GPIO_NUM_23. The SPI driver module can control 3 SPI devices per SPI buss.

If so, I will definitely try this set-up. But if you look at the diagram why is the Lora modules SPI configuration so strange?

Its configuration is not Lora CLK->Board CLK, Lora CS->Board CS, Lora MISO->Board MISO

But is apparently: Lora CLK → Board CS, Lora CS->Board CLK, LORA MISO → Board ?

Is this just a mislabeling on the manufacture’s part?

I am unfamiliar with the LoRa thingy.

Alright. Below is what I have tried with absolutely no luck on the readings.

esp32 attempts.png

esp32 attempts.png

What does LoRa have to say about their product not working?

The code you tried?

Have you tried to connect to another SPI device; like an OLED display to see if the LoRa thingy can do SPI?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.