Arduino code only works on arduino and not esp32

Hello Guys, i've got this new groove led strip driver wich as the name suggests drives an led strip (4pin 12v led strip). I tested it with my Arduino uno and the recomended code of the website and it works fine. Now I want to control my led strip wirelessly so i bought an esp32. When I tried the same code (I changed the pins obviously) with it, the led's don't work anymore and just blink in random colors at random intervalls. I think this has to do with the driver and the esp32 not beeing in sync with one another but I dont now. Thanks for any advice, you can find my code below

DemoLedStrip.ino

#include "RGBdriver.h"
#define CLK 18//pins definitions for the driver        
#define DIO 19
RGBdriver Driver(CLK,DIO);
void setup()  
{ 

}  
void loop()  
{ 
  unsigned int i;
  while(1){
    for(i = 0;i < 256;i ++)
    {
    Driver.begin(); // begin
    Driver.SetColor(i,i,i); //Green. First node data. SetColor(B,R,G)
    Driver.end();
    delay(10);
    }
    delay(10000);
    for(i = 255;i > 0;i --)
    {
      Driver.begin(); // begin
      Driver.SetColor(i,i,i); //Green. first node data
      Driver.end();
      delay(10);
    }
  }
}

RGBdriver.cpp

//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//  Modified Record:
/***************************************************************************/  
#include "RGBdriver.h"
RGBdriver::RGBdriver(uint8_t Clk, uint8_t Data)
{
  Clkpin = Clk;
  Datapin = Data;
  pinMode(Datapin, OUTPUT);
  pinMode(Clkpin, OUTPUT);
}

void RGBdriver::begin(void)
{
  Send32Zero();
}

void RGBdriver::end(void)
{
  Send32Zero();
}

void RGBdriver::ClkRise(void)
{
  digitalWrite(Clkpin, LOW);
  delayMicroseconds(20); 
  digitalWrite(Clkpin, HIGH);
  delayMicroseconds(20);   
}
 
void RGBdriver::Send32Zero(void)
{
  unsigned char i;
 
  for (i=0; i<32; i++)
  {
    digitalWrite(Datapin, LOW);
    ClkRise();
  }
}
 
uint8_t RGBdriver::TakeAntiCode(uint8_t dat)
{
  uint8_t tmp = 0;
 
  if ((dat & 0x80) == 0)
  {
    tmp |= 0x02; 
  }
 
  if ((dat & 0x40) == 0)
  {
    tmp |= 0x01; 
  }
 
  return tmp;
}
 
// gray data
void RGBdriver::DatSend(uint32_t dx)
{
  uint8_t i;
 
  for (i=0; i<32; i++)
  {
    if ((dx & 0x80000000) != 0)
    {
      digitalWrite(Datapin, HIGH);
    }
    else
    {
      digitalWrite(Datapin, LOW);
    }
 
    dx <<= 1;
    ClkRise();
  }
}
 
// Set color
void RGBdriver::SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
{
  uint32_t dx = 0;
 
  dx |= (uint32_t)0x03 << 30;             // highest two bits 1,flag bits
  dx |= (uint32_t)TakeAntiCode(Blue) << 28;
  dx |= (uint32_t)TakeAntiCode(Green) << 26;	
  dx |= (uint32_t)TakeAntiCode(Red) << 24;
 
  dx |= (uint32_t)Blue << 16;
  dx |= (uint32_t)Green << 8;
  dx |= Red;
 
  DatSend(dx);
}

RGBdriver.h

#ifndef RGB_DRIVER_H
#define RGB_DRIVER_H
//#include <inttypes.h>
#include <Arduino.h>
class RGBdriver
{
  public:
    RGBdriver(uint8_t, uint8_t);
    void begin(void);
    void end(void);
    void ClkRise(void);
    void Send32Zero(void);
    uint8_t TakeAntiCode(uint8_t dat);
    void DatSend(uint32_t dx);
    void SetColor(uint8_t Red,uint8_t Green,uint8_t Blue);
  private:
    uint8_t Clkpin;
    uint8_t Datapin;
};
#endif
1 Like

I am not familiar with the driver board that you have, but the Uno outputs 5V and the ESP32 outputs 3.3V

Could this be a factor in your problem ?

Please provide a wiring diagram showing all the connections including power and ground. Identify all your components including power supply.

The LED driver chip is 5V only.

Looking here, https://files.seeedstudio.com/wiki/Grove-LED_Strip_Driver/res/Grove-LED_Strip_driver_V1.2.pdf

One will see that the GROVE thingy is a 5V device. The ESP32 is not a 5V device.

Hi,
I have doubts if this library made for an arduino, works correctly in an ESP.

Based on the schematics on the seeedstudio website,
the +5V for the Grove circuit is obtained through the +12V that supplies it.

The SDin and SCin input from ESP is received in the grove at a SI5904 (Grove - LED Strip Driver V1.1:) or 2N7002 (Grove - LED Strip Driver V1.2:) MOSFET gate.

These MOSFETs have respectively Gate Threshold Voltage
from 0.6V to 1.5V (SI5904 ) and 0.8V to 3.0V (2N7002).

PS: I don't know if the resistor on the Source seems to get in the way of working at 3.3V.
Groove2

how can i create such a diagram
I could tell you how its all connected
12v and ground of the power supply goes to the driver
sdin (data) goes to pin 19 of the esp32
scin (clock) goes to pin 18 of the esp32
ground of the driver is connected to ground of esp32
the 12v from the power supply is also directly feeding into the esp32 through its vin port (I think you can do that)

https://www.autodesk.com/products/eagle/free-download

as ruilviana said, i think it can work with the 3.3v that the esp32 sends

Pencil and paper and upload a 'photo of it

i could try, I've tried bevor to make something like that but i'm to dumb


UKHeliBob
I can try that :slight_smile:


I'ts not good but it works out I hope

Read that reply again. I don't either.

But feel free to keep banging your head against the wall.

yeah sorry about that, I'm just frustrated yk

Guys do you think i could use a transistor to boost up the 3.3v to 5v(This is how transistors work right)

The resistor on the source of the board is meant as a pulldown right?

No. It is simply a bad design, that happens to work for 5V circuits.

Buy an LED driver that is designed for 3.3V logic, if you insist on using the ESP32 (or any other 3.3V processor).

sorry, but are you shure that i can't just simply use transistors

try it and let us know how it goes.

Logic level shifters.