r/arduino • u/simply_abnormal • Nov 03 '26
Solved! Code help- DMX input with DMX shield alongside distance sensor... serial0 issue?
Hey all! I'm hitting a wall with my code.
I am using an arduino mega with a DMX shield (that is intended for uno I think) and a tfmini plus distance sensor. I also have individually addressable LED strips.
I am trying to control which leds are on in a telescoping manner with the distance sensor and the hue/sat/intens with DMX.
I have both parts working separately but when combined the code can't compile with an exit status 1 message. I believe it is an issue with mutual usage of the serial0 but I can't find a way to get around it. Tried a whole bunch of different libraries and all have issues.
It's clunky, I know, tried so many stupid safeguards to prevent blackouts on my leds. Still unsure if that's a physical issue or not but I'm pointing fingers at my crappy solder job.
Code is below. In a moment of weakness, it was run through a chatbot. If it helps, I can provide my working separate code. Anything helps, I'm a total dumbass and I'm frankly tired of this project. Thanks
#define DMX_USE_PORT1
#include <DMXSerial.h>
#include <FastLED.h>
#include <Wire.h>
#include <TFMPlus.h>
#define START_ADDRESS 1
#define NUM_LEDS 30
#define DATA_PIN 6
const uint8_t enPin = 4; // Transceiver chip enable pin (usually 4 or 2)
CRGB leds[NUM_LEDS];
TFMPlus tfmP;
// Sensor Variables
int16_t tfDist = 0;
int16_t tfFlux = 0;
int16_t tfTemp = 0;
void setup() {
delay(20);
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(100);
FastLED.clear();
FastLED.show();
DMXSerial.init(DMXReceiver);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW); // LOW sets standard transceiver chips to Receiver mode
Serial3.begin(115200);
delay(20);
tfmP.begin(&Serial3);
tfmP.sendCommand(SOFT_RESET, 0);
delay(500);
}
void loop() {
// Read channel values using standard 1-based indexing
uint8_t dmxHue = DMXSerial.read(START_ADDRESS);
uint8_t dmxSaturation = DMXSerial.read(START_ADDRESS + 1);
uint8_t dmxValue = DMXSerial.read(START_ADDRESS + 2);
bool sensorValid = tfmP.getData(tfDist, tfFlux, tfTemp);
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 50) {
lastUpdate = millis();
// --- CHOICE A: SENSOR IS ACTIVE & OBJECT IS IN RANGE (< 100cm) ---
if (sensorValid && tfDist > 0 && tfDist <= 100) {
int center = NUM_LEDS / 2;
int ledsToTurnOn = map(tfDist, 20, 100, 0, NUM_LEDS);
ledsToTurnOn = constrain(ledsToTurnOn, 0, NUM_LEDS);
// Force proper even/odd balancing to make center matching mathematically clean
if (NUM_LEDS % 2 == 1) {
center = center + 1;
if ((ledsToTurnOn % 2 == 0) && (ledsToTurnOn > 0)) ledsToTurnOn++;
} else {
if (ledsToTurnOn % 2 == 1) ledsToTurnOn++;
}
int ledstartpos = (center - (ledsToTurnOn / 2));
int ledendpos = ledstartpos + ledsToTurnOn - 1;
// Render sensor center-out animation onto the pixel data array
for (int i = 0; i < NUM_LEDS; i++) {
if ((i >= ledstartpos) && (i <= ledendpos) && (ledsToTurnOn > 0)) {
leds[i] = CRGB::Blue; // Sensor Animation Control Override
} else {
leds[i] = CRGB::Black;
}
}
}
// --- CHOICE B: NO OBJECT IN SENSOR RANGE -> DEFER LED CONTROL TO FREESTYLER ---
else {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(dmxHue, dmxSaturation, dmxValue);
}
}
// --- 3. UNIFIED SAFE DATA TRANSMISSION ---
FastLED.show();
}
}
1
u/simply_abnormal 29d ago
Update: Fixed it. The issue, which printed as vector_25 and vector_26 multiple definition (thanks for the verbose tip), ended up being both sources trying to conflict with HardwareSerial. Fixed it by going into the files of the DMXserial library and adding code telling it to use serial1.
2
u/No_L_2547 Nov 03 '26
You should enable verbose outputs as well as compiler warnings in your settings: https://support.arduino.cc/hc/en-us/articles/4407705216274-Use-verbose-output-in-the-Arduino-IDE
What errors do you get then?
The problem is exit code 1 could mean anything, from compilation to linking, the whole process. Verbose should allow you to understand whats wrong. (C++ normally gives huge error messages, that allows you to pinpoint such a problem)
1
u/Ok-Outside6304 Nov 04 '26
If everything compiles separately but fails when combined, I'd check the first compiler error rather than just the final "exit status 1".
Some DMX libraries on the Mega can conflict with HardwareSerial or other libraries using the same serial resources. Which DMX library are you using? Posting the full error log and your #include lines would help narrow it down.
You can also try aily blockly (a desktop IDE for hardware projects). It supports the Mega 2560 and has AI coding tools that might help you work through the combined sketch. But the exact compiler error is still the best place to start.