Dimmer_light.h and Ethernet.h librairies not working together

Hi Everyone,

I made some test with ethernet.h first and then with dimmer_light only. I can do what I want in both cases. But I try to use them at the same time, the webserver is no more working.
In fact, as soon as I add the command line: DimmableLight::begin(); , the webserver is no more working well.

Can someone help me to fix it ?
Do I have to use other librairies ?

Thank you for your help.


// Include the web server
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoSTL.h>
#include <dimmable_light.h>


//*******************************************
//*******************************************
//     DECLARATION
//*******************************************
//*******************************************

//*******************************************
//     DIMMER MANAGER
//*******************************************
const int syncPin = 2; //zero pin  Set the Zero Cross pin, calling the static method setSyncPin:
const int thyrMur = 3; // command pin pour la lumière contre le mur
const int thyrPremier = 4; // command pin pour la lumière du palier du premier

DimmableLight lightMur(thyrMur);
DimmableLight lightPremier(thyrPremier);

//*******************************************
//     WEB SERVER 
//*******************************************
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
byte mac[] = { 0x95, 0x8F, 0x91, 0xEF, 0xA2, 0x98 };
IPAddress ip(192,168,1,92);
EthernetServer server(8090);

//*******************************************
//     OTHER VARIABLES
//*******************************************

char PARM = ' ' ;
char * PARMALL ;

  int DECOUP = 32;
  int TMAX = 2000;
  float iDelay = 20;
//*******************************************
//     DANCE PARAM
  
  int TEMPO = 90; // in BPM 
  unsigned long PROCTIME; // in milliseconds --  90 BPM = 90/60 BPS = 90/60000 BPmillis
//  unsigned long MUSICTIME;  
  
//*******************************************
//*******************************************
//     SETUP
//*******************************************
//*******************************************

void setup() {
  pinMode(5, OUTPUT); // Inter lumière plafond salon
  pinMode(6, OUTPUT); // Inter lumière mur salon
  pinMode(7, OUTPUT); // Inter lumière premier palier

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

//*******************************************
//     DIMMER
//*******************************************
  DimmableLight::setSyncPin(syncPin);
  
  // VERY IMPORTANT: Call this method to activate the library
  DimmableLight::begin();
  lightMur.setBrightness(110);

  Serial.println("Done!");

//*******************************************
//     WEB SERVER 
//*******************************************

  // start the Ethernet connection and the server:    
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());


//*******************************************
//     OTHER
//*******************************************
  
//  PROCTIME = millis();
  PARM = ' ';
//  pmRepos();
  Serial.println("Initialisation finie"); 
  
} // Fin SETUP

void loop() {
  char req[1024];
  int index = 0;
   // listen for incoming clients  
  EthernetClient client = server.available();

  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        //Serial.print("read : ");
        //Serial.println(index);
        req[index++] = c;
        
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
        
          req[index] = 0; 
          index=0;
          
          PARM  = req[5] ;
          PARMALL = req;
           
          Serial.print("PARM 1: ");
          Serial.println(PARM);

          if (PARM == 'a')
          {    Serial.println("on a recu un a");
              //manuallyMove(PARMALL); 
               Serial.println("on sort de manually"); }
     
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
	  //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.print("Requete recue : ");
          client.println(req[5]);
          // output the value of each analog input pin
          client.println("</html>");
          break;
        }
       // Serial.println("WHILE RECEIVE");
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    
    // give the web browser time to receive the data
    delay(1000);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
 
}

I see a problem in the 47th line, but then again I am looking at the wrong code, you forgot to post it following forum guidelines.

Hi Gilshultz,

Thank you for your answer. Sorry for that, it's done now.

Thx

Hi,

I found a solution.

Dimmer_light and RBDimmer are not compatible with ethernet librairy.

But with Circuitar/Dimmer (GitHub - circuitar/Dimmer: Arduino library to control dimmable lamps and other AC loads (110V / 220V).) I have no more issue.

Thank you

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

Hi Reyure,
I have tested the library Dimmable Light (v1.5.2) with Arduino Ethernet Shield (lib version 2.0.2), and I confirm you that these libraries are compatible. Of course, you must use them correctly: in particular, the Ethernet Shield uses pins 11, 12, 13, 10 (for ethernet) and 4 (for microSD card), so these pins aren't available to control dimmers. However, in this specific case, you can use pin 4 since you are not using the microSD. The main issue is the following line:

char req[1024];

Remember that Ethernet library requires a generous amount of memory. I have tried to compile your code, and the compiler tells:

Global variables use 1057 bytes (51%) of dynamic memory, leaving 991 bytes for local variables. Maximum is 2048 bytes.

So, there isn't enough space to allocate 1024 bytes of RAM and you should resize that buffer.