🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    SPI clash between LCD and nRF24L01

    PRODUCTS
    4
    14
    36.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      skelstar
      last edited by

      @m5stack any ideas about this? I shouldn't have any issues using other devices that use SPI should I?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • S
        sibtcha
        last edited by

        Hello, It seems like I have a problem similaire has yours... I would like to use à MAX6675 to get temperature from a Thermocouple K, but this board use SPI.

        When I test my code in a ESP32, it's OK. When I test my code in the M5Stack without the M5.begin(), it's ok, but when I include de M5.begin, the value returned by the MAX6675 are 0

        Is there any solution ?

        JJJ 1 Reply Last reply Reply Quote 0
        • JJJ
          JJ @sibtcha
          last edited by JJ

          @sibtcha Hi Sibtcha,
          I haven't tried using a thermocouple with the M5Stack..... I don't think Skelstar has been here in a while.... Perhaps post your code... someone may notice a problem.

          1 Reply Last reply Reply Quote 0
          • S
            sibtcha
            last edited by

            @JimiT You're right. Here is my code and the result when M5 lib is included or not

            #include <Adafruit_MAX31855.h>
            //#include <M5Stack.h>
            
            // Example creating a thermocouple instance with software SPI on any three digital IO pins.
            #define MAXDO   19
            #define MAXCS   17
            #define MAXCLK  18
            
            Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
            
            void setup() {
              //M5.begin();
              Serial.begin(115200);
              Serial.print("Internal Temp = ");
              Serial.println(thermocouple.readInternal());
              
              while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
              
              Serial.println("MAX31855 test");
            
              // wait for MAX chip to stabilize
              delay(2000);
            }
            
            void loop() {
            
              // basic readout test, just print the current temp
              Serial.print("Internal Temp = ");
              Serial.println(thermocouple.readInternal());
              
              double c = thermocouple.readCelsius();
              if (isnan(c)) {
                Serial.println("Something wrong with thermocouple!");
              } else {
                Serial.print("C = ");
                Serial.println(c);
              }
             
              delay(1000);
            
              //M5.update();
            }
            

            And the result is

            Internal Temp = 32.50
            C = 17.25
            Internal Temp = 32.56
            C = 15.25
            Internal Temp = 32.56
            C = 18.25
            Internal Temp = 32.50
            C = 16.50
            Internal Temp = 32.56
            C = 17.25
            Internal Temp = 32.63
            C = 18.50
            Internal Temp = 32.56
            C = 18.25
            Internal Temp = 32.63
            

            But if I uncomment the line 3 lines to include M5 to the projet, the result is:

            Internal Temp = 0.00
            C = 0.00
            Internal Temp = 0.00
            C = 0.00
            Internal Temp = 0.00
            C = 0.00
            Internal Temp = 0.00
            C = 0.00
            Internal Temp = 0.00
            C = 0.00
            Internal Temp = 0.00
            C = 0.00
            

            I think is something about the SPI, but I'm not sure. I try to use other pins but unfortunately unsucessfully

            JJJ 1 Reply Last reply Reply Quote 0
            • JJJ
              JJ @sibtcha
              last edited by JJ

              @sibtcha At the very top of the code it should have:

              #include <SPI.h>
              

              That file should already be on your system if you followed standard setup for the M5Stack - it should be located in:

              C:\Users\YOUR USER NAME\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src

              Perhaps give that a try with the M5Stack commands enabled.

              Further tweaks may be required....

              1 Reply Last reply Reply Quote 0
              • S
                sibtcha
                last edited by

                Thank you @JimiT

                Indeed I forgot to include the SPI lib, but unfortunetaly the result isn't good. The values jump between positive and negastives and I do nothing.

                Internal Temp = 68.12
                Something wrong with thermocouple!
                Internal Temp = -111.87
                Something wrong with thermocouple!
                Internal Temp = 33.75
                Something wrong with thermocouple!
                Internal Temp = -120.00
                C = 1548.50
                Internal Temp = 32.63
                C = 530.00
                Internal Temp = 33.56
                Something wrong with thermocouple!
                
                1 Reply Last reply Reply Quote 0
                • reaper7R
                  reaper7
                  last edited by reaper7

                  @sibtcha , try to initialize Adafruit_MAX31855 library only with CS pin:

                  Adafruit_MAX31855 thermocouple(MAXCS);
                  

                  as You see at library source: https://github.com/adafruit/Adafruit-MAX31855-library/blob/master/Adafruit_MAX31855.cpp
                  when You declare SPI CLK line then library try read this device by software SPI implementation!

                  also You are forgot thermocouple.begin();

                  MY GITHUB: https://github.com/reaper7/

                  1 Reply Last reply Reply Quote 0
                  • S
                    sibtcha
                    last edited by

                    @reaper7 在 SPI clash between LCD and nRF24L01 中说:

                    thermocouple.begin();

                    Thank you for the reply.

                    Wich pin do you think I have to use for the CS ? No matter wich one ? In the MAX31855 I've 5 pins

                    • GND
                    • VCC (3v3)
                    • DO
                    • CS
                    • CLK

                    If I only initialize the object with the CS, what must I do with the other pins (DO and CLK) ?

                    Sorry for this question, but I'm a begginer

                    1 Reply Last reply Reply Quote 0
                    • reaper7R
                      reaper7
                      last edited by reaper7

                      Phisically connect Your MAX to SPI lines and CS leave connected as is!
                      M5Stack pinout:
                      https://github.com/m5stack/M5Stack#pinout

                      MAX DO -> M5Stack MISO (GPIO19)
                      MAX CS -> M5Stack GPIO17
                      MAX CLK -> M5Stack CLK (GPIO18)

                      Looks like You have connection prepared corectly...

                      Change only Your sketch like this:

                      #include <SPI.h>
                      #include <Adafruit_MAX31855.h>
                      //#include <M5Stack.h>
                      
                      // Example creating a thermocouple instance with software SPI on any three digital IO pins.
                      //#define MAXDO   19
                      //#define MAXCLK  18
                      #define MAXCS   17
                      
                      Adafruit_MAX31855 thermocouple(MAXCS);
                      
                      void setup() {
                        //M5.begin();
                        Serial.begin(115200);
                        Serial.print("Internal Temp = ");
                        Serial.println(thermocouple.readInternal());
                        
                        while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
                        
                        Serial.println("MAX31855 test");
                      
                        thermocouple.begin();
                      
                        // wait for MAX chip to stabilize
                        delay(2000);
                      }
                      
                      void loop() {
                      
                        // basic readout test, just print the current temp
                        Serial.print("Internal Temp = ");
                        Serial.println(thermocouple.readInternal());
                        
                        double c = thermocouple.readCelsius();
                        if (isnan(c)) {
                          Serial.println("Something wrong with thermocouple!");
                        } else {
                          Serial.print("C = ");
                          Serial.println(c);
                        }
                       
                        delay(1000);
                      
                        //M5.update();
                      }
                      

                      MY GITHUB: https://github.com/reaper7/

                      1 Reply Last reply Reply Quote 1
                      • S
                        sibtcha
                        last edited by

                        Hello,

                        thank you for your reply. I'v tried to only use the CS pin and it works, but... yes, there is always a but :-) the results are not very accurate. From the moment a set a brightness in the screen, the values of the temperatures grows.

                        I try to read the temp in a separate task, but it didn't change anything.

                        Here is my code

                        #include "Adafruit_MAX31855.h"
                        #include <SPI.h>
                        #include <M5Stack.h>
                        
                        // Example creating a thermocouple instance with software SPI on any three
                        // digital IO pins.
                        #define MAXCS   17
                        
                        Adafruit_MAX31855 thermocouple(MAXCS);
                        
                        void task1(void * pvParameters) {
                          for (;;) {
                            float avg = 0;
                        
                            /* Read nbReadToAvg times to make an average of the temp */
                            for (int i = 0; i < nbReadToAvg; i++) {
                              float c = thermocouple.readCelsius();
                              avg = avg + c;
                              delay(100);
                            }
                        
                            avg = avg / nbReadToAvg;
                            Serial.println(avg);
                          }
                        }
                        
                        
                        void setup() {
                        
                          Serial.begin(115200);
                          Serial.print("MOSI=");
                          Serial.println(MOSI);
                          Serial.print("MISO=");
                          Serial.println(MISO);
                          Serial.print("SCK=");
                          Serial.println(SCK);
                          Serial.print("SS=");
                          Serial.println(SS);
                        
                          thermocouple.begin();
                          
                          Serial.print("Internal Temp = ");
                          Serial.println(thermocouple.readInternal());
                        
                          while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
                        
                          Serial.println("MAX31855 Initializing ...");
                        
                          //  M5.Lcd.setTextColor(WHITE, BLACK);
                        
                          // wait for MAX chip to stabilize
                          delay(1000);
                        
                          xTaskCreatePinnedToCore(
                            task1,
                            "task1",
                            4096,
                            NULL,
                            1,
                            NULL,
                            0
                          );
                        
                          Serial.println("M5 begin without LCD");
                          M5.begin(false, false);
                          delay(10000);
                          Serial.println("LCD Start");
                          M5.Lcd.begin();
                          for(int j=0;j<100;j++) {
                            //Serial.printf("Brigthness=%d\n", j);
                            M5.Lcd.setBrightness(j);
                            delay(200);
                          }
                          //delay(10000);
                          Serial.println("LCD Shutdown set Brightness to 20");
                          M5.Lcd.setBrightness(10);
                          //M5.Lcd.sleep();
                          M5.Lcd.setTextSize(4);
                          M5.Lcd.print("test");
                          M5.update();
                        }
                        
                        void loop() {
                        
                        }
                        

                        And here is the result :

                        20.27
                        20.50
                        20.35
                        20.45
                        20.27
                        18.52
                        20.12
                        20.58
                        20.42
                        LCD Start
                        20.27
                        18.60
                        21.55
                        22.73
                        21.58
                        21.77
                        21.98
                        20.87
                        21.40
                        22.40
                        21.65
                        23.60
                        23.40
                        24.02
                        24.48
                        24.62
                        24.55
                        29.67
                        26.83
                        25.52
                        29.15
                        LCD Shutdown set Brightness to 20
                        23.48
                        22.27
                        22.15
                        21.50
                        22.92
                        20.50
                        21.67
                        22.60
                        21.92
                        22.12
                        22.42
                        

                        Why can see that between the line LCD start and the LCD shutdown, the temperature grows and that why the brightness of the screen is increasing. After the line "LCD Shutdown" the brightness is set to 20 and the value are higher that the values at the beginning but they don't moved.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post