From c6f8fdd9a2f9b95f7cd053ddbd986aca26543dd7 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Fri, 19 Jan 2024 18:44:52 -0600 Subject: [PATCH] working ethernet version --- .vscode/settings.json | 3 ++- platformio.ini | 6 +++--- src/e131.cpp | 49 ++++++++++++++++++++++--------------------- src/e131.h | 10 ++++----- src/main.cpp | 46 +++++++++++++++++++++++++--------------- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 89f6be4..d3546e1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,6 @@ "string_view": "cpp", "initializer_list": "cpp", "ranges": "cpp" - } + }, + "C_Cpp.errorSquiggles": "disabled" } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 3ae4a79..c96ffcc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,14 +9,14 @@ ; https://docs.platformio.org/page/projectconf.html [env:pico] -board = rpipicow -framework = arduino platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = pico +framework = arduino board_build.core = earlephilhower upload_port = /run/media/amelia/RPI-RP2/ monitor_speed = 115200 board_build.filesystem_size = 1m board_build.f_cpu = 133000000L -board_flags = -DWIFICC=CYW43_COUNTRY_USA +; board_flags = -DWIFICC=CYW43_COUNTRY_USA lib_deps = fastled/FastLED@^3.6.0 diff --git a/src/e131.cpp b/src/e131.cpp index 1f90856..c32ded9 100644 --- a/src/e131.cpp +++ b/src/e131.cpp @@ -30,6 +30,10 @@ const PROGMEM byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e const byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 }; #endif +Wiznet5500lwIP eth(17, SPI, 21); // 17 : cs, 21 : INTn + + + /* Constructor */ E131::E131() { #ifdef NO_DOUBLE_BUFFER @@ -191,24 +195,34 @@ int E131::beginMulticast(const char *ssid, const char *passphrase, #if defined (INT_ETHERNET) /* Unicast Ethernet Initializers */ -int E131::begin(uint8_t *mac) { +int E131::begin() { int retval = 0; if (Serial) { Serial.println(""); Serial.println(F("Requesting Address via DHCP")); - Serial.print(F("- MAC: ")); - for (int i = 0; i < 6; i++) - Serial.print(mac[i], HEX); Serial.println(""); } - - retval = Ethernet.begin(mac); - + + SPI.setRX(16); + SPI.setCS(17); + SPI.setSCK(18); + SPI.setTX(19); + //eth.setSPISpeed(30000000); + //lwipPollingPeriod(3); + if (!eth.begin()) { + Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring."); + return false; + } + while (!eth.connected()) { + Serial.print("."); + delay(500); + } + retval = eth.connected(); if (Serial) { if (retval) { - Serial.print(F("- IP Address: ")); - Serial.println(Ethernet.localIP()); + Serial.print(F("\n- IP Address: ")); + Serial.println(eth.localIP()); } else { Serial.println(F("** DHCP FAILED")); } @@ -220,31 +234,18 @@ int E131::begin(uint8_t *mac) { return retval; } -void E131::begin(uint8_t *mac, IPAddress ip, IPAddress netmask, - IPAddress gateway, IPAddress dns) { - Ethernet.begin(mac, ip, dns, gateway, netmask); - if (Serial) { - Serial.println(""); - Serial.println(F("Static Configuration")); - Serial.println(F("- MAC: ")); - for (int i = 0; i < 6; i++) - Serial.print(mac[i], HEX); - Serial.print(F("- IP Address: ")); - Serial.println(Ethernet.localIP()); - } - - initUnicast(); -} /* Multicast Ethernet Initializers */ int E131::beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n) { //TODO: Add ethernet multicast support + return -1; } void E131::beginMulticast(uint8_t *mac, uint16_t universe, IPAddress ip, IPAddress netmask, IPAddress gateway, IPAddress dns, uint8_t n) { //TODO: Add ethernet multicast support + //return -1; } #endif /****** END - Ethernet ifdef block ******/ diff --git a/src/e131.h b/src/e131.h index 4dc22d5..1cc84ae 100644 --- a/src/e131.h +++ b/src/e131.h @@ -26,13 +26,15 @@ #include "Arduino.h" /* Network interface detection. WiFi for ESP8266 and Ethernet for AVR */ -# include +//# include //# include //# include +# include # include # include # define _UDP WiFiUDP -# define INT_WIFI +# define INT_ETHERNET + #define NO_DOUBLE_BUFFER 1 /* Defaults */ @@ -179,9 +181,7 @@ class E131 { /****** START - Ethernet ifdef block ******/ #if defined (INT_ETHERNET) /* Unicast Ethernet Initializers */ - int begin(uint8_t *mac); - void begin(uint8_t *mac, - IPAddress ip, IPAddress netmask, IPAddress gateway, IPAddress dns); + int begin(); /* Multicast Ethernet Initializers */ int beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n = 1); diff --git a/src/main.cpp b/src/main.cpp index 2685f7e..5ce5c6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ // Includes -#include +//#include //#include +#include #include #include #include @@ -9,8 +10,8 @@ // User configurable -const char* ssid = "iPhone 14"; // WiFi SSID -const char* password = "givemewifi"; // WiFi Password +//const char* ssid = "iPhone 14"; // WiFi SSID +//const char* password = "givemewifi"; // WiFi Password const char* ntpserver = "pool.ntp.org"; // Address of NTP server. Example: pool.ntp.org const char* HOSTNAME = "lighttest"; @@ -18,9 +19,11 @@ const char* update_path = "/firmware"; const char* update_username = "admin"; const char* update_password = "pico-stripper"; +//Wiznet5500lwIP eth(1); + //#define DEBUG // Total LED count -#define MAX_LEDS 50 +#define MAX_LEDS 150 #define LED_TYPE WS2812B // Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4 @@ -31,7 +34,7 @@ const char* update_password = "pico-stripper"; // Define the data pin connection to each strip // Only uncomment the strips you use -#define STRIP1 28 +#define STRIP1 0 //#define STRIP2 0 //#define STRIP3 2 //#define STRIP4 3 @@ -43,7 +46,7 @@ const char* update_password = "pico-stripper"; #define RGB_ORDER RGB // define how many LEDs / zones are in each strip -int strips[LED_STRIPS] = {50}; +int strips[LED_STRIPS] = {150}; // Begin code @@ -141,13 +144,25 @@ void write_universe(int universe, uint8_t data[]) { } void setup() { - pinMode(22, OUTPUT); - digitalWrite(22, LOW); // Enable buffer output! + pinMode(20, OUTPUT); + digitalWrite(20, LOW); // reset W5500 + delay(1); + digitalWrite(20, HIGH); + SPI.setRX(16); + SPI.setCS(17); + SPI.setSCK(18); + SPI.setTX(19); + pinMode(8, OUTPUT); + digitalWrite(8, LOW); // Enable buffer output! //pinMode(0, OUTPUT); //digitalWrite(0, HIGH); Serial.begin(115200); delay(3000); PRINTLNFUNC("========= PicoLighter v1.0 Initializing ========="); + if (!e131.begin()) { + PRINTFUNC("Connection failed. Retrying."); + rp2040.reboot(); + } while (ready == 0) { delay(100); } @@ -236,17 +251,17 @@ void setup1() { #endif // Test all lights for (int i = 0; i < MAX_LEDS; i++) { - ledstrip[i] = CRGB(130, 130, 130); + ledstrip[i] = CRGB(50, 50, 50); FastLED.show(); delay(30); ledstrip[i] = CRGB(0, 0, 0); } FastLED.show(); delay(3000); - WiFi.noLowPowerMode(); - if (e131.begin(ssid, password) != WL_CONNECTED) { - PRINTFUNC("Connection failed. Retrying."); - rp2040.reboot(); + // WiFi.noLowPowerMode(); + ready = 1; + while (ready == 1) { + delay(100); } PRINTLNFUNC("Starting mDNS client."); MDNS.begin(HOSTNAME); @@ -261,10 +276,7 @@ void setup1() { PRINTFUNC(" and password "); PRINTLNFUNC(update_password); server.begin(); - ready = 1; - while (ready == 1) { - delay(100); - } + // If we get here, then WiFi is good to go PRINTFUNC("Starting NTP client."); NTP.begin(ntpserver);