I am using an Arduino Uno and MAX31856 board to controller heater cartridges and to monitor the temperature. The code below runs perfect on my Macbook and my coworker's Windows. We both have Arduino IDE 2.3.2. I setup a Raspberry Pi 4 that runs the Raspberry Pi OS (64-bit). I downloaded Arduino IDE 1.8.19 for Linux (64 bit). Sometimes the code runs fine, but other times the temperature will get stuck at 0°C or will continuously repeat the last temperature it recorded. When I connect it back to the Macbook after this happens, it works fine. All the same libraries have been downloaded to the Raspberry Pi. I put the code below. We are very new to all of this, so we will gladly take any advice you give us!! Sorry for all the commented out lines. Thanks.
#include <Adafruit_MAX31856.h>
const int RELAY_PIN1 = A5;
const int RELAY_PIN2 = A4;
const int RELAY_PIN3 = A3;
const int RELAY_PIN4 = A2;
// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10);
// use hardware SPI, pass in the CS pin and using SPI1
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, &SPI1);
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("MAX31856 thermocouple test");
pinMode(RELAY_PIN1, OUTPUT);
pinMode(RELAY_PIN2, OUTPUT);
pinMode(RELAY_PIN3, OUTPUT);
pinMode(RELAY_PIN4, OUTPUT);
if (!maxthermo.begin()) {
Serial.println("Could not initialize thermocouple.");
while (1) delay(10);
}
maxthermo.setThermocoupleType(MAX31856_TCTYPE_K);
Serial.print("Thermocouple type: ");
switch (maxthermo.getThermocoupleType() ) {
case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
default: Serial.println("Unknown"); break;
}
maxthermo.setConversionMode(MAX31856_CONTINUOUS);
}
void loop() {
// trigger a conversion, returns immediately
// maxthermo.triggerOneShot();
//
// here's where you can do other things
//
delay(500); // replace this with whatever
//
//
// check for conversion complete and read temperature
// if (maxthermo.conversionComplete()) {
float a = maxthermo.readThermocoupleTemperature();
Serial.println(a);
// } else {
// Serial.println("Conversion not complete!");
// }
// constants won't change
// the Arduino pin, which connects to the IN pin of relay
// the setup function runs once when you press reset or power the board
//void setup() {
// initialize digital pin A5 as an output.
// the loop function runs over and over again forever
//void loop() {
// digitalWrite(RELAY_PIN, HIGH); // turn on heating element 5 seconds
// delay(500000);
// digitalWrite(RELAY_PIN, LOW); // turn off heating element 5 seconds
// delay(50);
//}
if (a <= 100){
digitalWrite(RELAY_PIN1, HIGH);
Serial.println("RELAY PIN HIGH");
}
else{
digitalWrite(RELAY_PIN1, LOW);
delay(1000);
}
if (a <= 100){
digitalWrite(RELAY_PIN2, HIGH);
Serial.println("RELAY PIN HIGH");
}
else{
digitalWrite(RELAY_PIN2, LOW);
delay(1000);
}
if (a <= 100){
digitalWrite(RELAY_PIN3, HIGH);
Serial.println("RELAY PIN HIGH");
}
else{
digitalWrite(RELAY_PIN3, LOW);
delay(1000);
}
if (a <= 100){
digitalWrite(RELAY_PIN4, HIGH);
Serial.println("RELAY PIN HIGH");
}
else{
digitalWrite(RELAY_PIN4, LOW);
delay(1000);
}
}
The code you posted runs on the Arduino Uno, not on the Mac or the RPi.
I don't understand your description of the problem.
You don't need the Arduino IDE to monitor the program output. A serial terminal app on the Rpi or the PC will do, but you need a UART Serial to USB converter or logic level converter of some sort, in all cases.
When the Arduino Uno is connected to the RPi and we are looking at the Arduino IDE serial monitor, it will repeat 0.00. Since it says 0.00, the heat cartridges will not turn off, even though the real temperature is at least 90 degrees. When we run Arduino IDE from a Macbook or a Windows computer, the serial monitor is reporting the correct temperatures. We are just confused why it gets stuck and repeats the same temperature on the RPi's Arduino IDE, but maybe not using Arduino IDE to track it might be the solution. Hopefully, that makes more sense.
I assume you are connecting the UNO USB to a RPi USB which creates a virtual serial port, e.g. dev/ttyUSB0, which you then read to get the temperature
in such a case the UNO is being powered by the RPi power supply which may not be able to supply sufficient voltage/current resulting in the temperature sensor returning 0
try powering the UNO from an external 5volt power upply
No, you should use a 5V power supply connected to the Arduino 5V pin. Connect all the grounds.
However, if the RPi power supply is that marginal, you are very likely to have other problems with the RPi. What are you using for the RPi power supply?
If you actually do have the " Raspberry Pi 18W 5V 3.6A Power Supply with ON/Off Switch" then that is not the problem.
Into your next post, please copy/paste the text output that appears on the Arduino serial monitor when the program is uploaded and run from the RPi. Use code tags when pasting.
Also, post a wiring diagram showing everything that is connected to the Arduino, and how it is powered. The Arduino 5V output cannot be used for heaters.
Here's a rough sketch of what the setup looks like. There was not any good options available at this time for the heaters. The red wires on the right are the heaters, one wire is connected to the relay and the other to the generic power source. The power source connected to the cartridge and the green wires from the relay has a 0-60 V output and is adjustable. I believe it is this one. The relay is powered by a 12 V adapter. I do not have access to the RPi's Arduino IDE serial output right now, but will post it as soon as possible.
⸮⸮⸮⸮MAX31856 thermocouple test
Thermocouple type: K Type
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH
0.00
RELAY PIN HIGH
RELAY PIN HIGH
RELAY PIN HIGH