ESP32-S2 Saola Making the RGB Work

Introduction: ESP32-S2 Saola Making the RGB Work

About: Long time software developer having fun with hardware!

I could not find any example code on how to access the Neo Pixel on my new ESP32-S2 so I decided to write some and share for anyone else who would like to do the same.

Step 1: Here Is Some Code to Get Your NeoPixel on Your ESP32-S2 Cycling.

First you need the ESP32 S2 devices installed in your Arduino IDE, downloaded here:

https://github.com/espressif/arduino-esp32/tree/es...

You will need the NeoPixel Library from Adafruit to get this sketch to work.

https://github.com/adafruit/Adafruit_NeoPixel

Finally just run the code attached.

//
//Sample code to control the single NeoPixel on the ESP32-S2 Saola
//
#include <Adafruit_NeoPixel.h>

// On the ESP32S2 SAOLA GPIO is the NeoPixel.
#define PIN        18 

//Single NeoPixel
Adafruit_NeoPixel pixels(1, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 25 // Time (in milliseconds) to pause between color change

void setup() {

  //This pixel is just way to bright, lower it to 10 so it does not hurt to look at.
  pixels.setBrightness(10);
  pixels.begin(); // INITIALIZE NeoPixel (REQUIRED)
}

// Simple function to return a color in the rainbow
// Input a value 0 to 255 to get a color value.
uint32_t Wheel(byte WheelPos)
{
    //Assume the wheel value is less than 85, if so Green value is 0
    uint32_t returnColor = Adafruit_NeoPixel::Color((byte)(255 - (WheelPos * 3)), 0, (byte)(WheelPos * 3));

    //If we are greater than 170 Red value is 0
    if (WheelPos > 84 && WheelPos < 170)
    {
        WheelPos -= 85;
        returnColor = Adafruit_NeoPixel::Color(0, (byte)(WheelPos * 3), (byte)(255 - WheelPos * 3));
    }
    //Finally above 170 and Blue value is 0
    else if (WheelPos >= 170)
    {
        WheelPos -= 170;
        returnColor = Adafruit_NeoPixel::Color((byte)(WheelPos * 3), (byte)(255 - WheelPos * 3), 0);
    }

    return returnColor;
}

//Counter to run from 0-255 to cycle the colors of the rainbow.
int colorCount = 0;
void loop() {

    //Set the new color on the pixel.
    pixels.setPixelColor(0, Wheel(colorCount++));

    // Send the updated pixel colors to the hardware.
    pixels.show();   

    //Cycle the colors at the end.
    if (colorCount > 255)
        colorCount = 0;

    // Pause before next pass through loop
    delay(DELAYVAL); 
}

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge
    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge

    8 Comments

    0
    eduarte12
    eduarte12

    8 months ago on Step 1

    After looking all over to find a working example I finally found this. Luckily I had already loaded the ESP32S2 board to the Arduino IDE so it was much easier to get this working. Thanks JeffL117!

    0
    JeffL117
    JeffL117

    Reply 8 months ago

    Your welcome, happy to help.

    0
    docslip70
    docslip70

    1 year ago

    Dear Jeff. Thank for your work using the Saola esp32-2s.
    I am attempting to upload any sketch to this unit and I'm greeted be a header error. I have selected node32s for a suitable board. I want to use whatever you selected because it obviously works.
    So, what board should I select as there is no Saola in the list of esp32 choices.
    Thank you in advance.
    Bill Phillips
    retired

    0
    docslip70
    docslip70

    Reply 1 year ago

    Now Sunday, August 16th, 2020:
    before you reply to my last reporting to you, I have followed the instructions from github , for windows, to install the library. It ends prematurely. I then watched a couple YouTube video's on the topic of installing the -S2 and trying to follow english subtitles with the guy's moving their mouse to fast over text too small .. well I just wished your instructable on the S2-- Saola had included the Arduino IDE setup. Seems that Arduino has not completed their official support for the S2.
    Thank yo for listening..back to the esp8266 for now.
    Bill Phillips
    Surrey, BC, Canada.

    0
    BobW14
    BobW14

    Reply 11 months ago

    I agree with those words , I have tried for weeks to make it work and no luck.
    Need a much better explaniation of how to install this so Arduino IDE can be used.

    0
    docslip70
    docslip70

    Reply 1 year ago

    Thank you. I did select the esp32-s2 branch, downloaded the zip file.
    The IDE reported 'not a valid library'.So I unzipped it and manually copied it to the sketch directory libraries. This time the complaint was:
    Invalid library found in C:\Users\TwWork 3\Documents\Arduino\libraries\arduino-esp32-esp32s2: no headers files (.h) found in C:\Users\TwWork 3\Documents\Arduino\libraries\arduino-esp32-esp32s2
    I noticed too, that the library contained a tools folder containing .exe's.
    Not sure what to do now.
    Regards,
    Bill Phillips

    0
    DrJohnM61
    DrJohnM61

    1 year ago on Step 1

    Hi, Thank you for the project. I have tested this on my ESP32S2 dev board and it works fine, however, if I try and use the setpixelcolor function after initialising a wifi connection, the LED does not show the correct color or intensity. The following example show the LED in red, green, blue and white and then does a wifi connect. It the attempt to do the same color display but it goes wrong. Apparently something to do with the following:

    https://www.eevblog.com/forum/beginners/esp12f-wit...

    Suggestion is to use the FastLED library (but I have not been able to get that to work).

    #include <Adafruit_NeoPixel.h>
    #include <WiFi.h>
    #include <WiFiMulti.h>
    // On the ESP32S2 SAOLA GPIO is the NeoPixel.
    #define PIN 18
    Adafruit_NeoPixel pixels(1, PIN, NEO_GRB + NEO_KHZ800); //Single NeoPixel
    WiFiMulti WiFiMulti;
    // Simple function to set a color based on RGB values
    void ShowColor(int r, int g, int b) {
    pixels.setPixelColor(0, r, g, b); //Set the new color on the pixel.
    pixels.show(); // Send the updated pixel colors to the hardware.
    delay(1000); // Pause before next pass through loop
    }
    void setup()
    {
    Serial.begin(115200);
    delay(10);
    Serial.println("Setting brightness");
    pixels.setBrightness(10);
    pixels.begin(); // INITIALIZE NeoPixel (REQUIRED)
    ShowColor(0, 0, 0);
    ShowColor(255, 0, 0);
    ShowColor(0, 255, 0);
    ShowColor(0, 0, 255);
    ShowColor(255, 255, 255);
    pixels.clear();
    pixels.show();
    // We start by connecting to a WiFi network
    WiFiMulti.addAP("SSID", "password");
    Serial.println();
    Serial.println();
    Serial.print("Waiting for WiFi... ");
    while (WiFiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    }
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    ShowColor(255,0,0);
    ShowColor(0,255,0);
    ShowColor(0,0,255);
    ShowColor(255,255,255);
    ShowColor(0,0,0);
    }
    void loop() {
    }

    Any help appreciated.