Skip to content

Instantly share code, notes, and snippets.

@algrant
Created March 14, 2021 23:20
Show Gist options
  • Save algrant/cd86aedb10d1b8f9302a87aa4770f49e to your computer and use it in GitHub Desktop.
Save algrant/cd86aedb10d1b8f9302a87aa4770f49e to your computer and use it in GitHub Desktop.
ESP-32-CAM with 3 MAX6657 temperature sensors. Custom pinouts for SPI
#include <SPI.h> // MAX6675 over hardware SPI
#define TC1_CS 12 // GPIO 12
#define TC2_CS 13 // GPIO 13
#define TC3_CS 15 // GPIO 15
/* Note: All MAX6675
* MAX6675 to EPS32
* VCC -> 3.3V
* GND -> GND
* SCK -> GPIO 14/CLK
* SO -> GPIO 2/MISO
*
* I chose these pins for CLK & MISO mainly cause of this:
* https://github.com/raphaelbs/esp32-cam-ai-thinker/blob/master/docs/esp32cam-pin-notes.md
* and figured out how to make SPI work with non-standard pins cause of this:
* https://www.youtube.com/watch?v=w3VIxtLPuRE
*/
#define ESP32_CAM_CLK 14
#define ESP32_CAM_MISO 2
// MAX6675
double readCelsius(uint8_t cs) {
uint16_t v;
digitalWrite(cs, LOW);
v = SPI.transfer(0x00);
v <<= 8;
v |= SPI.transfer(0x00);
digitalWrite(cs, HIGH);
if (v & 0x4) {
// uh oh, no thermocouple attached!
return NAN;
}
v >>= 3;
return v*0.25;
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
// SPI Setup
pinMode(TC1_CS, OUTPUT);
digitalWrite(TC1_CS, HIGH);
pinMode(TC2_CS, OUTPUT);
digitalWrite(TC2_CS, HIGH);
pinMode(TC3_CS, OUTPUT);
digitalWrite(TC3_CS, HIGH);
SPI.begin(ESP32_CAM_CLK, ESP32_CAM_MISO);
SPI.beginTransaction (SPISettings (1000000, MSBFIRST, SPI_MODE0));
}
int i = 0;
void loop() {
Serial.println();
Serial.print("T1: ");
Serial.print(readCelsius(TC1_CS));
Serial.print(", T2: ");
Serial.print(readCelsius(TC2_CS));
Serial.print(", T3: ");
Serial.print(readCelsius(TC3_CS));
Serial.println();
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment