ESP32 Touch not working with Neopixels

kian79
Posts: 30
Joined: Thu Jun 13, 2019 3:27 am

ESP32 Touch not working with Neopixels

Postby kian79 » Mon Feb 14, 2022 1:04 pm

Hi all,

I am working on project where I want to turn on/off and cycle through different colour on the Neopixel (WS2812) LED strip using capacitive touch on the ESP32.

I have standalone code for touch detection working and I also have standalone code working for controlling the LED strip. However when I try to combine both, it doesn't work anymore. I can still detect touch, but I am no longer able to control the LEDs. I have tried using different libraries (eg. FastLED, Adafruit Neopixel and NeoPixelBus) but none seems to work together with the touch detection on the ESP32.

Here is my code below. It works well when I comment out the line Serial.println(touchRead(TOUCH));, but if I uncomment this line and call the touchRead function, my LED no longer changes color. It still prints the serial messages in the loop. Just that the LED strip no longer respond.

Any suggestions on how I can overcome this problem? Someone suggested using the NeoPixelBus library that uses non bit bang method to control the LEDs, I tried, but it didn't work :(

Code: Select all

#include <NeoPixelBus.h>

#define LED_STRIP_PIN 32
#define LED_STRIP_COUNT 20

#define TOUCH         2

#define FEATURE NeoGrbFeature
#define METHOD NeoEsp32I2s1800KbpsMethod
#define colorSaturation 128

RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);

NeoPixelBus<FEATURE, METHOD> strip(LED_STRIP_COUNT, LED_STRIP_PIN);

int i;

void setup() 
{
  Serial.begin(115200);

  // Setup LED
  strip.Begin();
  strip.Show();

  Serial.println("On Green LED");
  delay(2000);
  for(i=0;i<LED_STRIP_COUNT;i++)
  {
    strip.SetPixelColor(i, green);
  }  
  strip.Show();
  delay(2000);

  Serial.println("On Red LED");  
  for(i=0;i<LED_STRIP_COUNT;i++)
  {
    strip.SetPixelColor(i, red); 
  }  
  strip.Show();
  delay(2000);

  //Serial.println(touchRead(TOUCH));
  
  //touchAttachInterrupt(TOUCH, gotTouch, touch_threshold);

void loop() 
{

  Serial.println("On Green LED");
  for(i=0;i<LED_STRIP_COUNT;i++)
  {
    strip.SetPixelColor(i, green);
  }  
  strip.Show();
  delay(2000);

  Serial.println("On Red LED");  
  for(i=0;i<LED_STRIP_COUNT;i++)
  {
    strip.SetPixelColor(i, red); 
  }  
  strip.Show();
  delay(2000);

}


Who is online

Users browsing this forum: benskiskull, Google [Bot] and 46 guests