Limite Arduino .... ESP 32 ?

Bonjour à tous,

Je suis en train de travailler sur un projet qui nécessite de passer d'une communication série à une communication Ethernet. L'objectif est de contrôler en temps réel des moteurs, des solénoïdes et des LEDs.

J'ai déjà développé un code fonctionnel pour contrôler des LEDs via des ESP8266.
Le voici:



/*
  UDPSendReceive.pde:
  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and received messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.

    https://github.com/kitesurfer1404/WS2812FX


*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1

#define LED_COUNT 93
#define NUMPIXELS 93
#define LED_PIN 3
#define PIN    3

// How many NeoPixels are attached to the Arduino?


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#include "SPI.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#ifndef STASSID
#define STASSID "F4IDM_2T2L"
#define STAPSK "xxxxxxxxxx"
#endif

#include <WS2812FX.h>

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int MODE, M_BR, Ba1, Pa2, Va2, Ra2, Ba2,Pa3, Va3, Ra3, Ba3, Pa4, Va4, Ra4, Ba4;

int ja1, ja2, jb1, jb2, jc1, jc2, jd1, jd2;

int val1a, val2a, val3a, val1b, val2b, val3b, val1c, val2c, val3c, val4a, val4b, val4c;

int Col1, Col2 ;


unsigned int localPort = 7778;  // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,

WiFiUDP Udp;
// Set your Static IP Address Settings
IPAddress local_IP(192, 168, 1, 102 );
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); // this is optional
IPAddress secondaryDNS(8, 8, 4, 4); // this is optional

void setup() {
  Serial.begin(115200);
  // Print feedback if the settings are not configured
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
  Serial.println("STA Failed to configure");
}
  
  WiFi.begin(STASSID, STAPSK);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    
    delay(500);
  }
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());
   
  
  Serial.printf("UDP server on port %d\n", localPort);
  Udp.begin(localPort);
  
  ws2812fx.init();
 // ws2812fx.setBrightness(2);
  ws2812fx.start();
  // segment 0 is the builtin comet effect
 // ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_THEATER_CHASE  );
pixels.begin(); // This initializes the NeoPixel library.
 // Update LED contents, to start they are all 'off'



 
}


void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    
    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    //Serial.println("Contents:");
   // Serial.println(packetBuffer);
  String   pacchetto = packetBuffer;
   // Create a new String object to be split

 
  String MODE_Int = splitString(pacchetto, ' ', 0);
  String M_BR_Int = splitString(pacchetto, ' ', 1);

 
 String a1 = splitString(pacchetto, ' ', 2);
 String a2 = splitString(pacchetto, ' ', 3);
 String a3 = splitString(pacchetto, ' ', 4);
 String a4 = splitString(pacchetto, ' ', 5);
 String a5 = splitString(pacchetto, ' ', 6);
 
 String b1 = splitString(pacchetto, ' ', 7); 
 String b2 = splitString(pacchetto, ' ', 8);
 String b3 = splitString(pacchetto, ' ', 9);
 String b4 = splitString(pacchetto, ' ', 10);
 String b5 = splitString(pacchetto, ' ', 11);

 String c1 = splitString(pacchetto, ' ', 12);
 String c2 = splitString(pacchetto, ' ', 13);
 String c3 = splitString(pacchetto, ' ', 14);
 String c4 = splitString(pacchetto, ' ', 15);
 String c5 = splitString(pacchetto, ' ', 16);

 String d1 = splitString(pacchetto, ' ', 17);
 String d2 = splitString(pacchetto, ' ', 18);
 String d3 = splitString(pacchetto, ' ', 19);
 String d4 = splitString(pacchetto, ' ', 20);
 String d5 = splitString(pacchetto, ' ', 21);

 
 String Col_1 = splitString(pacchetto, ' ', 22);
 String Col_2 = splitString(pacchetto, ' ', 23);


 ja1 = a1.toInt();
 ja2 = a2.toInt();
    val1a = a3.toInt();
    val1b = a4.toInt();
    val1c = a5.toInt();

jb1 = b1.toInt();
 jb2 = b2.toInt();
    val2a = b3.toInt();
    val2b = b4.toInt();
    val2c = b5.toInt();

jc1 = c1.toInt();
 jc2 = c2.toInt();
    val3a = c3.toInt();
    val3b = c4.toInt();
    val3c = c5.toInt();

jd1 = d1.toInt();
 jd2 = d2.toInt();
    val4a = d3.toInt();
    val4b= d4.toInt();
    val4c = d5.toInt();




MODE = MODE_Int.toInt();
M_BR = M_BR_Int.toInt();

Col1 = Col_1.toInt();
Col2 = Col_2.toInt();

 
    
if ((MODE) == 1) { 

{
       byte A;
       for (A = ja1 ; A < ja2; A++) {
          pixels.setPixelColor (A, pixels.Color ( val1a, val1b, val1c));
       }
}
{
        byte B;
       for (B = jb1 ; B < jb2; B++) {
          pixels.setPixelColor (B, pixels.Color ( val2a, val2b, val2c));
         }
      }
{
      byte C;
       for (C = jc1 ; C < jc2; C++) {
          pixels.setPixelColor (C, pixels.Color ( val3a, val3b, val3c));
         }
}   
  {    
        byte D;
        for (D = jd1 ; D < jd2; D++) {
          pixels.setPixelColor (D, val4a, val4b, val4c);
        }
      }
 
       
        
        pixels.show();   // Send the updated pixel colors to the hardware.
      
} 
     
 
    
    
      if ((MODE) == 2)  {
     if ((Col1) == 1)  {
     
 
         
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, BLUE , 20 );
          ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      
      if ((Col1) == 2 ) {
     
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, GREEN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, RED, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, WHITE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, YELLOW , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, CYAN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, MAGENTA, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, PURPLE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, ORANGE , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
          
      }
   
   
   
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();
 }



   if ((MODE) == 3)  {
   
      if ((Col1) == 1) {
         
           uint32_t colors[] = {BLUE, CYAN};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
        
          uint32_t colors[] = {GREEN, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        
          uint32_t colors[] = {RED, YELLOW};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        
           uint32_t colors[] = {MAGENTA, PURPLE};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
        
           uint32_t colors[] = {ORANGE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
           uint32_t colors[] = {WHITE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
        
          uint32_t colors[] = {PINK, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
        
          uint32_t colors[] = {BLUE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
      
 
 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, WHITE), 20);

      }
       if ((Col1) == 10) {
      
 
 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, GREEN) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, WHITE), 20);

      }
       if ((Col1) == 11) {
      
 
 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, RED), 20);

      }
       if ((Col1) == 12) {
      
 
 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, RED) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE), 20);

      }
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 4)  {
   
      if ((Col1) == 1) {
         ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, BLUE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
        ws2812fx.init();
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, GREEN  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        ws2812fx.init();
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, RED  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, CYAN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
          ws2812fx.init();
           
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, ORANGE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
          ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
          ws2812fx.init();
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, PINK  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
          ws2812fx.init();
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, PURPLE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        ws2812fx.init();
 uint32_t colors[] = {PINK, WHITE};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, MAGENTA  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 5)  {
   
      if ((Col1) == 1) {
         ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, BLUE, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
        ws2812fx.init();
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, GREEN  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        ws2812fx.init();
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, RED  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, CYAN   , 20);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
          ws2812fx.init();
           
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, ORANGE  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
          ws2812fx.init();
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
          ws2812fx.init();
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, PINK , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
          ws2812fx.init();
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, PURPLE, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, MAGENTA  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 6)  {
   
      if ((Col1) == 1) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, BLUE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
   
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, GREEN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
    
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, RED , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, CYAN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
     
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, ORANGE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
         
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, PINK , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
      
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, PURPLE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
 

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, MAGENTA , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 7)  {
   
      if ((Col1) == 1) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, BLUE , 1   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
   
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, GREEN , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
    
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, RED , 1);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, CYAN , 1 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
     
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, ORANGE , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, ULTRAWHITE , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
         
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, PINK , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
      
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, PURPLE , 1);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
 

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, MAGENTA , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

      if ((Col1) == 10) {
 

  ws2812fx.setSegment(0, 0, (LED_COUNT/2) - 1, FX_MODE_LARSON_SCANNER, CYAN , 1  );
  ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_LARSON_SCANNER, CYAN, 1, reverse);
      }
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 8)  {
   
      if ((Col1) == 1) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, BLUE , 1   );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
   
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, GREEN , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
    
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, RED , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
     
      if ((Col1) == 4) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, CYAN , 1 );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
     
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, ORANGE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, ULTRAWHITE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
         
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, PINK , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
      
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, PURPLE , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
 

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, MAGENTA , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

      
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 9)  {
   
      if ((Col1) == 1) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, BLUE , 1   );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
   
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, GREEN , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
    
       
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, RED , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
     
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, CYAN , 1 );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
     
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, ORANGE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, ULTRAWHITE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
         
         
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, PINK , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
      
    
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, PURPLE , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
 

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, MAGENTA , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

      
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}
if ((MODE) == 10)  {
   
      if ((Col1) == 1) {
     
  uint32_t colors[] = {RED, GREEN, WHITE};
  ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_TRICOLOR_CHASE, colors, 200   , true  );
      }
      if ((Col1) == 2) {
   
       
  uint32_t colors[] = {BLUE, RED, WHITE};
  ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_TRICOLOR_CHASE, colors, 200   , true  );
      }      
  
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();

}

  }
  delay (20);
}
  
String splitString(String str, char sep, int index)
{
 int found = 0;
 int strIdx[] = { 0, -1 };
 int maxIdx = str.length() - 1;

 for (int i = 0; i <= maxIdx && found <= index; i++)
 {
    if (str.charAt(i) == sep || i == maxIdx)
    {
      found++;
      strIdx[0] = strIdx[1] + 1;
      strIdx[1] = (i == maxIdx) ? i+1 : i;
    }
 }
 return found > index ? str.substring(strIdx[0], strIdx[1]) : "";
}
uint16_t myCustomEffect(void) { // random chase
  WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
  for(uint16_t i=seg->stop; i>seg->start; i--) {
    ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
  }
  uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
  int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
  int g = random(6) != 0 ? (color >> 8  & 0xFF) : random(256);
  int b = random(6) != 0 ? (color       & 0xFF) : random(256);
  ws2812fx.setPixelColor(seg->start, r, g, b);
  return seg->speed; // return the delay until the next animation step (in msec)
}
  

Cependant, lorsque j'essaie d'adapter ce code à un Arduino UNO avec un shield Ethernet pour gérer un volume de données plus important, je rencontre des problèmes de latence.

Plus précisément, j'utilise la fonction splitString pour traiter les données reçues. Lorsque le nombre de données à analyser est faible (environ 5-6), je n'ai pas de problème. Mais dès que ce nombre augmente (par exemple, 24), la latence devient importante.

Ma question est la suivante : Est-ce que l'Arduino UNO est adapté à ce type de tâche, ou dois-je envisager une autre solution ? J'ai pensé à l'ESP32, mais je ne suis pas sûr si ajouter un module Ethernet supplémentaire comme le WT32-ETH01 serait judicieux.

J'ai des connaissances limitées en programmation, mais j'ai essayé de trouver des solutions par moi-même.

Merci d'avance pour votre aide et vos conseils !

Pourriez-vous me donner votre avis sur les points suivants :

  • Choix du microcontrôleur: Arduino UNO, ESP32 avec module Ethernet, autre ?
  • Optimisation du code: Quelles techniques puis-je utiliser pour réduire la latence (par exemple, optimiser la fonction splitString, utiliser des structures de données plus efficaces) ?

Pour info voici un exemple de code pour l'adaptation à l'Arduino UNO (désolé pour la mise en forme mais c'est pour des test):



/*
  UDPSendReceive.pde:
  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and received messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.

    https://github.com/kitesurfer1404/WS2812FX


*/



#include "SPI.h"        // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(169,254,144,62);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1

#define LED_COUNT 20
#define NUMPIXELS 20
#define LED_PIN 6
#define PIN    6

// How many NeoPixels are attached to the Arduino?


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);




#include <WS2812FX.h>

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int MODE, M_BR, Ba1, Pa2, Va2, Ra2, Ba2,Pa3, Va3, Ra3, Ba3, Pa4, Va4, Ra4, Ba4;

int ja1, ja2, jb1, jb2, jc1, jc2, jd1, jd2;

int val1a, val2a, val3a, val1b, val2b, val3b, val1c, val2c, val3c, val4a, val4b, val4c;

int Col1, Col2 ;







void setup() {
  Serial.begin(115200);
     // pinMode(A1, OUTPUT); 

      
 Ethernet.begin(mac, ip);
  Udp.begin(localPort);

   
  

  
  ws2812fx.init();
 // ws2812fx.setBrightness(2);
  ws2812fx.start();
  // segment 0 is the builtin comet effect
 // ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_THEATER_CHASE  );
pixels.begin(); // This initializes the NeoPixel library.
 // Update LED contents, to start they are all 'off'



 
}


void loop() {




  
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    
    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    //Serial.println("Contents:");
   // Serial.println(packetBuffer);
  String   pacchetto = packetBuffer;  
   // Create a new String object to be split

 
 
  String MODE_Int = splitString(pacchetto, ' ', 0);
  String M_BR_Int = splitString(pacchetto, ' ', 1);

 
 String a1 = splitString(pacchetto, ' ', 12);
 String a2 = splitString(pacchetto, ' ', 13);
 String a3 = splitString(pacchetto, ' ', 4);
 String a4 = splitString(pacchetto, ' ', 5);
 String a5 = splitString(pacchetto, ' ', 6);
 
 String b1 = splitString(pacchetto, ' ', 7); 
 String b2 = splitString(pacchetto, ' ', 8);
 String b3 = splitString(pacchetto, ' ', 9);
 String b4 = splitString(pacchetto, ' ', 10);
 String b5 = splitString(pacchetto, ' ', 11);


 
 String Col_1 = splitString(pacchetto, ' ', 2);
 String Col_2 = splitString(pacchetto, ' ', 3);



 


MODE = MODE_Int.toInt();
M_BR = M_BR_Int.toInt();



Col1 = Col_1.toInt();
Col2 = Col_2.toInt();

    
     
      if ((MODE) == 2)  {
     if ((Col1) == 1)  {
     
 
         
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, BLUE , 20 );
          ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      
      if ((Col1) == 2 ) {
     
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, GREEN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, RED, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, WHITE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, YELLOW , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, CYAN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, MAGENTA, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, PURPLE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        
          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, ORANGE , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
          
      }
   
   
   
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();
 }
    
    
  }
  delay (20);
}
  
String splitString(String str, char sep, int index)
{
 int found = 0;
 int strIdx[] = { 0, -1 };
 int maxIdx = str.length() - 1;

 for (int i = 0; i <= maxIdx && found <= index; i++)
 {
    if (str.charAt(i) == sep || i == maxIdx)
    {
      found++;
      strIdx[0] = strIdx[1] + 1;
      strIdx[1] = (i == maxIdx) ? i+1 : i;
    }
 }
 return found > index ? str.substring(strIdx[0], strIdx[1]) : "";
}
uint16_t myCustomEffect(void) { // random chase
  WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
  for(uint16_t i=seg->stop; i>seg->start; i--) {
    ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
  }
  uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
  int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
  int g = random(6) != 0 ? (color >> 8  & 0xFF) : random(256);
  int b = random(6) != 0 ? (color       & 0xFF) : random(256);
  ws2812fx.setPixelColor(seg->start, r, g, b);
  return seg->speed; // return the delay until the next animation step (in msec)
}

  

Merci beaucoup d'avance de votre aide.
vinchia

Salut.
Ce qui est clair pour moi, c'est qu'un ESP8266 est 10 fois plus rapide qu'un ATMEGA328, donc l'exécution de la fonction splitString est également 10 fois plus rapide.
Ce qui est également clair est que ta fonction splitString utilise subString, ce qui entraîne une allocation mémoire, ce qui est forcément lent.

Une meilleure alternative : strtok() travaille uniquement sur la string à découper et n'a besoin d'aucune allocation !

Remarque :
Entre un ESP8266 160MHz capable de communiquer à 54Mbits/s et un Ethernet 100Mbits/s, sur une UNO à 16MHz, j'hésiterais à dire quel est le plus rapide au final. Je te suggérerais de comparer les deux.

Merci de ta réponse hbachetti ! Toujours présent !!!!
Dans l'idéal je préfère rester côté Arduino, mais penses-tu que si j'utilise la fonction strtok () je peux gérer des paquets assez grands comme envoyés dans l'exemple ? Bien entendu je vais faire des tests, mais vu ma lenteur dans l’apprentissage, si je sais que ça vaut le coup de revoir mon code avant de basculer sur un ESP8266, ça me ferait gagner du temps ...
Il y aussi le manque de confiance sur le WIFI ... en filaire c'est plus sûr.

Quel est l'ordre de ces latences ?
J'ai un doute, tu fais tes 16 split sur une chaine de 5 caractères?
Je suis étonné que 16 split sur une chaine de 24 caractères soit si lent par rapport à 16 split sur 5 caractères.

Rien ne t'oblige à utiliser le WIFI ?

Comme dit plus haut, strtok() travaille directement sur le buffer passé en paramètre.
La fonction place des '\0' entre chaque jeton.
Mais attention, il faudra lui donner packetBuffer à manger, et non pas sa recopie pacchetto.

J'envoie tous les 25 millisecondes une chaine de 24 chiffres qui vont de 0 à 255. C'est la méthode que j'utilise sur mon logiciel (Max/MSP).

J'ai peur de perdre la connexion en Wifi.

... je sens que j'ai du boulot en vue :smiley:

ok, mais tu ne réponds pas à la question :frowning:
quel est la latence constaté?
Du coup c'est pour tester que tu envois que 5 chiffres plutôt que 24 qui pose problèmes?

De manière générale, si tu as besoin de rapidité de traitement, le binaire pourrait être une bonne solution.
tu envois simplement 24 octets + un caractère de fin d'émission si nécessaire.
Tu as alors aucune manipulation de chaine, ni conversion à faire.
Mais je ne sais pas, si tu as la possibilité de changer le logiciel qui envois?

Merci pour votre aide. Je m'excuse pour le manque de clarté de mes précédents messages.

Le principal problème que je rencontre est lié à la fiabilité de la communication avec mon Arduino. Malgré une latence acceptable (1-2 secondes), mon code ne fonctionne plus à partir d'un certain seuil d'instructions.

Pour résumer le contexte :

  • Je souhaite envoyer des commandes simples (0 ou 1) pour contrôler un solénoïde et des valeurs numériques (0-10 pour la couleur, 0-255 pour l'intensité) pour gérer des LED.
  • J'aimerais regrouper ces commandes en un seul message pour optimiser les échanges.
  • Mon logiciel me permet d'envoyer n'importe quelle séquence de caractères.
  • Le problème réside dans l'interprétation de ces données au niveau de l'Arduino.

Exemple de message souhaité : "1 2 255" (Solénoïde 1 activé, LED en mode 2, intensité maximale)

Questions :

  • Format du message : Quel est le format le plus adapté pour représenter ces données ?

  • Traitement Arduino : Quelles fonctions utiliser sur Arduino pour interpréter ces données et piloter les composants ? hbachetti me propose justement strtok () et je suis en train de me battre pour comprendre son utilisation (déjà j'essaie de comprendre cet erreur: cannot convert 'String' to 'char*' for argument '1' to 'char* strtok(char*, const char*)' ... mais je vais vous envoyer le code une fois que j'ai creusé plus la question).

Je suis ouvert à toutes suggestions et exemples de code qui pourraient m'aider à résoudre cette problématique.

Par exemple avec ce code:



/*
  UDPSendReceive.pde:
  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and received messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.

    https://github.com/kitesurfer1404/WS2812FX


*/



#include "SPI.h"        // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(169,254,144,62);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1

#define LED_COUNT 20
#define NUMPIXELS 20
#define LED_PIN 6
#define PIN    6

// How many NeoPixels are attached to the Arduino?


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);




#include <WS2812FX.h>

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int MODE, M_BR, Ba1, Pa2, Va2, Ra2, Ba2,Pa3, Va3, Ra3, Ba3, Pa4, Va4, Ra4, Ba4;

int ja1, ja2, jb1, jb2, jc1, jc2, jd1, jd2;

int val1a, val2a, val3a, val1b, val2b, val3b, val1c, val2c, val3c, val4a, val4b, val4c;

int Col1, Col2 ;







void setup() {
  Serial.begin(115200);
     // pinMode(A1, OUTPUT); 

      
 Ethernet.begin(mac, ip);
  Udp.begin(localPort);

   
  

  
  ws2812fx.init();
 // ws2812fx.setBrightness(2);
  ws2812fx.start();
  // segment 0 is the builtin comet effect
 // ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_THEATER_CHASE  );
pixels.begin(); // This initializes the NeoPixel library.
 // Update LED contents, to start they are all 'off'



 
}


void loop() {




  
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    
    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    //Serial.println("Contents:");
   // Serial.println(packetBuffer);
  String   pacchetto = packetBuffer;  

Serial.println (pacchetto);

    }

   

  }
  
uint16_t myCustomEffect(void) { // random chase
  WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
  for(uint16_t i=seg->stop; i>seg->start; i--) {
    ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
  }
  uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
  int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
  int g = random(6) != 0 ? (color >> 8  & 0xFF) : random(256);
  int b = random(6) != 0 ? (color       & 0xFF) : random(256);
  ws2812fx.setPixelColor(seg->start, r, g, b);
  return seg->speed; // return the delay until the next animation step (in msec)
}

  

  

je reçois ce message dans le Serial: 2 8 255 1 0 0 0 0 0 0 0 
Comment puis-je diriger le 2 vers une sortie , le 8 vers une autre et ainsi de suite ? (peut-être c'est trop demander :roll_eyes:). En quelque sorte rendre ces chiffres des variables qui sont attribuées au processus Loop.

Voici une petite vidéo du passage de mon ordinateur à l'Arduino

Je continue mon raisonnement .... :face_with_peeking_eye:
Avec ce code je devrais être sur la bonne route ....



/*
  UDPSendReceive.pde:
  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and received messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.

    https://github.com/kitesurfer1404/WS2812FX


*/



#include "SPI.h"        // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(169,254,144,62);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1

#define LED_COUNT 20
#define NUMPIXELS 20
#define LED_PIN 6
#define PIN    6

// How many NeoPixels are attached to the Arduino?


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);




#include <WS2812FX.h>

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int MODE, M_BR, Ba1, Pa2, Va2, Ra2, Ba2,Pa3, Va3, Ra3, Ba3, Pa4, Va4, Ra4, Ba4;

int ja1, ja2, jb1, jb2, jc1, jc2, jd1, jd2;

int val1a, val2a, val3a, val1b, val2b, val3b, val1c, val2c, val3c, val4a, val4b, val4c;

int Col1, Col2 ;







void setup() {
  Serial.begin(115200);
     // pinMode(A1, OUTPUT); 

      
 Ethernet.begin(mac, ip);
  Udp.begin(localPort);

   
  

  
  ws2812fx.init();
 // ws2812fx.setBrightness(2);
  ws2812fx.start();
  // segment 0 is the builtin comet effect
 // ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_THEATER_CHASE  );
pixels.begin(); // This initializes the NeoPixel library.
 // Update LED contents, to start they are all 'off'



 
}


void loop() {




  
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    
    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    //Serial.println("Contents:");
   // Serial.println(packetBuffer);
  String   pacchetto = packetBuffer;  
  

//Serial.println (pacchetto);

char *token;
char *mystring = packetBuffer;
const char *delimiter = " ";

 token = strtok(mystring, delimiter);

   while (token != NULL) {
      Serial.println(token);
      token=strtok(NULL, delimiter);
   }
    }

   

  }
  
uint16_t myCustomEffect(void) { // random chase
  WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
  for(uint16_t i=seg->stop; i>seg->start; i--) {
    ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
  }
  uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
  int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
  int g = random(6) != 0 ? (color >> 8  & 0xFF) : random(256);
  int b = random(6) != 0 ? (color       & 0xFF) : random(256);
  ws2812fx.setPixelColor(seg->start, r, g, b);
  return seg->speed; // return the delay until the next animation step (in msec)
}

  

la prochaine étape serait d'attribuer les chiffres reçues aux différentes variables ... :sweat:

Par contre je vois qu'au delà de 11 chiffres mon moniteur série ne lit rien .... mon packet est limité ?

Bonjour vinkia

Pour moi, l'idéal est la structure de données. Je te donne un de mes exemples:

// Structure des données à envoyer
struct __attribute__((packed)) Message {
  char emitterID[10];
  char ledName[10]; // "VERT", "ORANGE", "ROUGE"
  int ledIntensity;    // Intensité de la LED à allumer (0-255)
};
    Message tcpData;

Cette structure doit se trouver des 2 côtés.

Pour l'envoyer:
client.write((uint8_t*)&tcpData, sizeof(tcpData));

Pourt la reçevoir:
int bytesReceived = client.read((uint8_t*)&tcpData, sizeof(tcpData));

L'avantage de la structure, tu mets toutes les variables dont tu as besoin (pas de String), tu l'envoies d'une commande et la reçoit de même.

PS: l'IA peut être une source d'inspiration :wink:
Je n'ai rien essayé :wink:

Cordialement
jpbbricole

Comme je te l'ai indiqué, ainsi que @jpbbricole le format binaire sera plus simple à utiliser, car tu n'a pas à manipuler de chaine de caractére.

Oui strtok est très puissant, mais demande un traitement un peu différent qu'un split.
L'erreur est dû au fait que comme @hbachetti te l'a indiqué, cette fonction ne prends pas un objet String, mais une chaine de caractère "basique" (avec le type char*).

Je t'ai fait un exemple wokwi partiel d'emplois de strtok pour ton cas.

Merci beaucoup pour vos messages. Cela m'a beaucoup aidé à mieux comprendre la fonctionnement de l'Arduino !
Après réflexion, et à cause du manque de temps et de connaissances, j'ai décidé de tester l'ESP32 avec mon ancien code, et surtout de voir si la connexion Wifi est fiable avec mon système. Après cela je verrais si passer par Ethernet avec des shield pour l'EPS32 (autre histoire à creuser) ou si revenir sur un Arduino en améliorant mon code.
Merci encore et affaire à suivre !

Il y a plusieurs années, sur ce forum il y a eu une discussion sur les modules éthernet.
De cette discussion fort intéressante, qui a bien clarifié le sujet, j'ai retenu que :

Coté éthernet il y a deux couches :

  • la couche protocole qui est de la programmation.
  • la couche physique qui est de l'électronique numérique.

Coté module il y a deux catégories :

  • les modules qui n'intègrent que la couche physique, comme par exemple l'ENC28j60 produit par Microchip et conçu pour travailler avec des pics de Microchip qui ont en interne la couche protocole.
    On peut les utiliser avec d'autre micro, mais il faut ajouter des bibliothèques pour réaliser cette couche protocole.
  • Les modules qui ont les deux couches, comme par exemple la série des Wiznet 5xxx

Bonsoir à tous,
je me permets de relancer cette discussion suite à l'achat et au travail sur un ESP 32.
J'arrive bien à gérer les leds avec ma fonction Split. J'ai un peu modifié mon ancien code et bidouillé pour que ma carte soit reconnue sur mon Mac.
Tout allait bien jusqu'au moment où j'ai voulu rajouter le contrôle d'un solénoïde par Mofset. La réponse du Mofset n'est pas bonne. il y a un décalage aléatoire sur la commande.
J'ai bien testé le Mofset avec un code comme celui-ci:

/*
* LAB: 5
* Name: ESP32 PWM LED Control
* Author: Khaled Magdy
* For More Info Visit: www.DeepBlueMbedded.com
*/
 
#define LED_GPIO   23
#define PWM1_Ch    0
#define PWM1_Res   8
#define PWM1_Freq  1000
 
int PWM1_DutyCycle = 0;
 
void setup()
{
  ledcAttachPin(LED_GPIO, PWM1_Ch);
  ledcSetup(PWM1_Ch, PWM1_Freq, PWM1_Res);
}
 
void loop()
{
  
    ledcWrite(PWM1_Ch, 255);
    delay(80);
  
  
    ledcWrite(PWM1_Ch, 0);
    delay(5);
  }

et je n'ai pas de probème.
Voici le fameux code "Split":


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#include <WiFi.h>
//#include <NetworkUdp.h>

const char *networkName = "F4IDM_2T2L";
const char *networkPswd = "1234567890@";

int pwmChannel = 0; //Choisit le canal 0
int frequence = 1000; //Fréquence PWM de 1 KHz
int resolution = 8; // Résolution de 8 bits, 256 valeurs possibles
int pwmPin = 23;




// Buffers pour stocker les valeurs
int MODE, M_BR, Ba1, Pa2, Va2, Ra2, Ba2,Pa3, Va3, Ra3, Ba3, Pa4, Va4, Ra4, Ba4, Speed;

int ja1, ja2, jb1, jb2, jc1, jc2, jd1, jd2, je1, je2, jf1, jf2, jg1, jg2, jh1, jh2, ji1, ji2;

int val1a, val2a, val3a, val1b, val2b, val3b, val1c, val2c, val3c, val4a, val4b, val4c, val5a, val5b, val5c, val6a, val6b, val6c, val7a, val7b, val7c, val8a, val8b, val8c;

int Col1, Col2 ;

int Mot1;


// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1

#define LED_COUNT 45
#define NUMPIXELS 45
#define LED_PIN 16
#define PIN    16

// How many NeoPixels are attached to the Arduino?


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define UDP_TX_PACKET_MAX_SIZE 255
unsigned int localPort = 7778;  // Port local pour écouter
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // Buffer pour les paquets entrants


// Set your Static IP Address Settings
IPAddress local_IP(192, 168, 1, 102);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); // this is optional
IPAddress secondaryDNS(8, 8, 4, 4); // this is optional


#include <WS2812FX.h>

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Classe UDP
WiFiUDP udp;


void setup() {

  // Configuration du canal 0 avec la fréquence et la résolution choisie
    ledcSetup(pwmChannel, frequence, resolution);
    // Assigne le canal PWM au pin 23
    ledcAttachPin(pwmPin, pwmChannel);
   
   


     Serial.begin(115200);
  // Print feedback if the settings are not configured
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
  Serial.println("STA Failed to configure");
}
 connectToWiFi(networkName, networkPswd);

  //WiFi.begin(networkName, networkPswd);
   udp.begin(localPort);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');

    delay(500);
  }  
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());
      ws2812fx.init();
  ws2812fx.start();

pixels.begin(); // This initializes the NeoPixel library.

}

void loop() {
    // Lire un paquet si disponible
    int packetSize = udp.parsePacket();
    if (packetSize) {
        udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
        String pacchetto = packetBuffer;
        //Serial.print(pacchetto);

 
  String MODE_Int = splitString(pacchetto, ' ', 0);
   String Time = splitString(pacchetto, ' ', 1);



 String a1 = splitString(pacchetto, ' ', 2);
 String a2 = splitString(pacchetto, ' ', 3);
 String a3 = splitString(pacchetto, ' ', 4);
 String a4 = splitString(pacchetto, ' ', 5);
 String a5 = splitString(pacchetto, ' ', 6);

 String b1 = splitString(pacchetto, ' ', 7);
 String b2 = splitString(pacchetto, ' ', 8);
 String b3 = splitString(pacchetto, ' ', 9);
 String b4 = splitString(pacchetto, ' ', 10);
 String b5 = splitString(pacchetto, ' ', 11);

 String c1 = splitString(pacchetto, ' ', 12);
 String c2 = splitString(pacchetto, ' ', 13);
 String c3 = splitString(pacchetto, ' ', 14);
 String c4 = splitString(pacchetto, ' ', 15);
 String c5 = splitString(pacchetto, ' ', 16);

 String d1 = splitString(pacchetto, ' ', 17);
 String d2 = splitString(pacchetto, ' ', 18);
 String d3 = splitString(pacchetto, ' ', 19);
 String d4 = splitString(pacchetto, ' ', 20);
 String d5 = splitString(pacchetto, ' ', 21);


 String Col_1 = splitString(pacchetto, ' ', 22);
 String Col_2 = splitString(pacchetto, ' ', 23);

  String M_BR_Int = splitString(pacchetto, ' ', 24);

String Mot_1 = splitString(pacchetto, ' ', 25);

 ja1 = a1.toInt();
 ja2 = a2.toInt();
    val1a = a3.toInt();
    val1b = a4.toInt();
    val1c = a5.toInt();

jb1 = b1.toInt();
 jb2 = b2.toInt();
    val2a = b3.toInt();
    val2b = b4.toInt();
    val2c = b5.toInt();

jc1 = c1.toInt();
 jc2 = c2.toInt();
    val3a = c3.toInt();
    val3b = c4.toInt();
    val3c = c5.toInt();

jd1 = d1.toInt();
 jd2 = d2.toInt();
    val4a = d3.toInt();
    val4b= d4.toInt();
    val4c = d5.toInt();


MODE = MODE_Int.toInt();
M_BR = M_BR_Int.toInt();

Col1 = Col_1.toInt();
Col2 = Col_2.toInt();

Speed = Time.toInt();

Mot1= Mot_1.toInt();




if ((MODE) == 1) {

{
       byte A;
       for (A = ja1 ; A < ja2; A++) {
          pixels.setPixelColor (A, pixels.Color ( val1a, val1b, val1c));
       }
}
{
        byte B;
       for (B = jb1 ; B < jb2; B++) {
          pixels.setPixelColor (B, pixels.Color ( val2a, val2b, val2c));
         }
      }
{
      byte C;
       for (C = jc1 ; C < jc2; C++) {
          pixels.setPixelColor (C, pixels.Color ( val3a, val3b, val3c));
         }
}   
  {   
        byte D;
        for (D = jd1 ; D < jd2; D++) {
          pixels.setPixelColor (D, val4a, val4b, val4c);
        }
      }

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

}



}   
      if ((MODE) == 2)  {
          
     if ((Col1) == 1)  {



          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, BLUE , 20 );
          ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);


      }

      if ((Col1) == 2 ) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, GREEN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
     
      }
   if ((Col1) == 3) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, RED, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);

      }
      if ((Col1) == 4) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, WHITE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
           
      }
      if ((Col1) == 5) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, YELLOW , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
           
      }
      if ((Col1) == 6) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, CYAN , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
           
      }
      if ((Col1) == 7) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, MAGENTA, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
           
      }
      if ((Col1) == 8) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, PURPLE, 20  );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
          
      }
      if ((Col1) == 9) {

          ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_THEATER_CHASE, ORANGE , 20 );
           ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
          
      }


  ws2812fx.setSpeed(Speed);
  ws2812fx.setBrightness(M_BR);
  ws2812fx.service();


 }


   if ((MODE) == 3)  {

      if ((Col1) == 1) {

           uint32_t colors[] = {BLUE, CYAN};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {

          uint32_t colors[] = {GREEN, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {

          uint32_t colors[] = {RED, YELLOW};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {

           uint32_t colors[] = {MAGENTA, PURPLE};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {

           uint32_t colors[] = {ORANGE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {

           uint32_t colors[] = {WHITE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {

          uint32_t colors[] = {PINK, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {

          uint32_t colors[] = {BLUE, RED};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_RUNNING_LIGHTS, colors  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {


 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, WHITE), 20);

      }
       if ((Col1) == 10) {


 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, GREEN) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, WHITE), 20);

      }
       if ((Col1) == 11) {


 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, RED), 20);

      }
       if ((Col1) == 12) {


 ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_RUNNING_LIGHTS, COLORS(GREEN, RED) , 20);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_RUNNING_LIGHTS, COLORS(RED, WHITE), 20);

      }

  ws2812fx.setBrightness(M_BR);
   ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 4)  {

      if ((Col1) == 1) {
         ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, BLUE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, GREEN  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, RED  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, CYAN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, ORANGE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, PINK  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, PURPLE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        ws2812fx.init();
 uint32_t colors[] = {PINK, WHITE};
  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_TWINKLE_FADE, MAGENTA  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 5)  {

      if ((Col1) == 1) {
         ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, BLUE, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, GREEN  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, RED  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, CYAN   , 20);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, ORANGE  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, PINK , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {
          ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, PURPLE, 20   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {
        ws2812fx.init();

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_HYPER_SPARKLE, MAGENTA  , 20 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 6)  {

      if ((Col1) == 1) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, BLUE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
   
      }
      if ((Col1) == 2) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, GREEN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, RED , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, CYAN , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, ORANGE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, ULTRAWHITE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, PINK , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, PURPLE , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_STROBE, MAGENTA , 20  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 7)  {

      if ((Col1) == 1) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, BLUE , 1   );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, GREEN , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, RED , 1);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, CYAN , 1 );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, ORANGE , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, ULTRAWHITE , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, PINK , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, PURPLE , 1);
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_LARSON_SCANNER, MAGENTA , 1  );
   ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

      if ((Col1) == 10) {


  ws2812fx.setSegment(0, 0, (LED_COUNT/2) - 1, FX_MODE_LARSON_SCANNER, CYAN , 1  );
  ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_LARSON_SCANNER, CYAN, 1);
      }

  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 8)  {

      if ((Col1) == 1) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, BLUE , 1   );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, GREEN , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, RED , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }

      if ((Col1) == 4) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, CYAN , 1 );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, ORANGE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, ULTRAWHITE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, PINK , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, PURPLE , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIREWORKS, MAGENTA , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }



  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 9)  {

      if ((Col1) == 1) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, BLUE , 1   );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 2) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, GREEN , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
   if ((Col1) == 3) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, RED , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 4) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, CYAN , 1 );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 5) {

  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, ORANGE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 6) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, ULTRAWHITE , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 7) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, PINK , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 8) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, PURPLE , 1);
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }
      if ((Col1) == 9) {


  ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_FIRE_FLICKER_INTENSE, MAGENTA , 1  );
     ws2812fx.setSegment(1, LED_COUNT +1, LED_COUNT +2);
      }



  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}
if ((MODE) == 10)  {

      if ((Col1) == 1) {

  uint32_t colors[] = {RED, GREEN, WHITE};
  ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_TRICOLOR_CHASE, colors, 200   , true  );
      }
      if ((Col1) == 2) {


  uint32_t colors[] = {BLUE, RED, WHITE};
  ws2812fx.setSegment(0, 0,           LED_COUNT - 1, FX_MODE_TRICOLOR_CHASE, colors, 200   , true  );
      }     

  ws2812fx.setBrightness(M_BR);
    ws2812fx.setSpeed(Speed);
  ws2812fx.service();

}

delay (20);



ledcWrite(pwmChannel, Mot1); 

}




String splitString(String str, char sep, int index)
{
 int found = 0;
 int strIdx[] = { 0, -1 };
 int maxIdx = str.length() - 1;

 for (int i = 0; i <= maxIdx && found <= index; i++)
 {
    if (str.charAt(i) == sep || i == maxIdx)
    {
      found++;
      strIdx[0] = strIdx[1] + 1;
      strIdx[1] = (i == maxIdx) ? i+1 : i;
    }
 }
 return found > index ? str.substring(strIdx[0], strIdx[1]) : "";
}




void connectToWiFi(const char* ssid, const char* password) {
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print('.');
    }
}

uint16_t myCustomEffect(void) { // random chase
  WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
  for(uint16_t i=seg->stop; i>seg->start; i--) {
    ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
  }
  uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
  int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
  int g = random(6) != 0 ? (color >> 8  & 0xFF) : random(256);
  int b = random(6) != 0 ? (color       & 0xFF) : random(256);
  ws2812fx.setPixelColor(seg->start, r, g, b);
  return seg->speed; // return the delay until the next animation step (in msec)
}

Désolé s'il n'est pas très bien mis en forme et si j'ai laissé traîner des informations pas claires.
Avez-vous une idée ?
Pour information j'ai priviligié à ce jour le protocole Split car c'est la logique d'envoie à partir de mon logiciel vers le microcontroleur.
Merci d'avance de vos retours.

Bonjour,
vu que je n'arrive toujours pas à faire marcher correctement mon système, j'ai décidé d'essayer la fameuse fonction strtok !
Voici le code:



#ifdef __AVR__
  #include <avr/power.h>
#endif
#include <WiFi.h>


const char *networkName = "F4IDM_2T2L";
const char *networkPswd = "1234567890@";

int mosfetPin = 23;                       // GPIO pour contrôler le MOSFET


unsigned int localPort = 7778;  // Port local pour écouter


// Set your Static IP Address Settings
IPAddress local_IP(192, 168, 1, 102);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); // this is optional
IPAddress secondaryDNS(8, 8, 4, 4); // this is optional




// Classe UDP
WiFiUDP udp;


void setup() {
// Configuration de la broche MOSFET en sortie PWM
    ledcAttachPin(mosfetPin, 1);           // Assigne GPIO 25 au canal PWM 1
    ledcSetup(1, 5000, 8);                 // Canal 1, fréquence 5kHz, résolution 8 bits
   


     Serial.begin(115200);
  // Print feedback if the settings are not configured
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
  Serial.println("STA Failed to configure");
}
 connectToWiFi(networkName, networkPswd);

  //WiFi.begin(networkName, networkPswd);
   udp.begin(localPort);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');

    delay(500);
  }  
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());

}

void loop() {
    int packetSize = udp.parsePacket();
    if (packetSize) {
        char incomingPacket[255];
        int len = udp.read(incomingPacket, 255);
        if (len > 0) {
            incomingPacket[len] = '\0'; // Terminer la chaîne
        }

        // Utilisation de strtok pour traiter la commande
        char* token = strtok(incomingPacket, " "); // Séparateur espace
        while (token != NULL) {
            int pwmValue = atoi(token); // Convertit chaque token en entier
            pwmValue = constrain(pwmValue, 0, 255); // Assurer que la valeur est entre 0 et 255
            ledcWrite(1, pwmValue); // Applique la valeur PWM à la broche MOSFET
            Serial.printf("MOSFET réglé à %d\n", pwmValue);
            token = strtok(NULL, " "); // Passage au prochain token
        }
    }
}

void connectToWiFi(const char* ssid, const char* password) {
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print('.');
    }
}

Effectivement j'arrive bien à communiquer avec l'ESP32 à partir de mon logiciel, mais la communication est instable, comme s'il y a beaucoup de paquets perdus. Cela arrive surtout quand je sollicite le Mofset très rapidement (80 ms).
Je ne pense pas que ça vient de mon logiciel car sur un Arduino je n'ai pas de soucis.
Si vous avez une piste pour m'aider à comprendre je vous remercie infiniment !

Bonjour vinkia
Quel est l'organe émetteur un autre Arduino ou un autre ESP?

Je trouve ta façon de transmettre les commandes un peu "rigide" et difficile à étendre ou modifier, il n'est qu`à voire ton programme et les difficultés que tu as à le lire et interpréter tes messages.
La façon que j'emploierai augmenterai les octets à transmettre, mais aujourd'hui, ce n'est plus un problème, ainsi pour ce faire, je crée un langage exemple pour 1 2 255:
SEL011, LED022255.
SEL011 = Solénoïde 1 (10 possibles) ON
LED022255 = LED 2 (10 possibles), mode 2 intensité 255

Ca te simplifiera le programme et le traitement des ordres, tu pourra aisément ajouter ou modifier les commandes, leur ordre n'aura plus d'importance etc.
Tu pourrais essayer ton récepteur, sans l'émetteur, simplement en introduisant tes commandes dans la ligne de commande du moniteur.

Mon option préférée si l'émetteur est un autre Arduino ou autre ESP, est la transmission d'une structure, comme préconisé au post#13, c'est vraiment le plus facile, tu auras, au récepteur, la copie des données de l'émetteur, ainsi plus de décodage donc plus de perte de temps.

A+
Cordialement
jpbbricole

Si j’ai bien compris c’est le logiciel Max/SMP

Max est un logiciel de création multimédia interactif utilisé pour le développement de projets audiovisuels et musicaux.

SMP est une extension de Max qui permet l’utilisation de plusieurs cœurs de processeur pour un traitement parallèle .