ich bin vor einiger Zeit schon auf das richtig interessante und gute Framework hier gestoßen. Ich selbst nutze es gerade um eine alten RC Playmobil Lok - die gelbe Rangierlok - wieder fahrtüchtig zu machen.
Die alte Elektronik hat leider den Geist aufgegeben.
Mein Plan war die Elektronik durch einen ESP32 zu ersetzen und mit allen Features und evtl. noch etwas mehr, wieder auszustatten. Die Anbindung an die Z21 und den Motor an den ESP32 über die H-Bridge anzuschließen und zu steuern war wirklich einfach.
Jetzt bin ich dabei die Beleuchtung einzubauen. Dazu habe ich mir ein 100er Pack WS2812b geholt.
Zur Ansteuerung hab ich das Adafruit Neopixel Framework mit ins Projekt verlinkt und referenziere es über eine neue Action:
ActionLedWS2812b.cpp
Code: Alles auswählen
#include <Arduino.h>
#include <stdlib.h>
#include "ActionLedWS2812b.h"
#include "Logger.h"
#include "Utils.h"
#define num_leds
Adafruit_NeoPixel pixels;
ActionLedWS2812b::ActionLedWS2812b(Pin *g, int lights)
{
gpio = g;
Logger::getInstance()->addToLog(LogLevel::INFO, "Starting ActionLedWS2812b " + g->toString());
GPIOobj.pinMode(gpio, OUTPUT, "LED");
numlights = lights;
//Logger::getInstance()->addToLog(LogLevel::INFO, "Number of lights " + String(lights));
pixels = Adafruit_NeoPixel(numlights, gpio->getPin());
pixels.begin();
pixels.show();
}
ActionLedWS2812b::~ActionLedWS2812b()
{
}
String ActionLedWS2812b::getHTMLController(String urlprefix)
{
String message = F("<div class=\"row\">");
message += F(" <div class=\"column column-10\">LEDWS2812B</div>");
message += F("<div class=\"column column-90\"><a class=\"button button-black\" href=\"");
message += urlprefix;
message += F("value=0");
message += F("\">💡Aus</a>");
message += F(" <a class=\"button button-white\" href=\"");
message += urlprefix;
message += F("value=1");
message += F("\">An</a></div>");
message += "</div>";
return message;
}
void ActionLedWS2812b::setSettings(String key, String value)
{
int status = value.toInt();
setSettings(status);
}
void ActionLedWS2812b::setSettings(int status)
{
if (currentStatus == status)
{
return;
}
Logger::getInstance()->addToLog(LogLevel::TRACE, "Led WS" + gpio->toString() + " changed to " + String(status));
if (status == 0)
{
pixels.fill(pixels.Color(255, 255, 255));
pixels.show();
Logger::getInstance()->addToLog(LogLevel::TRACE, "Led setPixelColor 0");
currentStatus = 0;
}
else if (status == 1)
{
pixels.fill(pixels.Color(255, 0, 0));
pixels.show();
Logger::getInstance()->addToLog(LogLevel::TRACE, "Led setPixelColor 1");
currentStatus = 1;
}
}
//int ActionLed::loop() {
// return 3000 + ; // TODO Pattern
//}
void ActionLedWS2812b::setPattern(const char *patternString)
{
// for (int i = 0; patternString[i] != 0; i++) {
// Logger::getInstance()->addToLog("GPIO " + String(patternString[i]) + " " + String(Utils::hextoint(patternString[i])));
// }
}
Code: Alles auswählen
{
"id":"out0",
"m":"ledWS2812b",
"numlights":"2",
"gpio":"IO13"
}
Mit der entsprechenden funconoff lässt es sich auch schon wunderbar schalten und wird jetzt nach Zustand rot oder weiß.
Damit das natürlich nicht per Knopf geschalten werden muss, habe ich mir die Connectors angesehen. Genauer gesagt die ConnectorsLights.cpp und .h
Die habe ich kopiert und angepasst:
Code: Alles auswählen
/*
* ConnectorWS2812b.cpp
*
* Created on: 23.07.2017
* Author: sven
*/
#include "Utils.h"
#include "ConnectorWS2812b.h"
#include "Consts.h"
ConnectorWS2812b::ConnectorWS2812b(ISettings *x, int locoaddr, int fkey, int richtung)
{
addAction(x);
direction = richtung;
addr = locoaddr;
func = fkey;
currentDirection = Consts::SPEED_FORWARD;
currentFStatus = 0;
r = new requestInfo();
r->art = requestInfo::ART::LOCO;
r->id = locoaddr;
}
ConnectorWS2812b::~ConnectorWS2812b()
{
}
void ConnectorWS2812b::DCCSpeed(int id, int speed, int direction, int source)
{
if (id != this->addr)
{
return;
}
currentDirection = direction;
update();
}
void ConnectorWS2812b::DCCFunc(int id, unsigned long int newvalue, int source)
{
if (id != this->addr)
{
return;
}
currentFStatus = newvalue;
update();
}
void ConnectorWS2812b::update()
{
int status = (currentDirection == direction && bit_is_set(currentFStatus, func)) ? 1 : 0;
send("status", String(status));
}
Allerdings kommt damit, sobald eine Fahrtrichtung gewählt ist folgender Fehler:
Code: Alles auswählen
[PIPE] Led WSIO13/13 changed to 0
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4017b316 PS : 0x00060233 A0 : 0x8017b438 A1 : 0x3ffb1b70
A2 : 0x0000002f A3 : 0x00000001 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00060620 A7 : 0x00000000 A8 : 0x00000001 A9 : 0x0000ffff
A10 : 0x3ffd1c0c A11 : 0xbaad5678 A12 : 0x3ffd43f4 A13 : 0x00000001
A14 : 0x00060623 A15 : 0x00000000 SAR : 0x00000013 EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000ffff LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x4017b316:0x3ffb1b70 0x4017b435:0x3ffb1b90 0x4017b66d:0x3ffb1bd0 0x4017b897:0x3ffb1c10 0x4017e093:0x3ffb1c40 0x4017e3aa:0x3ffb1c70 0x400fdf55:0x3ffb1ca0 0x400fde1c:0x3ffb1d00 0x400d2bbb:0x3ffb1d20 0x400d2af5:0x3ffb1d80 0x400e3349:0x3ffb1da0 0x400e2e13:0x3ffb1e00 0x400e2ed2:0x3ffb1e40 0x400e6c51:0x3ffb1e60 0x400fadad:0x3ffb1eb0 0x400fb191:0x3ffb1ed0 0x400d8fa9:0x3ffb1f20 0x400d9071:0x3ffb1f40 0x400e4a0b:0x3ffb1f70 0x400fd2d9:0x3ffb1f90 0x4010c3ad:0x3ffb1fb0 0x4008b60a:0x3ffb1fd0
#0 0x4017b316:0x3ffb1b70 in find_desc_for_source at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/intr_alloc.c:784
#1 0x4017b435:0x3ffb1b90 in get_available_int at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/intr_alloc.c:784
#2 0x4017b66d:0x3ffb1bd0 in esp_intr_alloc_intrstatus at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/intr_alloc.c:784
#3 0x4017b897:0x3ffb1c10 in esp_intr_alloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/intr_alloc.c:784
#4 0x4017e093:0x3ffb1c40 in rmt_isr_register at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/rmt.c:876
#5 0x4017e3aa:0x3ffb1c70 in rmt_driver_install at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/rmt.c:876
#6 0x400fdf55:0x3ffb1ca0 in espShow at .pio\libdeps\esp32dev\Adafruit NeoPixel/esp.c:117
#7 0x400fde1c:0x3ffb1d00 in Adafruit_NeoPixel::show() at .pio\libdeps\esp32dev\Adafruit NeoPixel/Adafruit_NeoPixel.cpp:2315
#8 0x400d2bbb:0x3ffb1d20 in ActionLedWS2812b::setSettings(int) at decoder/ActionLedWS2812b.cpp:81
#9 0x400d2af5:0x3ffb1d80 in ActionLedWS2812b::setSettings(String, String) at decoder/ActionLedWS2812b.cpp:65
#10 0x400e3349:0x3ffb1da0 in Connectors::send(String, String) at decoder/Connectors.cpp:40 (discriminator 2)
#11 0x400e2e13:0x3ffb1e00 in ConnectorWS2812b::update() at decoder/ConnectorWS2812b.cpp:68 (discriminator 3)
#12 0x400e2ed2:0x3ffb1e40 in ConnectorWS2812b::DCCSpeed(int, int, int, int) at decoder/ConnectorWS2812b.cpp:38
#13 0x400e6c51:0x3ffb1e60 in Controller::notifyDCCSpeed(int, int, int, int) at .pio/libdeps/esp32dev/LinkedList/LinkedList.h:334
#14 0x400fadad:0x3ffb1eb0 in Z21Format::handleDCCSpeed(unsigned int, unsigned char*) at decoder/Z21Format.cpp:388
#15 0x400fb191:0x3ffb1ed0 in Z21Format::parseServer2Client(unsigned char*, int) at decoder/Z21Format.cpp:388
#16 0x400d8fa9:0x3ffb1f20 in CmdReceiverZ21Wlan::doReceive() at decoder/CmdReceiverZ21Wlan.cpp:99
#17 0x400d9071:0x3ffb1f40 in CmdReceiverZ21Wlan::loop() at decoder/CmdReceiverZ21Wlan.cpp:54
#18 0x400e4a0b:0x3ffb1f70 in Controller::doLoops() at .pio/libdeps/esp32dev/LinkedList/LinkedList.h:334
#19 0x400fd2d9:0x3ffb1f90 in loop() at decoder/decoder.cpp:380
#20 0x4010c3ad:0x3ffb1fb0 in loopTask(void*) at C:\Users\fk\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
#21 0x4008b60a:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
Code: Alles auswählen
uru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400e31bd PS : 0x00060c30 A0 : 0x800e2d51 A1 : 0x3ffb1da0
A2 : 0x3ffd1d20 A3 : 0x3ffb1e10 A4 : 0x3ffb1e04 A5 : 0x00000000
A6 : 0x3ffd1d50 A7 : 0x3ffb1dac A8 : 0x800e31bd A9 : 0x3ffb1d80
A10 : 0xffffffff A11 : 0x00000000 A12 : 0x3ffb1e04 A13 : 0x3ffc7cbc
A14 : 0x3ffb844c A15 : 0xff000000 SAR : 0x00000018 EXCCAUSE: 0x0000001c
EXCVADDR: 0xffffffff LBEG : 0x4000c28c LEND : 0x4000c296 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x400e31bd:0x3ffb1da0 0x400e2d4e:0x3ffb1e00 0x400e2da6:0x3ffb1e40 0x400e6b49:0x3ffb1e60 0x400faca5:0x3ffb1eb0 0x400fb089:0x3ffb1ed0 0x400d8f81:0x3ffb1f20 0x400d9049:0x3ffb1f40 0x400e4903:0x3ffb1f70 0x400fd1d1:0x3ffb1f90 0x4010c2a5:0x3ffb1fb0 0x4008b60a:0x3ffb1fd0
#0 0x400e31bd:0x3ffb1da0 in Connectors::send(String, String) at decoder/Connectors.cpp:39 (discriminator 8)
#1 0x400e2d4e:0x3ffb1e00 in ConnectorWS2812b::update() at decoder/ConnectorWS2812b.cpp:56 (discriminator 2)
#2 0x400e2da6:0x3ffb1e40 in ConnectorWS2812b::DCCSpeed(int, int, int, int) at decoder/ConnectorWS2812b.cpp:39
#3 0x400e6b49:0x3ffb1e60 in Controller::notifyDCCSpeed(int, int, int, int) at .pio/libdeps/esp32dev/LinkedList/LinkedList.h:334
#4 0x400faca5:0x3ffb1eb0 in Z21Format::handleDCCSpeed(unsigned int, unsigned char*) at decoder/Z21Format.cpp:388
#5 0x400fb089:0x3ffb1ed0 in Z21Format::parseServer2Client(unsigned char*, int) at decoder/Z21Format.cpp:388
#6 0x400d8f81:0x3ffb1f20 in CmdReceiverZ21Wlan::doReceive() at decoder/CmdReceiverZ21Wlan.cpp:99
#7 0x400d9049:0x3ffb1f40 in CmdReceiverZ21Wlan::loop() at decoder/CmdReceiverZ21Wlan.cpp:54
#8 0x400e4903:0x3ffb1f70 in Controller::doLoops() at .pio/libdeps/esp32dev/LinkedList/LinkedList.h:334
#9 0x400fd1d1:0x3ffb1f90 in loop() at decoder/decoder.cpp:380
#10 0x4010c2a5:0x3ffb1fb0 in loopTask(void*) at C:\Users\fk\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
#11 0x4008b60a:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
Hat hier jemand evtl. eine Idee wo ich suchen könnte?
Vielen Dank!
Steinlaus