Go Down

Topic: Neopixel LED flash problem with MAX6675 thermal couple (Read 90 times) previous topic - next topic

emersonsh

Dear folk,
I met a problem when I use together "Neopixel LED ring" & "MAX6675 thermal module". I connect MAX6675 to my Arduino mega pin: 52(SCK), 53(SS), 50(SO). And Neopixel LED to D17. Every time  when the program read temperature value through SPI from MAX6675, the LED will be truned off for a very short period. I tried to move LED control pin to D13 but not work. Can anyone help me to check where does wrong? It looks like a timer conflict. But I have no idea how to solve this.



#include <Adafruit_NeoPixel.h>
#define NUMPIXELS 24
#define PIN_LED  17
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN_LED, NEO_GRB + NEO_KHZ800);


#include <max6675.h>
MAX6675 ktc(52, 53, 50);

int kt=0; //thermal couple read peroid
int Lnum=8; //default LED

void setup()
{
  Serial.begin(9600); //Barcode module
  pixels.begin();

}

void loop()
{
   lightoff();
   kt=kt+1;
   if(kt>=200)
   {
   Serial.print("Deg C = ");
   Serial.print(ktc.readCelsius());
   Serial.print("\t Deg F = ");
   Serial.println(ktc.readFahrenheit());
   kt=0;
   }
   
   pixels.setPixelColor(Lnum, pixels.Color(50,50,50));

   pixels.show();
}


void colorSet(uint32_t c)
{
  for (uint16_t i = 0; i < pixels.numPixels(); i++)
  {
    pixels.setPixelColor(i, c);
   }
  pixels.show();
}


void lightoff()
{
  colorSet(pixels.Color(0,0,0));
}

pylon

First of all: you forgot the code tags! Please edit your post and add them!

Quote
Every time  when the program read temperature value through SPI from MAX6675, the LED will be truned off for a very short period.
This is exactly what you code does. It turns off all LED, reads the value and then turns on the LEDs again. What did you expect?

The library you're using is bitbanging the SPI interface instead of using the hardware for it. And it does this very, very slowly.

emersonsh

Thanks pylon. Actually, my code is very complicate and the "light off" is used to reset current LED setting and make the new LED setting available. Since I have 5 sensors in my circuit. I need to switch LED timely. I did not show all detail code here as it is too complicate.

In my code the loop should runs extremely fast as there is no any delay or wait. So supposedly the light off is not visible. But after I add the MAX6675 code, it becomes very slow now which makes LED light off become a problem.

However, you are right! Maybe I should move the light off line behind the temperature reading and see if this gives defference.

Do you know if there is any other MAX6675 library can run faster?

pylon

Quote
Do you know if there is any other MAX6675 library can run faster?
No, but changing it to use the hardware SPI shouldn't be that difficult.

emersonsh

Thanks pylon! I found root cause! I use "Light off" to reset all LED but it should not show the result immediately. So I should remove "pixels.show()" during "void colorSet(uint32_t c)". The problem solved now!

Correct code:



#include <Adafruit_NeoPixel.h>
#define NUMPIXELS 24
#define PIN_LED  17
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN_LED, NEO_GRB + NEO_KHZ800);


#include <max6675.h>
MAX6675 ktc(52, 53, 50);

int kt=0; //thermal couple read peroid
int Lnum=8; //default LED

void setup()
{
  Serial.begin(9600); //Barcode module
  pixels.begin();

}

void loop()
{
   lightoff();
   kt=kt+1;
   if(kt>=200)
   {
   Serial.print("Deg C = ");
   Serial.print(ktc.readCelsius());
   Serial.print("\t Deg F = ");
   Serial.println(ktc.readFahrenheit());
   kt=0;
   }
   
   pixels.setPixelColor(Lnum, pixels.Color(50,50,50));

   pixels.show();
}


void colorSet(uint32_t c)
{
  for (uint16_t i = 0; i < pixels.numPixels(); i++)
  {
    pixels.setPixelColor(i, c);
   }
  //pixels.show(); //this line should be removed
}


void lightoff()
{
  colorSet(pixels.Color(0,0,0));
}

Go Up