-1

I am using the DMXSerial library to receive a value between 0-255 on a certain DMX channel. However the received value flips between 0 and the value I am expecting to receive. I could debug this with the Serial monitor but also with blinking LEDs.

My wireup uses a Leonardo and MAX485 exactly like in this picture taken from: https://wltd.org/posts/arduino-dmx-to-rgbw-led-with-max485

My code:

#include <Arduino.h>
#include <DMXSerial.h>

const int DmxChannel = 7;    
uint8_t lastData = 0;    
bool pinOn = true;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  DMXSerial.init(DMXReceiver);
  Serial.begin(9600);
}

void loop()
{    
  if (DMXSerial.dataUpdated())
  {
    uint8_t data = DMXSerial.read(DmxChannel);
    Serial.println(data);
    if (data != lastData)
    {
      pinOn = !pinOn;
      lastData = data;
    }
    DMXSerial.resetUpdated();
  }

   pinMode(LED_BUILTIN, pinOn?HIGH:LOW);    
}

This results in the LED blinking and printing alternating 0 and the expected value, even though the value sent on the DMX channel is constant 42. e.g:

0
42
0
42
0
42
...

I have also tried putting a 100Ohm resistor between the two XLR endpoints but it doesn't seem to make any difference.

10
  • 1
    There is likely a valid zero valued byte on the line the way you are reading. Try to figure when the byte comes in and also check your serial bit settings (stop bits, etc)
    – Abel
    Jan 6 at 16:45
  • alternating 0 and the expected value ... maybe your expectation is incorrect ... what is being sent? ... byte or int?
    – jsotola
    Jan 6 at 17:37
  • @Abel thanks, could you elaborate on the serial bit settings? Not fully sure if this is part of my code or that SerialDMX library I am using.
    – clamp
    Jan 6 at 18:50
  • @jsotola Thanks, it sends the value 42 on the DMX channel 7. Afaik DMX values are in range of 0 to 255, so i guess it fits in byte and int type.
    – clamp
    Jan 6 at 18:51
  • int data type is usually longer that a byte data type ... two bytes, or more ... what is sending the values?
    – jsotola
    Jan 6 at 19:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.