• Уважаемые посетители сайта esp8266.ru!
    Мы отказались от размещения рекламы на страницах форума для большего комфорта пользователей.
    Вы можете оказать посильную поддержку администрации форума. Данные средства пойдут на оплату услуг облачных провайдеров для сайта esp8266.ru
  • Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

Запуск WS2812 на ESP (nodeMCU)

vasai

New member
Добрый день. Пробую запустить RGB диодную ленту на ESP, через Lua так и не смог разобраться. C помощью ардуино, и его библиотек очень нравится возможность настройки диодной ленты. Хотелось бы реализовать такое же, но используя платформу ESP. пробовал стандартный пример из библиотеки Adafruit_NeoPixel ничего не заработало в скетче указываю Пин 2, в ESP подключаю к D4 (GPIO2) . Точно так же с примером из библиотеки NeoPixelBus by Makuna, результат опять же никакой.
ESP прошита прошивкой NodeMCU.
Вот пример используемый в тесте:
CSS:
#include <NeoPixelBus.h>

const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure
const uint8_t PixelPin = 2;  // make sure to set this to the correct pin, ignored for Esp8266

#define colorSaturation 128

// three element pixels, in different order and speeds
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin);

// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. 
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead

// You can also use one of these for Esp8266,
// each having their own restrictions
//
// These two are the same as above as the DMA method is the default
// NOTE: These will ignore the PIN and use GPI03 pin
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> strip(PixelCount, PixelPin);

// Uart method is good for the Esp-01 or other pin restricted modules
// NOTE: These will ignore the PIN and use GPI02 pin
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin);

// The bitbang method is really only good if you are not using WiFi features of the ESP
// It works with all but pin 16
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang400KbpsMethod> strip(PixelCount, PixelPin);

// four element pixels, RGBW
//NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);

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

HslColor hslRed(red);
HslColor hslGreen(green);
HslColor hslBlue(blue);
HslColor hslWhite(white);
HslColor hslBlack(black);


void setup()
{
    Serial.begin(115200);
    while (!Serial); // wait for serial attach

    Serial.println();
    Serial.println("Initializing...");
    Serial.flush();

    // this resets all the neopixels to an off state
    strip.Begin();
    strip.Show();


    Serial.println();
    Serial.println("Running...");
}


void loop()
{
    delay(5000);

    Serial.println("Colors R, G, B, W...");

    // set the colors,
    // if they don't match in order, you need to use NeoGrbFeature feature
    strip.SetPixelColor(0, red);
    strip.SetPixelColor(1, green);
    strip.SetPixelColor(2, blue);
    strip.SetPixelColor(3, white);
    // the following line demonstrates rgbw color support
    // if the NeoPixels are rgbw types the following line will compile
    // if the NeoPixels are anything else, the following line will give an error
    //strip.SetPixelColor(3, RgbwColor(colorSaturation));
    strip.Show();


    delay(5000);

    Serial.println("Off ...");

    // turn off the pixels
    strip.SetPixelColor(0, black);
    strip.SetPixelColor(1, black);
    strip.SetPixelColor(2, black);
    strip.SetPixelColor(3, black);
    strip.Show();

    delay(5000);

    Serial.println("HSL Colors R, G, B, W...");

    // set the colors,
    // if they don't match in order, you may need to use NeoGrbFeature feature
    strip.SetPixelColor(0, hslRed);
    strip.SetPixelColor(1, hslGreen);
    strip.SetPixelColor(2, hslBlue);
    strip.SetPixelColor(3, hslWhite);
    strip.Show();


    delay(5000);

    Serial.println("Off again...");

    // turn off the pixels
    strip.SetPixelColor(0, hslBlack);
    strip.SetPixelColor(1, hslBlack);
    strip.SetPixelColor(2, hslBlack);
    strip.SetPixelColor(3, hslBlack);
    strip.Show();

}
 

Сергей_Ф

Moderator
Команда форума
ESP прошита прошивкой NodeMCU.
Вот пример используемый в тесте:
Вы уверены в том что написали? Как Вы на nodeMCU запускаете код от Ардуино ИДЕ? Лента прекрасно управляется из Ардуино ИДЕ с библиотекой NeoPixelBus by Makuna, только метод раскоментируйте нужный. У меня работает с NeoPixelBus<NeoGrbFeature,NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
 

vasai

New member
Вы уверены в том что написали? Как Вы на nodeMCU запускаете код от Ардуино ИДЕ? Лента прекрасно управляется из Ардуино ИДЕ с библиотекой NeoPixelBus by Makuna, только метод раскоментируйте нужный. У меня работает с NeoPixelBus<NeoGrbFeature,NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
А какая должна быть прошивка подскажите? с этой прошивкой простые скетчи типа блинк, залитые через Arduino IDE нормально работают.
 

Сергей_Ф

Moderator
Команда форума
@vasai если Вы компилируете скетч в Ардуино ИДЕ - то это и есть Ваша прошивка. Скомпилированный скетч полностью прошивку заменяет собой.
Попробуйте закоментировать метод
Код:
NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin);
и раскоментировать
Код:
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin);
(убрать // вначале)
Всё должно заработать на пине 2
 

vasai

New member
@vasai если Вы компилируете скетч в Ардуино ИДЕ - то это и есть Ваша прошивка. Скомпилированный скетч полностью прошивку заменяет собой.
Попробуйте закоментировать метод
Код:
NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin);
и раскоментировать
Код:
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin);
(убрать // вначале)
Всё должно заработать на пине 2
Да, все заработало, Спасибо Вам большое!
 
Сверху Снизу