ESP32 control LED buildIN with OSC : not synchro. Problem with Heltech?

Hello,

I send OSC message with an LFO. (I send a float from 0.0 to 1.0)
I can see in the monitor of IDE Arduino, that message is not perfectly received
So the light of build in is not synchronized too.

I use my USB port as power supply. My esp32 is the Heltec Wifi 32 V3

I'm quite sure that I managed once to have a regular flashing...

Thank for trying to give me a direction

Here my code with fastLed library

/*---------------------------------------------------------------------------------------------

  Open Sound Control (OSC) library for the ESP8266/ESP32

  Example for receiving open sound control (OSC) messages on the ESP8266/ESP32
  Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266.

  This example code is in the public domain.

--------------------------------------------------------------------------------------------- */
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>

//char ssid[] = "Iphone de ben"; // your network SSID (name)
//char pass[] = "cacaprout";  // your network password

char ssid[] = "Bbox-E69F0626"; // your network SSID (name)
char pass[] = "NKg5Ad1m3mXFgx142p";  // your network password

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//const IPAddress outIp(10,40,10,105);        // remote IP (not needed for receive)
const IPAddress outIp(192,168,1,77); 
const unsigned int outPort = 9999;          // remote port (not needed for receive)
const unsigned int localPort = 8000;        // local port to listen for UDP packets (here's where we send the packets)

OSCErrorCode error;
unsigned int ledState = LOW;              // LOW means led is *on*

#ifndef BUILTIN_LED
#ifdef LED_BUILTIN
#define BUILTIN_LED LED_BUILTIN
#else
#define BUILTIN_LED 13
#endif
#endif

// control LED with FastLed
#include <FastLED.h>

#define NUM_LEDS  8
#define LED_PIN   1

CRGB leds[NUM_LEDS];
float count;
//---------------------

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, ledState);    // turn *on* led

  Serial.begin(115200);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
#ifdef ESP32
 Serial.print("LocalportESP32: ");
  Serial.println(localPort);
#else
  Serial.println(Udp.localPort());
#endif

// control LED with FastLed
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); // 500 is max?
  FastLED.setBrightness(10); //255 is max
  count = 0.0;
  //--------------------- TURN OFF LIGHT
   for (int i = 0; i <= NUM_LEDS; i++) {
  //  leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
  leds[i] = CRGB ( 0,0,0);
    delay(10);
    FastLED.show();
    delay(10);
  }
}

void led(OSCMessage &msg) {
  ledState = msg.getFloat(0);
  digitalWrite(BUILTIN_LED, ledState);
  if (ledState==true) {
    count+=1.0;
 
  // Serial.print("/led: ");
  // Serial.println(ledState);
  // Serial.print(" chek 240 data/min : " );
   Serial.println(count);

       for (int i = 0; i <= 7; i++)
    {
         leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
         leds[moduloD] = CRGB ( (moduloC+1)*(2),255/((moduloD+1)*(i+1)), 127);   
         FastLED.show();
  }


    }

}

void loop() {
  OSCMessage msg;
  int size = Udp.parsePacket();

  if (size > 0) {
    while (size--) {
      msg.fill(Udp.read());
    }
    if (!msg.hasError()) {
      msg.dispatch("/led", led);
    } else {
      error = msg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}

Won't compile.. :frowning:

moduloD and moduloC are undefined??
curious, why the float type, you store it in ledState which is an unsigned int??

confused..~q

Oups sorry.
I deleted too much thing

Here the good one

/*---------------------------------------------------------------------------------------------

  Open Sound Control (OSC) library for the ESP8266/ESP32

  Example for receiving open sound control (OSC) messages on the ESP8266/ESP32
  Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266.

  This example code is in the public domain.

--------------------------------------------------------------------------------------------- */
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>

//char ssid[] = "Iphone de ben"; // your network SSID (name)
//char pass[] = "cacaprout";  // your network password

char ssid[] = "Bbox-E69F0626"; // your network SSID (name)
char pass[] = "NKg5Ad1m3mXFgx142p";  // your network password

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//const IPAddress outIp(10,40,10,105);        // remote IP (not needed for receive)
const IPAddress outIp(192,168,1,77); 
const unsigned int outPort = 9999;          // remote port (not needed for receive)
const unsigned int localPort = 8000;        // local port to listen for UDP packets (here's where we send the packets)

OSCErrorCode error;
unsigned int ledState = LOW;              // LOW means led is *on*

#ifndef BUILTIN_LED
#ifdef LED_BUILTIN
#define BUILTIN_LED LED_BUILTIN
#else
#define BUILTIN_LED 13
#endif
#endif

// control LED with FastLed
#include <FastLED.h>

#define NUM_LEDS  8
#define LED_PIN   1

CRGB leds[NUM_LEDS];
float count;
int moduloD;
//---------------------

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, ledState);    // turn *on* led

  Serial.begin(115200);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
#ifdef ESP32
 Serial.print("LocalportESP32: ");
  Serial.println(localPort);
#else
  Serial.println(Udp.localPort());
#endif

// control LED with FastLed
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); // 500 is max?
  FastLED.setBrightness(10); //255 is max
  count = 0.0;
  //--------------------- TURN OFF LIGHT
   for (int i = 0; i <= NUM_LEDS; i++) {
  //  leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
    leds[i] = CRGB ( 0,0,0);
    delay(10);
    FastLED.show();
    delay(10);
  }
}

void led(OSCMessage &msg) {
  ledState = msg.getFloat(0);
  digitalWrite(BUILTIN_LED, ledState);
  if (ledState==true) {
    count+=1.0;
 
  // Serial.print("/led: ");
  // Serial.println(ledState);
  // Serial.print(" chek 240 data/min : " );
   Serial.println(count);
   moduloD =(int) count%8;

       for (int i = 0; i <= 7; i++)
    {
         leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
         leds[moduloD] = CRGB ( (moduloD+1)*(2),255/((moduloD+1)*(i+1)), 127);   
         FastLED.show();
    }
 }

}

void loop() {
  OSCMessage msg;
  int size = Udp.parsePacket();

  if (size > 0) {
    while (size--) {
      msg.fill(Udp.read());
    }
    if (!msg.hasError()) {
      msg.dispatch("/led", led);
    } else {
      error = msg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}

Chances are FastLED is going to interfere with you timing.

#define LED_PIN   1

That is also the TX pin isn't it ?
so when you do

Serial.println(count);

that may have some effect.

no it doesn't change anything.
I tried with 4 pulsations/sec

I should have data from monitor each 250 ms
but I have this

17:59:12.240 -> 320.00
17:59:12.606 -> 321.00
17:59:12.769 -> 322.00
17:59:13.209 -> 323.00
17:59:13.274 -> 324.00
17:59:13.636 -> 325.00
17:59:13.768 -> 326.00
17:59:14.005 -> 327.00
17:59:14.237 -> 328.00
17:59:14.670 -> 329.00
17:59:14.770 -> 330.00
17:59:15.003 -> 331.00
17:59:15.369 -> 332.00
17:59:15.501 -> 333.00
17:59:15.763 -> 334.00
17:59:15.992 -> 335.00
17:59:16.386 -> 336.00
17:59:16.518 -> 337.00
17:59:16.787 -> 338.00
17:59:17.019 -> 339.00
17:59:17.419 -> 340.00

the step is not regular but I have 20 pulsations in 5 secondes that 's exactly correct

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.