Hardware: NodeMCU ESP8266 (12E), 256 - WS2812b LEDs, 74LVC245 Logic Leveler.
Software: IDE 1.8.15, Blynk Library 1.0.1, blynk.cloud
Widgets: RTC
My project is a word clock. It gets the time, parses it and lights up the led’s that are behind the letters that spell out the time. I used this exact same hardware and code (getting the time from a time server) and everything worked. I wanted features of Blynk (the ability to change colors, etc) when I wrapped my code with blynk, the issue of extra lit LED’s arose…
The problem is when the code runs, it connects to the blynk server updates the RTC, but when the time is parsed and the LED’s turned on there are various other LEDs that illuminate also. I have checked all electrical connections.
#define BLYNK_TEMPLATE_ID "TMPLLvNnYzwL"
#define BLYNK_DEVICE_NAME "LED Blink"
#define BLYNK_FIRMWARE_VERSION "1.0.1"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
//**********************************************************************************************
//**************************************** Libraries *****************************************
//**********************************************************************************************
#include "BlynkEdgent.h"
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Adafruit_NeoPixel.h>
//**********************************************************************************************
//**************************** GLOBAL VARIABLES *********************************************
//**********************************************************************************************
int CurrentMinute, CurrentHour, CurrentDay, CurrentMonth, CurrentYear, CurrentWeekday;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
String months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
BlynkTimer timer;
WidgetRTC rtc;
//**********************************************************************************************
//************************ #defines for Blynk.Edgent *****************************************
//**********************************************************************************************
#define USE_NODE_MCU_BOARD
//**********************************************************************************************
//************************** NeoPixel Configuration *****************************************
//**********************************************************************************************
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)
#define MSG_COLOR strip.Color(127, 127, 127)
#define HOUR_COLOR strip.Color(255,255,0)
#define MIN_COLOR strip.Color(0,255,255)
#define LED_COUNT 256
#define LED_PIN 12
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//**********************************************************************************************
//************************** Pin for the LED to turn on and Off ******************************
//**************************** to verify connection to BLYNK *********************************
//**********************************************************************************************
#define Blynk_Led_Pin D7
//**********************************************************************************************
//************************** Processes the minutes into function calls *********************
//**************************** to light up LEDs *********************************************
//**********************************************************************************************
void LightMinutes(int CurrentMin)
{
switch (CurrentMin)
{
case 0 ... 4:
LightHourO();
LightHourClock();
break;
case 5 ... 9:
case 55 ... 59:
LightMinFive();
LightMinMinutes();
break;
case 10 ... 14:
case 50 ... 54:
LightMinTen();
LightMinMinutes();
break;
case 15 ... 19:
case 45 ... 49:
LightMinQuarter();
break;
case 20 ... 24:
case 40 ... 44:
LightMinTwenty();
LightMinMinutes();
break;
case 25 ... 29:
case 35 ... 39:
LightMinTwenty();
LightMinFive();
LightMinMinutes();
break;
case 30 ... 34:
LightMinHalf();
break;
default:
break;
}
if ((CurrentMin >= 5) && (CurrentMin < 35))
LightMinPast();
if (CurrentMin >= 35)
LightMinTo();
}
//**********************************************************************************************
//************************** Processes the Hour into function calls *********************
//**************************** to light up LEDs *********************************************
//**********************************************************************************************
void LightHour(int CurrentHour)
{
if (CurrentHour <= 11)
{
LightHourIn();
LightHourThe();
LightHourMorning();
}
if ((CurrentHour > 12) && (CurrentHour < 18))
{
LightHourIn();
LightHourThe();
LightHourAfternoon();
}
if ((CurrentHour >= 18) && (CurrentHour <=21))
{
LightHourIn();
LightHourThe();
LightHourEvening();
}
if ((CurrentHour > 5) && (CurrentHour < 9))
{
LightMsgTime();
LightMsgFor();
LightMsgCoffee();
LightMsgGood();
LightMsgMorning();
}
if (CurrentHour >= 21)
{
LightMsgTime();
LightMsgFor();
LightMsgSleep();
}
if (CurrentHour >= 12) CurrentHour = CurrentHour - 12;
switch (CurrentHour)
{
case 0: LightHourTwelve();
break;
case 1: LightHourOne();
break;
case 2: LightHourTwo();
break;
case 3: LightHourThree();
break;
case 4: LightHourFour();
break;
case 5: LightHourFive();
break;
case 6: LightHourSix();
break;
case 7: LightHourSeven();
break;
case 8: LightHourEight();
break;
case 9: LightHourNine();
break;
case 10: LightHourTen();
break;
case 11: LightHourEleven();
break;
case 12: LightHourMidnight();
break;
default:
break;
}
//will be sent the hour to display. Just light it up
//Check for morning, afternoon, sleep , coffee(chai)
}
Those are the declarations and includes. I also included the parsing of the time, I did not include the functions that turn on the LED’s. Imagine a bunch of for loops.
Here is the code:
void Update_Clock()
{
strip.clear();
CurrentMinute=minute();
CurrentHour=hour();
CurrentDay=day();
CurrentWeekday=weekday();
CurrentMonth=month();
CurrentYear = year();
LightMinutes(CurrentMinute);
if (CurrentMinute < 35)
{
LightHour(CurrentHour);
}
else
{
LightHour(CurrentHour + 1);
}
if (CurrentWeekday == 6)
{
LightMsgHappy();
LightMsgFriday();
}
strip.show();
strip.clear();
Serial.println(" ");
}
void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V1, currentTime);
// Send date to the App
Blynk.virtualWrite(V2, currentDate);
Blynk.virtualWrite(V3, months[CurrentMonth-1]);
Blynk.virtualWrite(V4, daysOfTheWeek[CurrentWeekday-1]);
}
//**********************************************************************************************
//****************************** BLYNK action functions **************************************
//**********************************************************************************************
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
}
BLYNK_WRITE(V0)
{
int pinValue = param.asInt();
digitalWrite(Blynk_Led_Pin,pinValue);
}
BLYNK_WRITE(V6)
{
colorWipe(strip.Color( param[0].asInt(), param[1].asInt(), param[2].asInt()));
}
BLYNK_WRITE(V5)
{
// Set incoming value from pin V5 to a variable
int value = param.asInt();
for (int i = 14; i <= 17; i++) { // For each pixel in strip...
strip.setPixelColor(i, strip.Color(255*value,0,0)); // Set pixel's color (in RAM)
}
}
void setup()
{
pinMode(Blynk_Led_Pin,OUTPUT);
Serial.begin(115200);
BlynkEdgent.begin();
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
// Update Blynk.consle clock every 9 seconds
timer.setInterval(90000L, clockDisplay);
//Update the LED Clock every 10 seconds
timer.setInterval(10000L, Update_Clock);
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(BRIGHTNESS);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
Any and all help is appreciated. I do not know if I used a reserved pin GPIO12 or if I am getting interference from the WIFI transmissions. I am stumped.