The good news is that DMX is dead simple at a protocol level, so it's hard to find n easier place to start, at least for a simple receiver. RDM responders are more complicated, but you probably don't much care about that for such a simple device, especially as a one-off.
A couple of random tips off the top of my head, from having built quite a number of DMX devices:
- Use a protected, failsafe RS485 transceiver. Failsafe in this context means that the receiver will give you an idle output when the line is in an invalid state (like it's undriven or shorted).
- Don't terminate the receiver, unless it's switchable termination.
- Isolation is nice, but not really required on small, limited installations, I've done a number of projects with no isolation, as long as the system is otherwise in good condition you'll be fine.
- If you do isolate your receiver, don't use optocouplers, use a digital isolator IC. You can get a single IC that has three isolated channels in one direction and one in the other direction which is perfect for driving the DE, RE, and DI lines and receiving the RO line from the transceiver.
- ALWAYS CHECK THE START CODE in your receiver! If it ain't null, it ain't channel data and you should probably ignore it. People who don't check the start code make RDM unworkable and that makes me really sad.
- If you are going to the trouble of isolating, protect the data lines as well.
From a programming perspective, as I said the protocol is pretty simple.
- Wait for the USART framing error flag to be set, when it is you're in the DMX break period
- The next byte that you receive will be the start code. check to make sure it's null.
- If the start code is non-null, then you are receiving something other than channel data and should ignore everything until the next break.
- If the start code is null, then the next byte will be the first byte of channel data. If your start address is N, then wait for N-1 bytes to go by before you start capturing data
- Once you start getting bytes you care about, start copying them to wherever
- Once you've received as many bytes as you need, ignore the rest until the next break.
One complication to watch out for is that if you are using multiple bytes together, like as a 16-bit channel, you may need to double buffer or otherwise control when the received data is transferred to the consuming code so that you don't wind up mashing data from more than one DMX packet together.