Libraries not working along

Hey there!

I am trying to use the DMXSerial2.h library, which uses the Serial to send the DMX data to the shield.

I would like to also use the SevenSeg.h library, but those don't work along. I am asuming that is because both libraries are using the serial. Is there a way to built around this problem? I can include the code if needed :slight_smile:

Thanks in advance!!

Post a link to where you got the libraries from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Hans-Adolf:
but those don't work along.

Please explain exactly what you mean by "don't work". Are you encountering a compilation error or does the code compile and upload fine, but then not work as expected?

The SevenSeg is downloadable here:
https://github.com/sigvaldm/SevenSeg/archive/master.zip

The DMXSerial2 (by Matthias Hertel) is installed via Manage Libraries.

pert:
Please explain exactly what you mean by "don't work". Are you encountering a compilation error or does the code compile and upload fine, but then not work as expected?

When compiling, I get this error:

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':

(.text+0x0): multiple definition of `__vector_25'

libraries\DMXSerial\DMXSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

c:/users/nicoas/appdata/local/arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':

(.text+0x0): multiple definition of `__vector_26'

libraries\DMXSerial\DMXSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

Thank You!

Please post your sketch. Also, which board are you compiling for?

pert:
Please post your sketch.

#include <DMXSerial.h>

#include <SevenSeg.h>

//#include <DMXSerial2.h>
//#include <rdm.h>
//#include <Wire.h>
//#include <EEPROM.h>


SevenSeg disp(6,7,8,9,10,11,12);
const int numOfDigits=4;
int digitPins[numOfDigits]={2,3,4,5};


////BUTTONS//////
const int Button1 = 24; // DMX-Button (red)
const int Button2 = 22; // Change-Button (green)
unsigned long lastDebounceTime1 = 0;  // the last time the output pin was toggled
unsigned long debounceDelay1 = 50;    // the debounce time; increase if the output flickers
int buttonState1=HIGH;             // the current reading from the input pin
int lastButtonState1 = LOW;   // the previous reading from the input pin
byte button1 = 0;  // becomes 1 if pressed
unsigned long lastDebounceTime2 = 0;  
unsigned long debounceDelay2 = 50;
unsigned long buttonCounter2 = 1000;
int buttonState2=HIGH;
int lastButtonState2 = LOW;
byte button2 = 0;

////GREEN BUTTON 5 SEC CHECK////
unsigned long keyPrevMillis = 0;
const unsigned long keySampleIntervalMs = 25;
byte longKeyPressCountMax = 80;    // 80 * 25 = 2000 ms
byte longKeyPressCount = 0;
byte prevKeyState = HIGH;        // button is active low
const byte keyPin = 22;            // button is connected to pin 2 and GND

////DMX////
int dmx = 512;

////MENU////
byte menu=0;

void setup() {
  
  ////DEBUG////
  Serial.begin(9600);

  ////DISPLAY////
  disp.setDigitPins(numOfDigits,digitPins);
  disp.setDPPin(13);
  for(int startupwait=0; startupwait<=30; startupwait++) {
    disp.write("8.");
  }
  for(int startupwait=0; startupwait<=30; startupwait++) {
    disp.write("88.");
  }
  for(int startupwait=0; startupwait<=30; startupwait++) {
    disp.write("888.");
  }
  for(int startupwait=0; startupwait<=30; startupwait++) {
    disp.write("8888.");
  }
  
  ////DMX////
//  DmxSimple.usePin(23);
//  DmxSimple.maxChannel(24);
  
  ////BUTTONS////
  pinMode(keyPin, INPUT_PULLUP);
  pinMode(Button1, INPUT_PULLUP);

}

void loop() {
  Serial.println("MENU 0");
//  DmxSimple.write(1,0);
  disp.write(dmx);
  buttoncheck();
  longpresscheck();
  dmxpresscheck();
  
}
 void buttoncheck(){
int reading1 = digitalRead(Button1);
  button1=0;
  if (reading1 != lastButtonState1) { // reset the debouncing timer
    lastDebounceTime1 = millis();
  }
  if ((millis() - lastDebounceTime1) > debounceDelay1) { // whatever the reading is at, it's been there for longer than the debounce
      if (reading1 != buttonState1) {
      buttonState1 = reading1; // only toggle the LED if the new button state is HIGH
      if (buttonState1 == LOW) {
        button1=1;
        Serial.println("RED (DMX)");
      }
    }
  }
  lastButtonState1 = reading1;
  
  int reading2 = digitalRead(Button2);
  button2=0;
  if (reading2 != lastButtonState2) {
    lastDebounceTime2 = millis();
  }
  if ((millis() - lastDebounceTime2) > debounceDelay2) {
    if (reading2 != buttonState2) {
      buttonState2 = reading2;
      if (buttonState2 == LOW) {
        button2=1;
        Serial.println("GREEN (SET)");
      }
    }
  }
  lastButtonState2 = reading2;
}



////DMXPRESS////
void dmxpresscheck(){
if (button1=1){
//    DmxSimple.write(1, 255);
  }
  if (button2=1){
    //
  }
}


////GREEN BUTTON 5 SEC PRESS////
void longpresscheck(){
    if (millis() - keyPrevMillis >= keySampleIntervalMs) {
      keyPrevMillis = millis();
      
      byte currKeyState = digitalRead(keyPin);
      
      if ((prevKeyState == HIGH) && (currKeyState == LOW)) {
          keyPress();
          menu=0;
      }
      else if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
          keyRelease();
          menu=0;
      }
      else if (currKeyState == LOW) {
        menu=2;
        while(menu==2){
        longKeyPressCount++;
        int keycounter=0;
        if (longKeyPressCount>40){
          Serial.println("MENU 2");
          keycounter=1;
        }
        if (longKeyPressCount>80){
          keycounter=2;
        }
        if (longKeyPressCount>120){
          keycounter=3;
        }
        switch(keycounter){
          case 1:
            disp.clearDisp();
            disp.write("SET");
          break;
          case 2:
            disp.clearDisp();
            disp.write("ADD.");
          break;
          case 3:
            
            setdmx();  
          break;
        }
      }
    }      
  prevKeyState = currKeyState;
  }
}



// called when button is kept pressed for less than 2 seconds
void shortKeyPress() {
    Serial.println("short");
}


// called when button is kept pressed for more than 2 seconds
void longKeyPress() {
    Serial.println("long");
    
}


// called when key goes from not pressed to pressed
void keyPress() {
    Serial.println("key press");
    longKeyPressCount = 0;
}


// called when key goes from pressed to not pressed
void keyRelease() {
    Serial.println("key release");
    
    if (longKeyPressCount >= longKeyPressCountMax) {
        longKeyPress();
    }
    else {
        shortKeyPress();
    }
}





void setdmx() {
  menu=1;
  while (menu==1){
    Serial.println("MENU 1");
    buttoncheck();
    disp.write(dmx-30); 
    if (button1==1){
      menu=0;
    }
  }
}

pert:
Please post your sketch. Also, which board are you compiling for?

I am compiling for the Mega2560 :slight_smile:
Thank You for your help!!

Hans-Adolf:

#include <DMXSerial.h>

You said you were using the DMXSerial2 library.

Anyway, I think the problem has absolutely nothing to do with the SevenSeg library. It's caused by using DMXSerial2 library and Serial at the same time. Here's a minimal demonstration:

#include <DMXSerial2.h>
void setup() {
  Serial.begin(9600);
}
void loop() {}

Hans-Adolf:
I am compiling for the Mega2560 :slight_smile:

Then you can edit DMXSerial2.cpp to use Serial1:

// For using the serial port 1 on a Arduino MEGA 2560 board, enable the DMX_USE_PORT1 definition.
// #define DMX_USE_PORT1

Thank you guys so much!!!

pert:
You said you were using the DMXSerial2 library.

Oooops, I was messing around with the DMXSerial to find out if it changes anything and forgot to change it back.. :confused:

pert:
Anyway, I think the problem has absolutely nothing to do with the SevenSeg library. It's caused by using DMXSerial2 library and Serial at the same time.

Deactivated all Serial. Sadly, that didn't help :frowning:

oqibidipo:
Then you can edit DMXSerial2.cpp to use Serial1

That worked for me, thank you sooooo much!!!