1

I have 8xMAX31856 and I am trying to use the Adafruit library. Instead of writing all 8 thermocouple channels each time in code (and wasting memory), I want to store the objects in an array and loop through them periodically.

Here is my code:

Adafruit_MAX31856 TCouple1 = Adafruit_MAX31856(2,11,12,13);
Adafruit_MAX31856 TCouple2 = Adafruit_MAX31856(3,11,12,13);
Adafruit_MAX31856 TCouple3 = Adafruit_MAX31856(4,11,12,13);
Adafruit_MAX31856 TCouple4 = Adafruit_MAX31856(5,11,12,13);
Adafruit_MAX31856 TCouple5 = Adafruit_MAX31856(6,11,12,13);
Adafruit_MAX31856 TCouple6 = Adafruit_MAX31856(7,11,12,13);
Adafruit_MAX31856 TCouple7 = Adafruit_MAX31856(8,11,12,13);
Adafruit_MAX31856 TCouple8 = Adafruit_MAX31856(9,11,12,13);

char* thermocouples[] = {TCouple1, TCouple2, TCouple3, TCouple4, TCouple5, TCouple6, TCouple7, TCouple8};

however, I am met with this error on compile:

cannot convert 'Adafruit_MAX31856' to 'char*' in initialization

Why can I not store these variables in an array and call on them later? Is there another way to do this? They work on SPI logic...

1

You CAN store them in an array, but NOT in an array of pointers to characters. That is just the wrong type. Try

Adafruit_MAX31856 thermocouples[] = {TCouple1, ...}

or even ditch the first declarations and use

Adafruit_MAX31856 thermocouples[] = {
    Adafruit_MAX31856(2,11,12,13),
    Adafruit_MAX31856(3,11,12,13),
    Adafruit_MAX31856(4,11,12,13),
    ...
};

I don't have that library installed, but I tried compiling this pattern with the Bounce2 library and it works. That looks like this:

Bounce buttons[] = {
    Bounce(),
    Bounce(),
    Bounce()
};
2
  • Alright! I have tried that and it compiles past it... but how do I loop through this array? I tried for(int i = 0; i<8; i++){thermocouples[i].setThermocoupleType(MAX31856_TCTYPE_T);} and it says it is void
    – NRav
    Sep 23 '20 at 14:32
  • nevermind... sorted out issue. Thanks for the guidance!
    – NRav
    Sep 23 '20 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.