Controling the brightness of a lamp

change it to 'Serial`

Hello,
I hope everyone is okay, because of this pandemic situation.
After i implemented the suggestions you gave me, i uploaded the code sucessufuly to ESP8266, but in cayenne platform it says the ESP8266 is pending connection.
How can I solve this?

#include <RBDdimmer.h>
#include <CayenneMQTTESP8266.h>

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

#define CAYENNE_PRINT Serial
//#define CAYENNE_DEBUG

// WiFi network info.
char ssid = “”;
char wifiPassword = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “”;
char password = “”;
char clientID = “”;

unsigned long lastMillis = 0;
/**************

  • RobotDyn
  • Dimmer Library

  • The following sketch is meant to to define dimming value through potentiometer,
  • The potentiometer values are changing in range from 0 to 1023
  • potentiometer values are converted through the map function to values from 0 to 100% and saved in dimmer.setPower(outVal);
  • Serial.begin is used to display dimming values
  • ---------------------- OUTPUT & INPUT Pin table ---------------------
  • ±--------------±------------------------±------------------------+
  • | Board | INPUT Pin | OUTPUT Pin |
  • | | Zero-Cross | |
  • ±--------------±------------------------±------------------------+
  • | Lenardo | D7 (NOT CHANGABLE) | D0-D6, D8-D13 |
  • ±--------------±------------------------±------------------------+
  • | Mega | D2 (NOT CHANGABLE) | D0-D1, D3-D70 |
  • ±--------------±------------------------±------------------------+
  • | Uno | D2 (NOT CHANGABLE) | D0-D1, D3-D20 |
  • ±--------------±------------------------±------------------------+
  • | ESP8266 | D1(IO5), D2(IO4), | D0(IO16), D1(IO5), |
  • | | D5(IO14), D6(IO12), | D2(IO4), D5(IO14), |
  • | | D7(IO13), D8(IO15), | D6(IO12), D7(IO13), |
  • | | | D8(IO15) |
  • ±--------------±------------------------±------------------------+
  • | ESP32 | 4(GPI36), 6(GPI34), | 8(GPO32), 9(GP033), |
  • | | 5(GPI39), 7(GPI35), | 10(GPIO25), 11(GPIO26), |
  • | | 8(GPO32), 9(GP033), | 12(GPIO27), 13(GPIO14), |
  • | | 10(GPI025), 11(GPIO26), | 14(GPIO12), 16(GPIO13), |
  • | | 12(GPIO27), 13(GPIO14), | 23(GPIO15), 24(GPIO2), |
  • | | 14(GPIO12), 16(GPIO13), | 25(GPIO0), 26(GPIO4), |
  • | | 21(GPIO7), 23(GPIO15), | 27(GPIO16), 28(GPIO17), |
  • | | 24(GPIO2), 25(GPIO0), | 29(GPIO5), 30(GPIO18), |
  • | | 26(GPIO4), 27(GPIO16), | 31(GPIO19), 33(GPIO21), |
  • | | 28(GPIO17), 29(GPIO5), | 34(GPIO3), 35(GPIO1), |
  • | | 30(GPIO18), 31(GPIO19), | 36(GPIO22), 37(GPIO23), |
  • | | 33(GPIO21), 35(GPIO1), | |
  • | | 36(GPIO22), 37(GPIO23), | |
  • ±--------------±------------------------±------------------------+
  • | Arduino M0 | D7 (NOT CHANGABLE) | D0-D6, D8-D13 |
  • | Arduino Zero | | |
  • ±--------------±------------------------±------------------------+
  • | Arduino Due | D0-D53 | D0-D53 |
  • ±--------------±------------------------±------------------------+
  • | STM32 | PA0-PA15,PB0-PB15 | PA0-PA15,PB0-PB15 |
  • | Black Pill | PC13-PC15 | PC13-PC15 |
  • | BluePill | | |
  • | Etc… | | |
  • ±--------------±------------------------±------------------------+
    */

#define USE_SERIAL Serial //Serial for boards whith USB serial port
#define outputPin 12
#define zerocross 5 // for boards with CHANGEBLE input pins

dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
//dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int outVal = 0;

void setup() {
USE_SERIAL.begin(9600);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
pinMode(outputPin, OUTPUT);
Serial.begin(74880);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop()
{
outVal = map(analogRead(0), 1, 1024, 100, 0); // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
digitalWrite(outputPin, outVal);
dimmer.setPower(outVal); // name.setPower(0%-100%)
}

CAYENNE_IN(1)
{
int outvalue = getValue.asInt(); // 100 to 0
digitalWrite(outputPin, outVal);
dimmer.setPower(outVal); // name.setPower(0%-100%)

}

what do you get in the serial monitor? add this in the code #define CAYENNE_DEBUG

This is what I get in serial monitor:

16:10:18.298 → (@40202dd4
16:10:18.298 → 3fffff90: feefeffe feefeffe feefeffe feefeffe
16:10:18.324 → 3fffffa0: feefeffe 00000000 3ffeeaac 40205388
16:10:18.324 → 3fffffb0: feefeffe feefeffe 3ffe8580 40101039
16:10:18.324 → <<<stack<<<
16:10:18.358 → ⸮⸮⸮PV⸮⸮ET⸮⸮⸮⸮T⸮⸮⸮⸮u⸮U+UZ⸮⸮UT⸮⸮⸮TQT⸮UQ⸮⸮jP⸮V⸮⸮u⸮⸮⸮⸮⸮ZT⸮(E⸮⸮⸮⸮QTE⸮jQTE⸮⸮UU⸮⸮⸮/⸮⸮ISR not in IRAM!
16:10:18.425 →
16:10:18.425 → User exception (panic/abort/assert)
16:10:18.460 → Abort called
16:10:18.460 →
16:10:18.460 → >>>stack>>>
16:10:18.460 →
16:10:18.460 → ctx: cont
16:10:18.460 → sp: 3ffffec0 end: 3fffffc0 offset: 0000
16:10:18.460 → 3ffffec0: feefeffe feefeffe feefeffe feefeffe
16:10:18.460 → 3ffffed0: 000000fe 00000000 00000000 00000000
16:10:18.460 → 3ffffee0: 00000000 00000000 00000000 00ff0000
16:10:18.460 → 3ffffef0: 5ffffe00 5ffffe00 00000020 00000000
16:10:18.493 → 3fffff00: 00000002 00000005 00000005 40205732
16:10:18.493 → 3fffff10: 4010072e 3ffef834 3ffef81c 40205748
16:10:18.493 → 3fffff20: 0000001c 00012480 00000005 40205c8d
16:10:18.493 → 3fffff30: 00000000 4020677d ffffffff 00000001
16:10:18.493 → 3fffff40: feefeffe 00000001 3ffeea74 3ffeeaec
16:10:18.527 → 3fffff50: 3fffdad0 3ffeea74 00000005 40205d3c
16:10:18.527 → 3fffff60: 00000000 feefeffe feefeffe 40203065
16:10:18.527 → 3fffff70: 00012480 0000001c 3ffee5dc 4020309e
16:10:18.527 → 3fffff80: 3fffdad0 3ffeea74 00012480 40202dd4
16:10:18.527 → 3fffff90: feefeffe feefeffe feefeffe feefeffe
16:10:18.561 → 3fffffa0: feefeffe 00000000 3ffeeaac 40205388
16:10:18.561 → 3fffffb0: feefeffe feefeffe 3ffe8580 40101039
16:10:18.561 → <<<stack<<<
16:10:18.561 → ⸮⸮⸮PV⸮⸮ET⸮⸮⸮⸮T⸮⸮⸮⸮u⸮U+UZ⸮⸮UT⸮⸮⸮TQT⸮UQ⸮⸮jP⸮V⸮⸮u⸮⸮⸮⸮⸮ZT⸮(E⸮⸮⸮⸮QTE⸮jQTE⸮⸮UU⸮⸮⸮/⸮⸮ISR not in IRAM!
16:10:18.662 →
16:10:18.662 → User exception (panic/abort/assert)
16:10:18.662 → Abort called
16:10:18.662 →
16:10:18.662 → >>>stack>>>
16:10:18.696 →
16:10:18.696 → ctx: cont

I’m using ESP8266 - CP2102, so I’m trying use: USE_SERIAL.begin(74880);

it looks like your esp is reset due to some error. it maybe because of the RBDimmer library. Can you try the basic cayenne esp8266 code.

I have other projects where I use the ESP8266 connected to motion sensors, luminosity sensors, digital relay and It works with cayenne. Is that what you asking?

i am saying it maybe the RBDtimmer library that might be causing the issue.

So, what you suggest? I remove the library?

first, try to check if RBDTimmer library works standalone.

Using this code, as you tell me:

17:08:00.971 → ctx: cont
17:08:00.971 → sp: 3ffffed0 end: 3fffffc0 offset: 0000
17:08:01.007 → 3ffffed0: feefeffe feefeffe feefeffe feefeffe
17:08:01.075 → 3ffffee0: 000000fe 00000000 00000000 00000000
17:08:01.110 → 3ffffef0: 00000000 00000000 00000000 00ff0000
17:08:01.177 → 3fffff00: 5ffffe00 5ffffe00 00000020 00000000
17:08:01.208 → 3fffff10: 00000002 00000005 00000005 4020200a
17:08:01.281 → 3fffff20: 4010072e 3ffef39c 3ffef384 40202020
17:08:01.313 → 3fffff30: 0000001c 00002580 00000005 4020256d
17:08:01.379 → 3fffff40: 00000000 40203021 ffffffff 00000001
17:08:01.415 → 3fffff50: feefeffe 00000001 3ffee5ec 3ffee654
17:08:01.479 → 3fffff60: 3fffdad0 00000000 00000005 4020261c
17:08:01.510 → 3fffff70: 00000000 feefeffe feefeffe 4020125d
17:08:01.578 → 3fffff80: 00002580 0000001c 3ffee35c 40201296
17:08:01.611 → 3fffff90: 3fffdad0 00000000 3ffee614 40201042
17:08:01.678 → 3fffffa0: feefeffe feefeffe feefeffe 40201c60
17:08:01.712 → 3fffffb0: feefeffe feefeffe 3ffe84f0 40101039
17:08:01.780 → <<<stack<<<
17:08:01.814 → ⸮⸮A4⸮⸮>⸮ISR not in IRAM!
17:08:01.914 →
17:08:01.914 → User exception (panic/abort/assert)
17:08:01.948 → Abort called
17:08:01.981 →
17:08:01.981 → >>>stack>>>
17:08:01.981 →

Using the serial monitor in 9600 Baud rate, it’s what shows

which code are you using?

/**************

  • RobotDyn
  • Dimmer Library

  • The following sketch is meant to to define dimming value through potentiometer,
  • The potentiometer values are changing in range from 0 to 1023
  • potentiometer values are converted through the map function to values from 0 to 100% and saved in dimmer.setPower(outVal);
  • Serial.begin is used to display dimming values
  • ---------------------- OUTPUT & INPUT Pin table ---------------------
  • ±--------------±------------------------±------------------------+
  • | Board | INPUT Pin | OUTPUT Pin |
  • | | Zero-Cross | |
  • ±--------------±------------------------±------------------------+
  • | Lenardo | D7 (NOT CHANGABLE) | D0-D6, D8-D13 |
  • ±--------------±------------------------±------------------------+
  • | Mega | D2 (NOT CHANGABLE) | D0-D1, D3-D70 |
  • ±--------------±------------------------±------------------------+
  • | Uno | D2 (NOT CHANGABLE) | D0-D1, D3-D20 |
  • ±--------------±------------------------±------------------------+
  • | ESP8266 | D1(IO5), D2(IO4), | D0(IO16), D1(IO5), |
  • | | D5(IO14), D6(IO12), | D2(IO4), D5(IO14), |
  • | | D7(IO13), D8(IO15), | D6(IO12), D7(IO13), |
  • | | | D8(IO15) |
  • ±--------------±------------------------±------------------------+
  • | ESP32 | 4(GPI36), 6(GPI34), | 8(GPO32), 9(GP033), |
  • | | 5(GPI39), 7(GPI35), | 10(GPIO25), 11(GPIO26), |
  • | | 8(GPO32), 9(GP033), | 12(GPIO27), 13(GPIO14), |
  • | | 10(GPI025), 11(GPIO26), | 14(GPIO12), 16(GPIO13), |
  • | | 12(GPIO27), 13(GPIO14), | 23(GPIO15), 24(GPIO2), |
  • | | 14(GPIO12), 16(GPIO13), | 25(GPIO0), 26(GPIO4), |
  • | | 21(GPIO7), 23(GPIO15), | 27(GPIO16), 28(GPIO17), |
  • | | 24(GPIO2), 25(GPIO0), | 29(GPIO5), 30(GPIO18), |
  • | | 26(GPIO4), 27(GPIO16), | 31(GPIO19), 33(GPIO21), |
  • | | 28(GPIO17), 29(GPIO5), | 34(GPIO3), 35(GPIO1), |
  • | | 30(GPIO18), 31(GPIO19), | 36(GPIO22), 37(GPIO23), |
  • | | 33(GPIO21), 35(GPIO1), | |
  • | | 36(GPIO22), 37(GPIO23), | |
  • ±--------------±------------------------±------------------------+
  • | Arduino M0 | D7 (NOT CHANGABLE) | D0-D6, D8-D13 |
  • | Arduino Zero | | |
  • ±--------------±------------------------±------------------------+
  • | Arduino Due | D0-D53 | D0-D53 |
  • ±--------------±------------------------±------------------------+
  • | STM32 | PA0-PA15,PB0-PB15 | PA0-PA15,PB0-PB15 |
  • | Black Pill | PC13-PC15 | PC13-PC15 |
  • | BluePill | | |
  • | Etc… | | |
  • ±--------------±------------------------±------------------------+
    */

#include <RBDdimmer.h>//

//#define USE_SERIAL SerialUSB //Serial for boards whith USB serial port
#define USE_SERIAL Serial
#define outputPin 12
#define zerocross 5 // for boards with CHANGEBLE input pins

dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
//dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int outVal = 0;

void setup() {
USE_SERIAL.begin(9600);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
}

void loop()
{
outVal = map(analogRead(0), 1, 1024, 100, 0); // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
USE_SERIAL.println(outVal);
dimmer.setPower(outVal); // name.setPower(0%-100%)
}

i tried the code with my nodemcu and same result. what are using the library for?

I’m just using the code you suggested.
What changes should I do?

I just want to use this dimmer: https://robotdyn.com/ac-light-dimmer-module-1-channel-3-3v-5v-logic-ac-50-60hz-220v-110v.html
With ESP8266 - CP2102 NodeMCU V3 Lua, trough a slider widget on cayenne platform to control the brightness/intensity of a lamp.

there is nothing i can do if the librray is not supported. Try searching for similer library and see if their compatiable with esp8266

There’s at least two projects that sucessfully used a dimmer, to control a lamp intensity, trough cayenne dashboard:

How is it not supported?

but the hardare used is not same.

They both use TRIAC to control the brightness of the lamp, it should be equal.

if same then give it a try.

Hello,

I managed to control the intensity of my lamp sucessfuly trought Arduino IDE serial monitor (by manualy insert values in it), using:

And: ESP8266 - CP2102 NodeMCU V3 Lua

How can I now use a cayenne dashboard widget (slider) to control the lamp this way?

The code:

#include “hw_timer.h”
const byte zcPin = 12;
const byte pwmPin = 13;

byte fade = 1;
byte state = 1;
byte tarBrightness = 255;
byte curBrightness = 0;
byte zcState = 0; // 0 = ready; 1 = processing;
void ICACHE_RAM_ATTR zcDetectISR ();
void ICACHE_RAM_ATTR dimTimerISR ();
void setup() {
Serial.begin(115200);
pinMode(zcPin, INPUT_PULLUP);
pinMode(pwmPin, OUTPUT);
attachInterrupt(zcPin, zcDetectISR, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
hw_timer_init(NMI_SOURCE, 0);
hw_timer_set_func(dimTimerISR);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()){
int val = Serial.parseInt();
if (val>0){
tarBrightness =val;
Serial.println(tarBrightness);
}

}

}

void dimTimerISR() {
if (fade == 1) {
if (curBrightness > tarBrightness || (state == 0 && curBrightness > 0)) {
–curBrightness;
}
else if (curBrightness < tarBrightness && state == 1 && curBrightness < 255) {
++curBrightness;
}
}
else {
if (state == 1) {
curBrightness = tarBrightness;
}
else {
curBrightness = 0;
}
}

if (curBrightness == 0) {
  state = 0;
  digitalWrite(pwmPin, 0);
}
else if (curBrightness == 255) {
  state = 1;
  digitalWrite(pwmPin, 1);
}
else {
  digitalWrite(pwmPin, 1);
}

zcState = 0;

}

void zcDetectISR() {
if (zcState == 0) {
zcState = 1;

if (curBrightness < 255 && curBrightness > 0) {
  digitalWrite(pwmPin, 0);
  
  int dimDelay = 30 * (255 - curBrightness) + 400;//400
  hw_timer_arm(dimDelay);
}

}
}