Difference between revisions of "Dmx interface for raspberry pi"

From BitWizard WIKI
Jump to: navigation, search
(all raspberries)
(output mode)
(47 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
= Introduction =
  
= Introduction =
+
[[File:DMX_case_complete.jpg‎|thumb|DMX with case]]
 +
 
 +
The [http://www.bitwizard.nl/shop/DMX-interface-for-Raspberry-pi '''DMX interface for raspberry pi'''] allows you to interface a raspberry pi with DMX hardware.
  
The '''DMX interface for raspberry pi''' allows you to interface a raspberry pi with DMX hardware.
+
There is also [http://www.bitwizard.nl/shop/DMX-interface-for-Raspberry-pi-with-usb-(FT245RL) a version "with FT245"]. That version adds the option to use your raspberry pi with our board as an Enttec USB Pro compatible device from another computer (raspberry pi or PC, Windows or Linux)
  
There is also a version "with FT245" That version adds the option to use your raspberry pi with our board as an Enttec USB Pro compatible device from another computer (raspberry pi or PC, Windows or Linux)
+
If you select "for pi zero" we give you an extra 40 pin male header and do not solder the matching female header onto our board. You can then chose several configurations yourself. The one I prefer is to have the male headers on the zero on the bottom, and the female on our board on the top. Keep in mind that if you arrange for the pi to stick out from under or above our board, the pinout is going to be wrong. So you can't put the connectors on both boards on top, and then flip one to make the connection.
  
= software =
+
= Software =
  
 
There are several software packages that can be used with your '''DMX interface for Raspberry pi'''.
 
There are several software packages that can be used with your '''DMX interface for Raspberry pi'''.
  
First there are QLC and OLA. These are packages that run on Linux on the raspberry pi and allow you to control a DMX Universe.  
+
First there are QLC+ and OLA. These are packages that run on Linux on the raspberry pi and allow you to control a DMX Universe.  
  
 
Second, there are several packages by Arjan van Vught that use the raspberry pi "bare metal".  
 
Second, there are several packages by Arjan van Vught that use the raspberry pi "bare metal".  
 +
 +
See: http://www.raspberrypi-dmx.com/
  
  
== QLC and OLA ==
+
== QLC+ and OLA ==
  
 
Don't forget to remove the console and getty from the serial port that the DMX inteface is using.  
 
Don't forget to remove the console and getty from the serial port that the DMX inteface is using.  
Line 22: Line 27:
  
  
=== QLC ===
+
=== QLC+ ===
todo
+
 
 +
Harold van Hulten wrote a nice "howto". See: http://www.udenix.nl/2016/how_did_i/rpi2dmx/
 +
 
 +
QLC+ 's home is at: http://www.qlcplus.org
 +
 
 +
 
 +
==== our tests ====
 +
 
 +
To build qlc+ on raspberry pi with support for our board, you need to follow the howto at:
 +
  https://github.com/mcallegari/qlcplus/wiki/Linux-build-Qt5
 +
but with one addition:
 +
  apt-get install libqt5serialport5-dev
 +
 
 +
needs to be added after installing the prerequisites. Next, it seems the uart device is disabled by default: edit
 +
  plugins/plugins.pro
 +
 
 +
to remove the hash on the line with "uart" so that it reads:
 +
  !macx:!win32:SUBDIRS += uart
 +
 
 +
Next, you can build and install. Also use raspi-config to disable console output on serial but to enable the hardware. One more thing is to add the disable-bt and uart_clock to config.txt. See elsewhere on this page for the precise instructions.
 +
 
 
=== OLA ===
 
=== OLA ===
 +
 +
==== stretch ====
 +
 +
The distribution ola works on Stretch. ''sudo apt-get install ola'' should do the trick.
 +
 +
Don't forget to disable login on the serial port (raspi-config) and to set init-uart-clock in /boot/config.txt. If you forget that last, you will notice that the "native-uart" option is not available when you try to add the universe.
  
 
==== Jessie ====
 
==== Jessie ====
On raspbian jessie installing OLA is easy: ''apt-get install ola'' should do the trick. The downside is however that it doesn't work :-( .  
+
On raspbian jessie installing OLA is easy: ''sudo apt-get install ola'' should do the trick. <s>The downside is however that it doesn't work :-( . </s>
  
what does work however is:  
+
'''update:''' The simple option seems to work now. :-) '''update2:''' Some hints are that it still doesn't work. :-(
 +
Some have reported success by following the howto at: http://www.raspberrypi-dmx.com/raspberry-pi-dmx512-rdm/ola-on-the-raspberry-pi (which boils down to installing ola 0.10.5 instead of 0.10.1.
 +
 
 +
<span style="color:#808080">
 +
what does work however is:
 +
#sudo apt-get install automake libtool bison flex libcppunit-dev libprotobuf-dev libprotoc-dev protobuf-compiler protobuf-c-compiler uuid-dev libmicrohttpd-dev
 +
sudo apt-get build-dep ola
 
  mkdir ola
 
  mkdir ola
 
  cd ola
 
  cd ola
  https://github.com/OpenLightingProject/ola/archive/0.10.1.tar.gz
+
  wget https://github.com/OpenLightingProject/ola/archive/0.10.1.tar.gz
 
  tar xvfz 0.10.1.tar.gz
 
  tar xvfz 0.10.1.tar.gz
 
  cd ola-0.10.1
 
  cd ola-0.10.1
 +
#libtoolize
 
  autoreconf -i
 
  autoreconf -i
 
  ./configure  
 
  ./configure  
  make -j 5
+
  make -j 5 all
 
  sudo make install
 
  sudo make install
 +
<span style="color:#808080">
 +
There is one little thing about the first two commands here. The first should always work, but if I accidentally missed a package, well.. I missed a package and the build will fail. The second one (with "build-dep" should be more reliable. But before that works, you need to add the sources to your /etc/apt/sources.list file. It's already there, but commented out. Use your favorite editor to do that. (otherwise, try: sudo nano /etc/apt/sources.list )
 +
</span>
  
 
==== wheezy ====
 
==== wheezy ====
Line 50: Line 91:
  
 
Add:  
 
Add:  
  device_tree=bcm2709-rpi-2-b.dtb
+
  dtoverlay=pi3-disable-bt
  
Otherwise, the wrong UART will be used. The "wrong" uart will  
+
to your config.txt file in the /boot directory.
 +
 
 +
Otherwise, the wrong UART will be used. The "wrong" uart (=ttyS0) will  
 
* change baudrate unexpectedly when the CPU feels hot.  
 
* change baudrate unexpectedly when the CPU feels hot.  
 
* I haven't figured out if it CAN do the required baud rate, and/or how to do that.  
 
* I haven't figured out if it CAN do the required baud rate, and/or how to do that.  
  
 
This has the consequence that we've stolen back the good UART from the bluetooth that's present on the PI3.
 
This has the consequence that we've stolen back the good UART from the bluetooth that's present on the PI3.
 +
 +
On the raspberry pi forums there is talk about re-enabling bluetooth at a lower performance level.
  
 
==== all raspberries ====
 
==== all raspberries ====
 +
 +
First you need to disable "other things" on the UART that the DMX board uses.
 +
 +
sudo systemctl disable serial-getty@ttyAMA0.service
 +
 +
and remove "ttyAMA" or "serial0" from /boot/config.txt. (you'll find something like '''console=ttyAMA0,115200''' there, remove that whole '''console=''' entry. Try not to mess up the rest of that line.
 +
  
 
Most importantly: add:  
 
Most importantly: add:  
Line 64: Line 116:
 
to your config.txt file in the /boot directory.  
 
to your config.txt file in the /boot directory.  
  
Next, you need to configure ola to use the native-uart plugin. This is described at: http://www.raspberrypi-dmx.com/raspberry-pi-ola-dmx512-sender
+
Next, you need to configure ola to use the native-uart plugin. It should be as easy as clicking on "add universe" on the ola home page. Somehow we often do not see the plugin active. Sometimes clicking on reload plugins helps, other times we need to restart ola to get the plugin to show up.
 +
 
  
Locate your ola-uartdmx.conf (on some systems I'm told it is in ''/etc/ola/conf/'', on others ''/var/lib/ola/conf/''). Edit it and set enabled to true, set the correct device (ttyS0 on rpi3, ttyAMA0 on
+
Locate your ola-uartdmx.conf (on some systems I'm told it is in ''/etc/ola/conf/'', on others ''/var/lib/ola/conf/'', and in some cases: ''/root/.ola/ola-uartdmx.conf'' or ''/home/pi/.ola/ola-uartdmx.conf''. One of the ways to find out is to look at the -c argument on your running olad.). Edit it and set enabled to true, set the correct device (ttyAMA0), and add ''/dev/ttyAMA0-break = 100'' and ''/dev/ttyAMA0-malf = 100'' . It should then look like:
others), and add ''/dev/ttyAMA0-break = 100'' and ''/dev/ttyAMA0-malf = 100'' . It should then look like:
 
  
 
  /dev/ttyAMA0-break = 100
 
  /dev/ttyAMA0-break = 100
  /dev/ttyAMA0-malf = 100
+
  /dev/ttyAMA0-malf = 24000
 
  device = /dev/ttyAMA0
 
  device = /dev/ttyAMA0
 
  enabled = true
 
  enabled = true
 +
 +
Note that the "malf" (mark after last frame) is set to 24 miliseconds. This is due to a problem with OLA: it writes the data and after that waits for the time specified in "malf". It turns out that the kernel will return from the write before the buffer is flushed. So the malf is measured from close to the START of the frame. Thus if you would enter the normal MALF of 100 microseconds, the next break is attempted after only about three characters have been sent. When the kernel then tries to empty the buffer before issuing the BREAK, it waits way too long. We (bitwizard + ola developers) have not been able to figure out an easy fix. So until then saying "24000" gives reasonable performance. (but once the bug has been fixed, you'll need to adjust this configuration parameter)
 +
 +
==== output mode ====
  
 
Then set the board to output mode. I would recommend creating a small script (''sudo nano /usr/bin/set_dmx_mode; sudo chmod 755 /usr/bin/set_dmx_mode'') :  
 
Then set the board to output mode. I would recommend creating a small script (''sudo nano /usr/bin/set_dmx_mode; sudo chmod 755 /usr/bin/set_dmx_mode'') :  
Line 78: Line 134:
 
  #!/bin/sh
 
  #!/bin/sh
 
  # set_dmx_mode
 
  # set_dmx_mode
 +
pin=18
 +
gpio=/sys/class/gpio/gpio$pin
 
  if [ $# -lt 1 ] ; then  
 
  if [ $# -lt 1 ] ; then  
   echo 'on or off?'
+
   echo "$0 : on or off?"
 
   exit 1
 
   exit 1
 
  fi
 
  fi
 
   
 
   
  if [ ! -d /sys/class/gpio/gpio18 ] ; then  
+
  if [ ! -d $gpio ] ; then  
     echo 18 > /sys/class/gpio/export
+
     echo $pin > /sys/class/gpio/export
 
  fi
 
  fi
  echo out > /sys/class/gpio/gpio18/direction
+
  echo out > $gpio/direction
  echo $1 > /sys/class/gpio/gpio18/value
+
  echo $1 > $gpio/value
  
  
 
then calling the script:  
 
then calling the script:  
  sudo set_dmx_mode 1
+
  sudo /usr/bin/set_dmx_mode 1
  
 
I recommend putting that line in /etc/rc.local so that it gets executed at boot time so you don't have to worry about it. (IIRC there is an "exit 0" in there, so don't put it AFTER that!)
 
I recommend putting that line in /etc/rc.local so that it gets executed at boot time so you don't have to worry about it. (IIRC there is an "exit 0" in there, so don't put it AFTER that!)
 +
 +
Or you can install the gpio utility from wiringpi and use the following command to view the status of all the pins
 +
 +
gpio readall
 +
 +
and to set GPIO 18 (BCM) in output mode
 +
 +
gpio -g mode 18 out
 +
gpio -g write 18 1
 +
 +
also, pin 14 & 15 need to be in the ALT0 mode, if this is not the case use
 +
 +
gpio -g mode 14 alt0
 +
gpio -g mode 15 alt0
  
  
 
Note that the earlier versions of the DMX board have a bug that when the GPIO pin is an input (not driven) it will configure the board as an output. This is not desirable. Newer versions (starting 1.4) will have this "fixed" and the "default" will be "DMX IN" mode.  
 
Note that the earlier versions of the DMX board have a bug that when the GPIO pin is an input (not driven) it will configure the board as an output. This is not desirable. Newer versions (starting 1.4) will have this "fixed" and the "default" will be "DMX IN" mode.  
  
This does mean that you can get away with forgetting about this gpio18 business if you have an older version. (I just realized I was getting away with this.... :-) )
+
This does mean that if you want the board to do output, you can get away with forgetting about this gpio18 business if you have an older version. (I just realized ''I'' was getting away with this.... :-) )
 +
 
 +
= Hardware =
 +
 
 +
== used hardware pins ==
 +
 
 +
The DMX harware uses the 3.3V, 5V, GND, RX, TX and GPIO18 signals. Besides that the non-FTDI version breaks out the SPI bus and I2C bus.
 +
 
 +
== jumper settings ==
 +
 
 +
The jumper block has three (sensible) jumper positions, they can be either on or off.
 +
(We used to deliver the jumpers on the jumper block in say 1-NC, 3-NC, 4-NC: each of the jumpers on just one pin, not connected to another jumper pin. Nowadays we deliver them loose in the bag.)
 +
 
 +
Officially the DMX wire is called a bus. Oficially a bus should be terminated at both ends. Most people think of the DMX bus as coming out of our board and then TO the lamps. So most often our board will be at one end of the bus. In that case you should terminate the bus on our board: Jumper 3-4 mounted. Termination at the SENDING side of the bus is less important than on the opposite end. So if you're just sending DMX data with our board, the termination at our board is not that important. Most people don't bother.
 +
 
 +
Another possible configuration is that you have a few fixtures and then connect to the DMX IN connector on our board, and then another few fixtures on the DMX out. Our board will be in the middle of the bus, and you are then NOT supposed to add a terminator on our board: Do NOT place the 3-4 jumper.
 +
 
 +
With "short" busses, the termination is less important than with longer busses. What is "short" and what is "long" depends on the dataspeed. For example, for "SATA" 30-50cm is normal, 1m would be long. For DMX a few tens of meters is still "short". 
 +
 
 +
The other two jumper positions should be added and removed in tandem. They provide a pullup/pulldown on the DMX databus so that the signal level is defined even when there is noone driving the bus. This is important when you do RDM. I found documentation that specified pullup on one line and pulldown on the other, but also the other way around. If you have trouble with RDM, add the jumpers. If that doesn't make things better, try using a few jumper wires and wire 1-5 and 2-6. If that works better for you, let us know!
 +
 
 +
 
 +
== Case ==
 +
 
 +
There is a case for raspberry pi with DMX board.
 +
 
 +
The assembly instructions have a few pictures.
 +
 
 +
[[Assembling_the_DMX_case]]

Revision as of 14:37, 4 April 2020

Introduction

DMX with case

The DMX interface for raspberry pi allows you to interface a raspberry pi with DMX hardware.

There is also a version "with FT245". That version adds the option to use your raspberry pi with our board as an Enttec USB Pro compatible device from another computer (raspberry pi or PC, Windows or Linux)

If you select "for pi zero" we give you an extra 40 pin male header and do not solder the matching female header onto our board. You can then chose several configurations yourself. The one I prefer is to have the male headers on the zero on the bottom, and the female on our board on the top. Keep in mind that if you arrange for the pi to stick out from under or above our board, the pinout is going to be wrong. So you can't put the connectors on both boards on top, and then flip one to make the connection.

Software

There are several software packages that can be used with your DMX interface for Raspberry pi.

First there are QLC+ and OLA. These are packages that run on Linux on the raspberry pi and allow you to control a DMX Universe.

Second, there are several packages by Arjan van Vught that use the raspberry pi "bare metal".

See: http://www.raspberrypi-dmx.com/


QLC+ and OLA

Don't forget to remove the console and getty from the serial port that the DMX inteface is using.

See: http://elinux.org/RPi_Serial_Connection#Preventing_Linux_using_the_serial_port


QLC+

Harold van Hulten wrote a nice "howto". See: http://www.udenix.nl/2016/how_did_i/rpi2dmx/

QLC+ 's home is at: http://www.qlcplus.org


our tests

To build qlc+ on raspberry pi with support for our board, you need to follow the howto at:

 https://github.com/mcallegari/qlcplus/wiki/Linux-build-Qt5

but with one addition:

 apt-get install libqt5serialport5-dev

needs to be added after installing the prerequisites. Next, it seems the uart device is disabled by default: edit

 plugins/plugins.pro 

to remove the hash on the line with "uart" so that it reads:

 !macx:!win32:SUBDIRS += uart

Next, you can build and install. Also use raspi-config to disable console output on serial but to enable the hardware. One more thing is to add the disable-bt and uart_clock to config.txt. See elsewhere on this page for the precise instructions.

OLA

stretch

The distribution ola works on Stretch. sudo apt-get install ola should do the trick.

Don't forget to disable login on the serial port (raspi-config) and to set init-uart-clock in /boot/config.txt. If you forget that last, you will notice that the "native-uart" option is not available when you try to add the universe.

Jessie

On raspbian jessie installing OLA is easy: sudo apt-get install ola should do the trick. The downside is however that it doesn't work :-( .

update: The simple option seems to work now. :-) update2: Some hints are that it still doesn't work. :-( Some have reported success by following the howto at: http://www.raspberrypi-dmx.com/raspberry-pi-dmx512-rdm/ola-on-the-raspberry-pi (which boils down to installing ola 0.10.5 instead of 0.10.1.

what does work however is:

#sudo apt-get install automake libtool bison flex libcppunit-dev libprotobuf-dev libprotoc-dev protobuf-compiler protobuf-c-compiler uuid-dev libmicrohttpd-dev
sudo apt-get build-dep ola
mkdir ola
cd ola
wget https://github.com/OpenLightingProject/ola/archive/0.10.1.tar.gz
tar xvfz 0.10.1.tar.gz
cd ola-0.10.1
#libtoolize
autoreconf -i
./configure 
make -j 5 all
sudo make install

There is one little thing about the first two commands here. The first should always work, but if I accidentally missed a package, well.. I missed a package and the build will fail. The second one (with "build-dep" should be more reliable. But before that works, you need to add the sources to your /etc/apt/sources.list file. It's already there, but commented out. Use your favorite editor to do that. (otherwise, try: sudo nano /etc/apt/sources.list )

wheezy

On Wheezy, adding

deb   http://apt.openlighting.org/raspbian  wheezy main

to /etc/apt/sources.list, and then the apt-get install ola should work.

There are some important hints at: http://opendmx.net/index.php/OLA_Device_Specific_Configuration#UART_native_DMX

raspberry pi 3

Add:

dtoverlay=pi3-disable-bt

to your config.txt file in the /boot directory.

Otherwise, the wrong UART will be used. The "wrong" uart (=ttyS0) will

  • change baudrate unexpectedly when the CPU feels hot.
  • I haven't figured out if it CAN do the required baud rate, and/or how to do that.

This has the consequence that we've stolen back the good UART from the bluetooth that's present on the PI3.

On the raspberry pi forums there is talk about re-enabling bluetooth at a lower performance level.

all raspberries

First you need to disable "other things" on the UART that the DMX board uses.

sudo systemctl disable serial-getty@ttyAMA0.service

and remove "ttyAMA" or "serial0" from /boot/config.txt. (you'll find something like console=ttyAMA0,115200 there, remove that whole console= entry. Try not to mess up the rest of that line.


Most importantly: add:

init_uart_clock=16000000

to your config.txt file in the /boot directory.

Next, you need to configure ola to use the native-uart plugin. It should be as easy as clicking on "add universe" on the ola home page. Somehow we often do not see the plugin active. Sometimes clicking on reload plugins helps, other times we need to restart ola to get the plugin to show up.


Locate your ola-uartdmx.conf (on some systems I'm told it is in /etc/ola/conf/, on others /var/lib/ola/conf/, and in some cases: /root/.ola/ola-uartdmx.conf or /home/pi/.ola/ola-uartdmx.conf. One of the ways to find out is to look at the -c argument on your running olad.). Edit it and set enabled to true, set the correct device (ttyAMA0), and add /dev/ttyAMA0-break = 100 and /dev/ttyAMA0-malf = 100 . It should then look like:

/dev/ttyAMA0-break = 100
/dev/ttyAMA0-malf = 24000
device = /dev/ttyAMA0
enabled = true

Note that the "malf" (mark after last frame) is set to 24 miliseconds. This is due to a problem with OLA: it writes the data and after that waits for the time specified in "malf". It turns out that the kernel will return from the write before the buffer is flushed. So the malf is measured from close to the START of the frame. Thus if you would enter the normal MALF of 100 microseconds, the next break is attempted after only about three characters have been sent. When the kernel then tries to empty the buffer before issuing the BREAK, it waits way too long. We (bitwizard + ola developers) have not been able to figure out an easy fix. So until then saying "24000" gives reasonable performance. (but once the bug has been fixed, you'll need to adjust this configuration parameter)

output mode

Then set the board to output mode. I would recommend creating a small script (sudo nano /usr/bin/set_dmx_mode; sudo chmod 755 /usr/bin/set_dmx_mode) :

#!/bin/sh
# set_dmx_mode
pin=18
gpio=/sys/class/gpio/gpio$pin
if [ $# -lt 1 ] ; then 
  echo "$0 : on or off?"
  exit 1
fi

if [ ! -d $gpio ] ; then 
   echo $pin > /sys/class/gpio/export
fi
echo out > $gpio/direction
echo $1 > $gpio/value


then calling the script:

sudo /usr/bin/set_dmx_mode 1

I recommend putting that line in /etc/rc.local so that it gets executed at boot time so you don't have to worry about it. (IIRC there is an "exit 0" in there, so don't put it AFTER that!)

Or you can install the gpio utility from wiringpi and use the following command to view the status of all the pins

gpio readall

and to set GPIO 18 (BCM) in output mode

gpio -g mode 18 out
gpio -g write 18 1

also, pin 14 & 15 need to be in the ALT0 mode, if this is not the case use

gpio -g mode 14 alt0
gpio -g mode 15 alt0


Note that the earlier versions of the DMX board have a bug that when the GPIO pin is an input (not driven) it will configure the board as an output. This is not desirable. Newer versions (starting 1.4) will have this "fixed" and the "default" will be "DMX IN" mode.

This does mean that if you want the board to do output, you can get away with forgetting about this gpio18 business if you have an older version. (I just realized I was getting away with this.... :-) )

Hardware

used hardware pins

The DMX harware uses the 3.3V, 5V, GND, RX, TX and GPIO18 signals. Besides that the non-FTDI version breaks out the SPI bus and I2C bus.

jumper settings

The jumper block has three (sensible) jumper positions, they can be either on or off. (We used to deliver the jumpers on the jumper block in say 1-NC, 3-NC, 4-NC: each of the jumpers on just one pin, not connected to another jumper pin. Nowadays we deliver them loose in the bag.)

Officially the DMX wire is called a bus. Oficially a bus should be terminated at both ends. Most people think of the DMX bus as coming out of our board and then TO the lamps. So most often our board will be at one end of the bus. In that case you should terminate the bus on our board: Jumper 3-4 mounted. Termination at the SENDING side of the bus is less important than on the opposite end. So if you're just sending DMX data with our board, the termination at our board is not that important. Most people don't bother.

Another possible configuration is that you have a few fixtures and then connect to the DMX IN connector on our board, and then another few fixtures on the DMX out. Our board will be in the middle of the bus, and you are then NOT supposed to add a terminator on our board: Do NOT place the 3-4 jumper.

With "short" busses, the termination is less important than with longer busses. What is "short" and what is "long" depends on the dataspeed. For example, for "SATA" 30-50cm is normal, 1m would be long. For DMX a few tens of meters is still "short".

The other two jumper positions should be added and removed in tandem. They provide a pullup/pulldown on the DMX databus so that the signal level is defined even when there is noone driving the bus. This is important when you do RDM. I found documentation that specified pullup on one line and pulldown on the other, but also the other way around. If you have trouble with RDM, add the jumpers. If that doesn't make things better, try using a few jumper wires and wire 1-5 and 2-6. If that works better for you, let us know!


Case

There is a case for raspberry pi with DMX board.

The assembly instructions have a few pictures.

Assembling_the_DMX_case