Receive DMX-512 with an Arduino

Part I: ProloguePart II: InstructionsPart III: Known Limitations, Notes, and the Code

You Will Need:

  • A copy of the latest release and the modified wiring_serial.c or HardwareSerial.cpp file.  See the instructions for what to do with the files.
  • An Arduino with an Atmega168 or Atmega368 processor.  Because of the timing-sensitive nature of DMX-512, some of the code had to be optimized by referring to particular registers on the Atmega168/368.  The code can easily be adapted to other processors, though.
  • An RS-485 to Serial Transceiver, such as the MAX485 or the TI 75176.  They’ll run you about $1, the MAX485 is a little more but it apparently has some kind of fancy overvoltage protection, so I used that.
  • A breadboard and some wires, also a 150Ω resistor to terminate the DMX line if necessary.

Instructions:

DMX uses a twisted pair of signal wires with opposite polarity to transmit information per RS-485.  However, your Arduino needs a serial signal, with a pin brought high for one and low for zero.  To convert between these protocols, you’ll need to wire up your MAX485 or 75176 in the following way:

Schematic Rev2

Here are some pictures which may help you:

The prototype from the left.

The prototype from the left.


The prototype from the right.

The prototype from the right.

Note 1: Starting with Rev11 of the software, I adjusted the pin layout slightly for better routing on the DMX I/O Shield.  The two gray wires in the above photos that are plugged into pins 3 and 4 should be plugged into pins 2 and 3, respectively, if you’re using the latest software.

Note 2: I’m using the Arduino protoshield here, which I highly recommend, they’re handy.  If you don’t have one, the pin layout is the same as if you ran directly into the Arduino board.

Note 3: if you want to retain the use of pins 1, 4, and 5, at the cost of being able to transmit as well as receive, you can connect the corresponding pins on the MAX485 to the ground on the Arduino board.  I’ve done it this way for possible future RDM functionality ;).

One Dumb Hack is necessary: rename your currently installed HardwareSerial.cpp file to HardwareSerial.cpp.backup, and put the modified HardwareSerial.cpp from this site in the same directory.  It’s located in:

(Arduino Install Directory)/hardware/cores/arduino/

The reason for this is that the Arduino software defines the USART_RX_vect serial reception interrupt, and includes it in your compiled code, even if you don’t use any serial functions.  This will, I hope, be fixed in a future release, but until it is this is the work-around.  You can read more about the issue here.  Once you’ve uploaded the sketch and it’s working to your satisfaction, you can undo this part to regain your normal serial library functionality.

Finally, fire up the Arduino software, and put what you want the Arduino to do with the received values in the action() loop. The received values are stored in the dmxvalue[] array. The downloaded sketch contains example code to print out each of the values to the serial port, and set PWM pins 5 and 6 to the first and second value in the array, respectively, but this can of course be changed to anything you want.

That’s it, let me know how it works for you!  You may want to keep reading for the Known Limitations, etc.

Go to Section:

  1. Part I: Prologue
  2. Part II: Instructions
  3. Part III: Known Limitations, Notes, and the Code
  4. View All

Pages: 1 2 3


112 Responses to “Receive DMX-512 with an Arduino”

  • ewanuno Says:

    i can confirm that the shield must be unplugged to upload code. on my boards i put a jumper on pin0, or use a 10way dip switch for adressing and use the extra pin to enable/disable the 485 transciever.

    to the people who requested my modifications to Max’s original (and fantastic) code:
    i have recently updated my code for a new project, i’ll post it on my website in the next few weeks.

    now it can use adresses 1- 511,
    3 channels of pwm with p-channel mosfets
    and 3 240v relays!

    Max, i have one problem though, if i disconect the dmx cable, it receives random gibberish.(not before connecting though…)

    ewan.

    does mark after break detection only trip once?

  • Sebastian H. Says:

    Hi
    is there a way to get this working in Arduino 1.0 I have got some trouble to get this working I just wan´t to get my Arduino Bord to recive DMX. There isn´t any other solution on that I think. I think it´s the crappy HardwareSerial.cpp thing that I stuck on

    Many thanks for your Help.

    Sebastian, Hannover Germany

  • Max Says:

    Hi Sebastian,
    I’m sure this is possible, my prior experience has been that the HardwareSerial.cpp changes little if at all from release to release, so you just need to find the lines that conflict and comment them out. But I’ve got so many other projects in the works these days that I wouldn’t expect I’d get to this any time soon. In the meantime, unless there’s some new aspect of the software that you need, you could always use a prior tested release to compile.

    Max

  • Sebastian Says:

    Many Thanks,
    I hav got the clue by using the 0021 release of Arduino no errors while compiling. The new HardwareSerial.cpp seems to be completely different to me 200 lines to 400 lines … I now ran into other cruxes – I opend the three files on arduino and it seems to me that only one sketch is uploading to the board. Maybe you could give me a hint …

  • Sebastian H. Says:

    Hi again,
    it´s working now ! Thank You for your great job ! I testet it with my Open DMX USB with some kind of DMX Software. Some of my desks dosn´t working in fact they send 512 chans.
    MA 12/02 / grandMAUltraLight / LeapFrog 48

  • Bennage Says:

    Sebastian H: any chance you could post your solution to the 1.0 dilema? I’m having the same problem.

  • Thomas Says:

    Just a quick question: will this work on the Mega so I can use the other serial ports to communicate over RS232?

  • Sebastian H. Says:

    @Bennage
    Hi, I just use the older Release Version 0021

  • Christoffer Says:

    i could not find the .cpp so just to anyone that have the same problem i found mine under \arduino-0022\hardware\arduino\cores\arduino

  • Vlad Says:

    Hi, I have a little problem with the DMX code. When I connect the board to the PC through a usb-DMX cable and use the DMX program it works fine but when I connect it to a 6 ch DMX pannel the channels are overlaping and the period between channels fluctuates.
    The signal from the PC doesn’t do that.
    So the question is how I can make it work with that DMX 6 ch pannel?

  • Vlad Says:

    I forgot to mention! Very good job! and Thanks! for the code.

  • Riley Kolus Says:

    Christoffer, I think i am just being very dumb right now, but I don’t know how to access any of these files, my computer doesn’t seem to think they exist, any tips on how to get to them?

Leave a Reply