B4R Question [SOLVED] DMX Error multiple definition of '__vector_18'

rwblinn

Well-Known Member
Licensed User
Longtime User
EDIT: SOLVED see post 5.

Got an issue working on a project to control DMX lights using the DMX512 protocol.
B4R 4.0, Arduino UNO, CQRobot DMX Shield Arduino.

Started to explore how to use the Conceptinetics library with B4R.
Prior developing with B4R tested a simple sketch with the Arduino IDE 2.

STEP 1: Simple C++ sketch is working fine.
Arduino Test Sketch:
#include <Conceptinetics.h>
#define DMX_MASTER_CHANNELS 10
#define RXEN_PIN 2
DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );
void setup() { 
    dmx_master.enable ();
    dmx_master.setChannelValue ( 2, 127 );
    dmx_master.setChannelValue ( 4, 50 );
}
void Loop() {}

STEP 2: B4R test with Inline C with ERROR
B4R Test Code:
Sub Process_Globals
    Public Serial1 As Serial
    Private Channel As Int    'ignore 1-10
    Private Value As Byte    'ignore 0-255
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    RunNative ("initialize", Null)
    Set_Channel_Value (2, 127)
    Set_Channel_Value (4, 50)
End Sub

private Sub Set_Channel_Value(ch As Int, val As Byte)
    Channel = ch
    Value = val
    RunNative("setchannelvalue", Null)
End Sub

#if C
#include <Conceptinetics.h>
#define DMX_MASTER_CHANNELS 10
#define RXEN_PIN 2
DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );
void initialize (B4R::Object* o) {
  dmx_master.enable ();
}
void setchannelvalue(B4R::Object* o) {
      dmx_master.setChannelValue ( b4r_main::_channel, b4r_main::_value );
}
#End If

ISSUE
When compiling & linking, the error "multiple definition of '__vector_18'" occurs.
It seems there is a double definition of hardware serial 0. The error happens as soon as Conceptinetics.h is included.
Any help appreciated.

B4R IDE Log Snippet
B4X:
Linking everything together...
"C:\\Users\\NAME\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E/src.ino.elf" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\B4RArduino.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\B4RCore.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\B4RStream.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\Scheduler.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\b4r_main.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\sketch\\src.ino.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E\\libraries\\Conceptinetics\\Conceptinetics.cpp.o" "C:\\Users\\rwbli\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E/..\\..\\cores\\arduino_avr_uno_e161e75f098ed477e196c7c14c088163\\core.a" "-LC:\\Users\\NAME\\AppData\\Local\\Temp\\arduino\\sketches\\617D7F3746514C7DCD8267DC8C2F520E" -lm
HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_18'
C:\Users\NAME\AppData\Local\Temp\arduino\sketches\617D7F3746514C7DCD8267DC8C2F520E\libraries\Conceptinetics\Conceptinetics.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Error during build: exit status 1
 
Last edited:

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks for the hints.

Got a step further:
Have taken the generated Arduino project and add to all serial related the conditional B4R_SERIAL (basically 2 missing).
In B4RDefines.h comment out the #define B4R_SERIAL.
The project compiles in the Arduino IDE and runs as expected after uploading.

Fixes Applied
In the B4R Code undefined B4R_SERIAL
B4X:
#DefineExtra: #undef B4R_SERIAL

In the B4R Libraries folder rCore changed following files to add the missing #ifdef B4R_SERIAL

scheduler.cpp:
void Scheduler::printList(){
        ScheduledNode* n = first->next;
        while (n != last) {
            #ifdef B4R_SERIAL
            ::Serial.println(n->eventTime);
            #endif
            n = n->next;
        }
    }
B4RCore.cpp:
void Common::LogHelper(int length, ...) {
        va_list arguments;
        va_start ( arguments, length );
        Object o[length];
        BR::varArgsToObject(o, length, arguments);
        for (int i = 0;i < length;i++) {
            #ifdef B4R_SERIAL
            B4R::B4RStream::Print(&::Serial, &o[i]);
            #endif
        }
        va_end ( arguments );
        #ifdef B4R_SERIAL
        ::Serial.println();
        if (AUTO_FLUSH_LOGS)
            ::Serial.flush();
        #endif
    }
 
Last edited:
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
[SOLVED] Explored further and found a solution using the CQRobot DMX shield with the Conceptinetics library:
  • Changed the hardware from Arduino UNO to Arduino MEGA
  • Changed the Conceptinetics serial port from 0 to 1 in conceptinetics.h = use hardwareserial1 instead hardwareserial0
  • Set jumper wires from MEGA pin 18 TX1, 19 RX1 to the DMX shield pins 3 & 4
  • Set DMX shield jumper to RX1-io & TX-io instead UART
  • Removed the #DefineExtra: #undef B4R_SERIAL
  • Added Serial1 to B4R code & asyncstream handling (hardwareserial0)
  • Data communication between B4J and B4R uses B4RSerializer with an array holding 2 items channel & value
  • Created B4J test program to send DMX channel & value to the MEGA running B4R program as a DMX Controller (set the light)
  • Developed a simple B4R library rConceptinetics (to replace inlinec) just to set channel values only in master mode for hardwareserial1
  • Test setup running OK
With this proof-of-concept a DMX512 light (tested with LSPA36RC)) with 7 channels can be controlled by B4R receiving serialized commands from B4J via serial line.

Will share more when the solution is ready to control multiple DMX512 lights with different channels depending model .
 
Last edited:
Upvote 0
Top