Esp01 module does not execute the code

Hello, I'm trying to make a rgb module based on an esp01, my problem is that it doesn't matter which code I upload, it doesn't run on the final board, but on the programmer it does (it doesn't give any error when compiling or uploading)

note: 3.28v arrives at both the VCC and ENABLE pins

pcb schematic:


My code:

#define PWM_PIN_R 0
#define PWM_PIN_G 2
#define PWM_PIN_B 3

void setup() {
  pinMode(PWM_PIN_R, OUTPUT);
  pinMode(PWM_PIN_G, OUTPUT);
  pinMode(PWM_PIN_B, OUTPUT);
  delay(2000);
}

void loop() {
  for(int i=0; i<=127; i++){
    analogWrite(PWM_PIN_R, i);
    analogWrite(PWM_PIN_G, i);
    analogWrite(PWM_PIN_B, i);
    delay(10);
  }
  for(int i=127; i>=1; i--){
    analogWrite(PWM_PIN_R, i);
    analogWrite(PWM_PIN_G, i);
    analogWrite(PWM_PIN_B, i);
    delay(10);
  }
}

Code downloaded from internet:

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>

const char *ssid = "RGB";
//Uncomment below line if you wish to set a password for ESP wifi network...
// const char *password = "87654321";  

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);   //IP address of your ESP 
DNSServer dnsServer;
ESP8266WebServer webServer(80);

//Webpage html Code
String webpage = ""
"<!DOCTYPE html><html><head><title>RGB control eTechPath.com</title><meta name='mobile-web-app-capable' content='yes' />"
"<meta name='viewport' content='width=device-width' /></head><body style='margin: 0px; padding: 0px;'>"
"<canvas id='colorspace'></canvas>"
"</body>"
"<script type='text/javascript'>"
"(function () {"
" var canvas = document.getElementById('colorspace');"
" var ctx = canvas.getContext('2d');"
" function drawCanvas() {"
" var colours = ctx.createLinearGradient(0, 0, window.innerWidth, 0);"
" for(var i=0; i <= 360; i+=10) {"
" colours.addColorStop(i/360, 'hsl(' + i + ', 100%, 50%)');"
" }"
" ctx.fillStyle = colours;"
" ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);"
" var luminance = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);"
" luminance.addColorStop(0, '#ffffff');"
" luminance.addColorStop(0.05, '#ffffff');"
" luminance.addColorStop(0.5, 'rgba(0,0,0,0)');"
" luminance.addColorStop(0.95, '#000000');"
" luminance.addColorStop(1, '#000000');"
" ctx.fillStyle = luminance;"
" ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);"
" }"
" var eventLocked = false;"
" function handleEvent(clientX, clientY) {"
" if(eventLocked) {"
" return;"
" }"
" function colourCorrect(v) {"
" return Math.round(1023-(v*v)/64);"
" }"
" var data = ctx.getImageData(clientX, clientY, 1, 1).data;"
" var params = ["
" 'r=' + colourCorrect(data[0]),"
" 'g=' + colourCorrect(data[1]),"
" 'b=' + colourCorrect(data[2])"
" ].join('&');"
" var req = new XMLHttpRequest();"
" req.open('POST', '?' + params, true);"
" req.send();"
" eventLocked = true;"
" req.onreadystatechange = function() {"
" if(req.readyState == 4) {"
" eventLocked = false;"
" }"
" }"
" }"
" canvas.addEventListener('click', function(event) {"
" handleEvent(event.clientX, event.clientY, true);"
" }, false);"
" canvas.addEventListener('touchmove', function(event){"
" handleEvent(event.touches[0].clientX, event.touches[0].clientY);"
"}, false);"
" function resizeCanvas() {"
" canvas.width = window.innerWidth;"
" canvas.height = window.innerHeight;"
" drawCanvas();"
" }"
" window.addEventListener('resize', resizeCanvas, false);"
" resizeCanvas();"
" drawCanvas();"
" document.ontouchmove = function(e) {e.preventDefault()};"
" })();"
"</script></html>";
void handleRoot() 
{
// Serial.println("handle root..");
String red = webServer.arg(0); // read RGB arguments
String green = webServer.arg(1);  // read RGB arguments
String blue = webServer.arg(2);  // read RGB arguments

//for common anode
analogWrite(0, red.toInt());
analogWrite(2, green.toInt());
analogWrite(3, blue.toInt());
//for common cathode
//analogWrite(0,1023 - red.toInt());
//analogWrite(2,1023 - green.toInt());
//analogWrite(3,1023 - blue.toInt());
webServer.send(200, "text/html", webpage);
}
void setup() 
{
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);

analogWrite(0, 1023);
analogWrite(2, 1023);
analogWrite(3, 1023);
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid);
dnsServer.start(DNS_PORT, "rgb", apIP);
webServer.on("/", handleRoot);
webServer.begin();
testRGB();
}
void loop() 
{
dnsServer.processNextRequest();
webServer.handleClient();
}
void testRGB() 
{ 
// fade in and out of Red, Green, Blue
analogWrite(0, 1023); // Red off
analogWrite(2, 1023); // Green off
analogWrite(3, 1023); // Blue off

fade(0); // Red fade effect
fade(2); // Green fade effect
fade(3); // Blue fade effect
}
void fade(int pin) 
{
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, 1023 - u);
delay(1);
}
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, u);
delay(1);
}
}

Is J1, pin 1 Vcc or ground? And, is PJ1, pin 3 (minus sign, n/c) ground?

Reset has to be pulled up too.

With GPIO 0 & 2 (and 1 but that doesn't matter) driving an NPN transistor, you are in effect pulling both GPIO pins LOW, which neither can be if you want the ESP to go into normal boot-mode. GPIO pins 0, 1 & 2 can not be pulled LOW during boot. So basically you will have to come up with a different solution. Easiest is to use a TTL a Chiip of some kind and i usually use a 74HCT04 or sometimes a 74HCT02, to prevent the LED's coming on during boot (the other input is then blocking the output signal)
The main thing is that you can not pull the pins LOW in the schematic, so either you can route their siganl thru something that is truly an input pin, or use pullup resistors and an inverter, there are several ways to go about it.

the pins are PJ1{GND,VCC,NC} and J1{VCC, G, R, B}

and if they are replaced by a mosfet? I understand that your gate is electrically isolated

for example a bs170

yes, that can work, observe the maximum gate voltage though (3.0v) and keep in mind you can't use a voltage divider since that also pulls the pin LOW. a TTL chip is an easier solution.

Or a PNP.

won't work on a 12v strip, or even a 5v strip for that matter.

Didn't see that mentioned.
Anyways. . .

Could there also be a matter of ESP01 vs ESP01S ?

No not really, Basically you can't pull the pins LOW at boot on either versions.

Nearly all non-addressable Strip is 12v (or 24v) but regardless, i've never seen 3.3v strip.

Mind you i will have to add some more comments on the Vin.

It should, yes, but you have not provided any more heatsink on the PCB for the AMS1117 other than the tab, and if the ESP is going to connect to WiFi, you will need that, even more so if the input voltage is 12v.
So you do have a power issue as well as far as i can tell.

Well yes that has a regulator that drops it from 5v to 3.3v and it has some heatsink on the PCB probably.

Since i anyway use 5v to power a TTL (HCT) chip, i drop down from 12v in steps, first with a 7805 (TO-220 package) that already gets quite warm, and then a AMS1117 3.3v from 5v to 3.3v with about 2 square centimeters of heatsink on the PCB for that.

Something came to mind, if you just add a 1.2v zener diode instead of the 10K resistor, (or basically almost any diode should get you in the clear, you just need to be within a rather wide window for those) and use the mosfets that should work OK.

hello, you can't see it in the design, but on the tab, a copper plate is soldered as a heatsink, on the other hand, how would it be using a diode?

that is, would the base of the 2n2222 be connected to the cathode of the diode and the anode to the resistor?

or is it another system?

Would a rectifier diode like the 1n4001 work?

the diode is for if you would be using a bs170 instead of the 2n2222, the voltage drop across the diode should suffice to drop the gate voltage down from 3.3v to below 3v.

that is clearly not visible. I would normally use copper fill on the PCB for this. As long as the heatsink doesn't get to warm that should do the trick.

I am just looking for a solution for you with this pcb , which should be considered a patch, more than a solution. The best is still to use a TTL chip, and depending on the amount of LED's you want to control, mosfets with heatsink as well, but clearly you need a different PCB for that.

Well, I think I'm going to put it together with another project, which is based on a "WeMos D1 mini", which pwm pins don't have this restriction?

note: using some irlr8726 mosfets, two of them stay always active (I suppose because the esp01 has some pullup resistor)

here
all pins can be used as PWM pins. I found that when using PWM i had to create a bit of a curve to be able to use the lower brightness levels, for that i had to increase the PWM resolution and PWM frequency.

GPIO 1 has a pullup through the internal LED, but mosfets may also just keep the gate open simply because there is nothing closing it. Regardless of that, you deal with pulse at boot and that is why i resorted to a 7402 (nor-gate) where there is 1 pin controlling the logic while the device is starting up.

That is to say, the MOSI, MISO and SCK pins would not have a problem on boot with a 2n2222? not even with a MOSFET?

Nope should not be a problem, you can use those either way.

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