Hi Blynkers,
I have a very weird issue when I migrated my sketch to Blynk 2.0.
The code is a 4 channel led lamp, where with the PWM output trought the GPIO I can control the brightness of the leds.
This piece of code was working fine with the legacy Blynk, but with the new Blynk it looks like I can’t set the PWM output to GPIO0, but the other outputs works.
The code is too long, the I’ll show the main parts related to the fail:
//Declarations
#define BLYNK_TEMPLATE_ID "--------------------------"
#define BLYNK_DEVICE_NAME "Lampara SunnyReef"
#define BLYNK_FIRMWARE_VERSION "0.2.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
#include <TimeLib.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <WidgetRTC.h>
int PWM_Digital_Canal[5] = { 16, 5, 4, 0, 2};
void setup()
{
Serial.begin(115200); // See the connection status in Serial Monitor
setSyncInterval(1);
rtc.begin();
Serial.println("Iniciando App");
//Inicializa el controlador y sus variables
analogWriteFreq(250);
int i;
for (i = 0; i < 4; i = i + 1)
{
pinMode(PWM_Digital_Canal[i], OUTPUT);
analogWrite(PWM_Digital_Canal[i], potCanal[i]*proteccion_temp / 100);
}
pinMode(Relay, OUTPUT);
BlynkEdgent.begin();
actualizaLuzTemp();
timer.setInterval(60000, actualizaLuzTemp);
timer.setInterval(5000, leeTemperatura);
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
}
void actualizaLuzTemp()
{
/* a lot of code not related with the fail */
int i;
for (i = 0; i < 4; i = i + 1 )
{
analogWrite(PWM_Digital_Canal[i], potCanal[i]*proteccion_temp / 100);
luz_anterior[i] = potCanal[i];
delay(10);
}
Blynk.virtualWrite(Virtual_Total_Azul, (potCanal[0] + potCanal[1] + potCanal[3]+ potCanal[2]*3/5)*proteccion_temp / 100);
Blynk.virtualWrite(Virtual_Azul_Blanco, (potCanal[2])*2/5*proteccion_temp / 100);
terminal.println(currentTime);
Blynk.virtualWrite(GraphTemp_LED, temp_LED);
terminal.println("LED " + String( temp_LED) + "°C ");
terminal.println(Modo_txt[Modo]);
for (i = 0; i < 4; i = i + 1 )
{
terminal.print("Canal ");
terminal.print(String(i + 1));
terminal.print(": ");
terminal.print(String(potCanal[i]*proteccion_temp / 100));
if ( Luz_Luna && ( potCanal[i] <= 10 ) && ( ( i == 0) || ( i == 3))) terminal.print(" Luna");
terminal.println("");
}
terminal.println(F("-----------------"));
terminal.flush();
}
The line:
analogWrite(PWM_Digital_Canal[i], potCanal[i]*proteccion_temp / 100);
does not work for GPIO0 only.
I’m using the last Arduino IDE, with all the upgraded libraries.
I know the code is doing right because I cann see at the Blynk app the messages in the terminal widget with the rigth values for each GPIO (channel).
Any ideas?