Writing Data to SDCard with Multplex Shield

Thanks Stefan.....strange as I'm following those steps to paste code as you indicated in my first post....maybe I need to highlight the entire code first next time. Good to know on the serial output as well, didnt realize it worked that way.
Regarding the code you've pasted, I'll take a look at it this evening...from what you've shown this looks straightforward......at least until I attempt doing it.....lol. Great way to learn none the less.


additional comment:

most of the time I'm using ESP32 which have a lot of RAM. (320 kB)

As an Arduino Uno has only 2KB of RAM I think it will be a good to idea to set the length of the SafeStrings to that length that is really needed.

maybe even eliminating the timestamp-variable would be good (saves another 32 bytes)
A string like I suggested

2021.08.24 ; 09:07:05 ; 55.23 ; 55.23 ; 55.23 ; 55.23 ; 55.23 ; 55.23 ; 55.23 ; 55.23 ;

needs 87 bytes
while a string like this


needs only 65 bytes.
And of course writing to SD-Card with multiple


works too

Whenever an application needs permanent processor-power and is not battery-operated I use the ESP32.

If for an application it is acceptable to let the CPU "deepsleep" for 2 minutes then wake up for 0,1 seconds read in some sensordata, send sensor-data fall into deep-sleep again
an ESP32 can be used too because in deepsleep-mode (where the onboard-RTC is still working) the current is as low as 150µA. So a medium sized battery is lasting very long

best regards Stefan

I'm now using the MuxTest code, I've changed code to #define MUX 1 in the .h file and updated the TCM.setMUX (channel-1).
Serial monitor output now is outputing blocks of 8 lines at a time which my expectation is to print 1 line with all 8 channel temperature readings/errors. I've added a serial.print(channel) to the error code section to ensure the channel number was updating every loop, which it is.
I've also moved the serial.print(external) to the error code section as I'd like the code to determine if there is an error first and print if so, but if no error then print the external temperature.... hope this makes sense. I don't believe the Channel count you see in the serial monitor output is actually looking at the MUX channel data...it seems like it is just counting based on how i read the code.

Examle for MAX31855_lib library for MAX31855* thermocouple amplifier
Written by Cory J. Fowler
BSD license, all text above must be included in any redistribution.

#include <SPI.h>
#include <MAX31855.h>

const byte scale = 2; // 0 is Celsius/Centigrade, ~80µs. 1 is Kelvin, ~108µs. 2 is Fahrenheit ~100µs. 3 is Rankine, ~100µs.

byte error;
byte channel = 0;

double external;
double internal;

//print temp test - code from header file
//double intTemp(int _SCALE);
//double extTemp(int _SCALE);
//byte tempErr();

MAX31855 TCM(9);

void setup() {
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

void loop() {

TCM.setMUX(channel - 1); // Set MUX channel, enable MUX, and start MAX31855 conversion process.
TCM.getTemp(external, internal, scale, error); // Read MAX31855

//if(channel == 0) // Just print the channel 1's cold junction
//Serial.println("Cold Junction Temperature:");
Serial.print(" , ");

//Serial.println("Thermocouple Temperature:");
//Serial.print(" , ");

if (error & 0x01) {
Serial.print(" ");
Serial.print(" ");
} else if (error & 0x02) {
} else if (error & 0x04) {
} else

if (channel == 7) {
channel = 0;
} else {

Serial Monitor Output

21:05:00.551 -> 79.81F , Channel 1 Open
21:05:00.645 -> 79.81F , Channel 2 Open
21:05:00.739 -> 79.81F , Channel 3 Open
21:05:00.832 -> 79.93F , Channel 4 Open
21:05:00.926 -> 79.81F , Channel 5 Open
21:05:01.020 -> 79.81F , Channel 6 Open
21:05:01.114 -> 79.81F , Channel 7 Open

Will definitely use this once i get the device working as intended. Thank you

This library is using a programming-technique of "handover the RAM-Adress of the variable mentioned in the code" and update the value at this adress.

You are initialising channel with zero and then do a calculation of

TCM.setMUX(channel - 1);

this means you try to set channel "-1" but as byte is unsigned

The original example-code has

byte channel = 0;

This means the comment
use channel -1 is meant
if you number your channels starting at 1 going on 2,3,4,5,6,7,8 reading a so defined channel as "channel-1"

The function-call to setMUX needs numbers starting at 0 going on 1,2,3,4,5,6,7

0 to 7

As a general hint:
You should start with the working code of the example
to check if the hardware and the wiring is OK
and then do small modifications to the code and test
small modifications to the code and RE-test

my experience: trying to be quick (through too much code-changing) slows you down (through long searches for the bug

best regards Stefan

Success !!
Well, I believe i forgoed the logic as presented for some unexplainable reason.
I certainly tried the original code which didnt seem to work, so I proceeded to play with TCM.setMUX(channel - 1); .
Sooo, changing this back to the original value from the library as you suggested... all channels are working perfectly. When i move the thermocouple to each channel, i get a correct temperature value.
I'll add the SD Datalogging Card code this weekend and use your advice on reducing data size, but that seems straightforward. I've learned alot on this project and ready for the next.
Your efforts here are greatly appreciated Stefan!!! Thank you and Cheers !!!