Use GPIO pins to trigger scenes

All the topics related to QLC+ on the Raspberry Pi
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Yesterday I created some light switches in the props for triggering scenes on and off. Also sound effects like doorbells and telephone rings were done in the same way.

Just in case someone has similar needs I decided to write a little note about it.

The Raspberry Pi has a wiringPi extension. You can simply read the state of a pin from the command line like

gpio read 7

This returns the value 1 or 0.

The switch can be connected directly between GPIO pin 7 and ground. Raspberry Pi has its own pullup resistors.

To send the data to QLC+ you need to select OSC input from the input/output tab.

The first input listens to port 7770 by default.

A small python script like this does the job

Code: Select all

#!/usr/bin/env python

import liblo, sys

try:
    target = liblo.Address(7770)
except liblo.AddressError, err:
    print str(err)
    sys.exit()

liblo.send(target, "/foo/message1", 123)
The last part is to go to the Virtual console, choose a button, click on Widget Properties, click on Auto detect.
Then run you python script that sends the message. And voila - you have external triggering of the widget.

You can use bash to poll for the pin and call the python script or perhaps even search for python bindings to monitor the GPIO pins directly from python.

I am very happy with the flexibility of Raspberry Pi2 and QLC+. We will use just one tablet as backup in case of troubles. All controls will be done by the actors pressing hidden pushbuttons around the stage. The ASUS WiFi USB-dongle is set to operate in server mode so there is no extra electronics needed. You can connect to the system using an ordinary browser at http://192.168.42.1:9999 (The IP chosen when you set up the access point and dhcp server).

The total cost of the Raspberry Pi2, SD card, uDMX USB dongle, audio cable, WiFi dongle and power supply is just a little above 100€. And you get control of both lights, sound effects and music. All music and sound effects are on the SD card. The Raspberry Pi 2 plays them out in pretty good quality. So far no one has complained.

The next step is to create a real extension board for the RPi with proper screw terminals for external switches and good quality isolated DMX hardware. Perhaps a small 7" touch screen showing the real QLC+ user interface would be cool. :roll:

As the minimum PCB order is 10 boards interested parties can drop me a line. I need just two of them. One main system and a hot backup. The time for making the design is sometimes during summer. Hopefully before our autumn season.

Enjoy,
Karri
User avatar
mcallegari
Posts: 4461
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Hi Karri,
thanks for sharing this.

I believe at some point a native GPIO plugin should be implemented.
Apparently this is a topic of interest, so why not covering it as a "out of the box" solution ?

My problem at the moment is to find the time also for this, and moreover to test it. I don't have a way to test GPIO signals other than wiring some batteries and see if the digital level changes.
Since you already contributed to QLC+ via GitHub, maybe we can work together on it ?
I can create the plugin stub for you and push it in a branch, and then you can continue from there and do some tests ?
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Hi Massimo,

Sounds great!

Our premiere is on the 2nd of June and the month of June is very hectic. But in July I could have a look at it. So please create a stub to set me on the right track.

It might also be nice to add support for digital rotary knobs. They take just 2 GPIO pins. We would need it for our theatre as a master volume control and master intensity controller.

The Raspberry Pi has two SPI interfaces that can easily be extended to handle hundreds of bi-directional GPIO pins with minimal code writing.

Another interesting thing would be to have native DMX bidirectional support using the UART pins on Raspberry Pi. Of course with properly isolated interfaces.

I also played around with LED strips with individually addressable full color leds. The SPI interface on Raspberry Pi can drive them directly. Just push 3 byte RGB values down the SPI. It is an amazing small computer.
User avatar
mcallegari
Posts: 4461
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

karrika wrote:I also played around with LED strips with individually addressable full color leds. The SPI interface on Raspberry Pi can drive them directly. Just push 3 byte RGB values down the SPI. It is an amazing small computer.
This is already there ! I've shown it in my RPi video one year ago: https://www.youtube.com/watch?v=ch0sNUbO9lo
iamchrislaurie
Posts: 58
Joined: Mon Apr 27, 2015 11:27 am
Real Name: Chris Laurie

I would sign op for this. I need to learn how to drive and read the SPI bus anyway. I would like to suggest that the board be made to work with a reasonable number of buttons and potentiometers. I suggest 30-40 buttons and a similar amount of potentiometers. If this is overkill then maybe a simple way to either daisy chain these boards or add another.

Lots of potentiometers will allow the use of joysticks to control sliders using the level monitor and relative update profile setting. Giving one the equivalent of a board with motorised faders at a fraction of the cost.

So far I have successfully built hid based controllers using this principle and these boards http://www.leobodnar.com/shop/index.php ... cts_id=204. They are however limited to 8 potentiometers.

As soon as I have time I'll be trying to build a HID device using this board: https://www.pjrc.com/teensy/teensyLC.html (or one of its siblings) that can have a larger number of buttons and potentiometers - but only on Linux - Windows is limited to 8 potentiometers. However building a board on on top of a SPI bus directly on the Pi2 will be very exciting.

I have been using the teensy board to build my own dmx controlled led strips for use in our musical productions - write-up and video will come soon.

I kind of see it a bit like this: A qlc+ input plug-in that can be configured through a profile to read any amount of buttons and potentiometers from the SPI bus and then map them to buttons etc in the virtual console.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

Hi guys,

I don't recommend connecting the PI directly to external switches, especially over a long distance. The wrong kind of shoes and carpet and ZAPP!, a few thousand volts of static will kill your show and the PI.

If a PCB is being made, I suggest some kind of protection/input buffer with filtering etc. It could even be made safe if plugged in to the mains by mistake! The cost would be pennies.

Once I've come with a few designs I'll post them on here.
User avatar
mcallegari
Posts: 4461
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Chris, SPI or GPIO ? :)
We're talking about GPIOs here to use them as their name says: "General Purpose IO" :)
SPI at the moment is dedicated to LED strips and LED panels and it is output only.
The RPi has plenty of available GPIOs, while it has just 2 SPI lines (if I remember correctly) and to be honest I have no idea what can be read from a SPI bus.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

SPI is MOSI, MISO and SCLK (3 wires). The clock signal is one way (generated by the Master - the PI).

MOSI is Master Out, Slave In.
MISO is Master In, Slave Out.

SPI is therefore 2 directional and can be very fast (1mbit).
User avatar
mcallegari
Posts: 4461
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

boxy wrote:SPI is MOSI, MISO and SCLK (3 wires). The clock signal is one way (generated by the Master - the PI).

MOSI is Master Out, Slave In.
MISO is Master In, Slave Out.

SPI is therefore 2 directional and can be very fast (1mbit).
Thanks for the lesson :)
And how many devices have you ever wired on SPI buses ? As far as I know, apart for LED strips, the most common SPI devices are NAND/NOR memories and EEPROMs.
Believe me, even if GPIO has a lower bandwidth, it is much more common (together with I2C) and widely used for sensors or actuators.

By the way we're going off-topic here.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

EDIT:

The SPI also has 2 CE (Chip Enable) lines so that two slave devices can on the same bus.
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

I already have another project going on that uses MCP23S17 chips to extend SPI to bidirectional 16-bit I/O. It also supports interrupt capability. With one chip select I can add 8 chips. It means 128 I/O pins.

The Raspberry Pi has two SPI interfaces and several CE lines so there is really no restrictions of how many buttons you can use.

I had my first Raspberry Pi 2 show yesterday using unisolated switches to control everything. During the summer the plan is to build a pcb with isolated hardware. Would any of you be interested to join forces and participate in an open platform?

The board could have:
- a SPI MCP23S17 chip providing 16 isolated inputs
- 8 small pushbuttons
- 4 small rotary encoders
- dip-switches to set the SPI address. 3 bits set the logical address and 2 bits choose the CE/ signal allowing you to connect up to 16 boards (128 buttons and 64 rotary encoders)
- form factor 5cm by 10cm
- two 16-pin terminal blocks for external connections

This still leaves the second SPI bus for LED control.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

We use SPI for:

System ASICs (PSUs, I/O, diagnostics etc.),
G-sensors (accelerometers) and yaw-rate sensors,
EEPROM,
Coil drivers,
Electric Park Brake micro,
Comms diagnostics.

I'm more hardware than software, but I know SPI can be difficult to get running unless there are ready made routines out there you just blast data to.

Some ideas for connecting GIO are in the second link:

http://www.mosaic-industries.com/embedd ... ifications

http://elinux.org/RPi_GPIO_Interface_Circuits

One thing missing from the circuits are capacitors to filter ESD (Electrostatic Discharge). Typically these are 10nF, 50V parts on each pin going to the outside world. A second component to GND across each GIO pin will greatly stop risk of blowing the Pi up.
iamchrislaurie
Posts: 58
Joined: Mon Apr 27, 2015 11:27 am
Real Name: Chris Laurie

@karrika - I would certainly be interested in such a board. In my case I would like to fit joystick controls (x y return spring potentiometers) as opposed to rotary encoders. In other words analog data. So if the board could be had without the actual switches and knobs, that would be first prize. Maybe 2 boards rather?

The point of the joystick is the interaction with the level monitoring and relative settings in the input plugin. This allows my scene to set the value and the moving the joystick adjust the value from where it is currently and not the absolute value.

Being able to combine the 2 methods would also allow for more adaptability and versatility for us almost maker types.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

This sounds interesting, if it hasn't already been done?

I have access to Mentor Graphics software so we could get something going (schematics for a start).
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Thanks for the comments. While walking out with my daughters dog during the weekend I had some spare time to think about this. So far I can think of many different boards.

All boards would have a 40 pin plat cable input and output.

Board 1)
DMX board using pins 8 TXD, 10 RXD

Board 2)
Extended SPI board with lots of input pins
24 (SPI0 CE0), 26 (SPIO CE1), 19 (SPI0 MOSI), 21 (SPI0 MISO), 23 (SPI0 SCLK),
12 (SPI1 CE0), 11 (SPI1 CE1), 38 (SPI1 MOSI), 35 (SPI1 MISO), 40 (SPI1 SCLK)
The system provides 4 different SPI chip addresses. With dip switches or jumpers you can choose SPI0/SPi1 and CE0/CE1.
Once the address is known you can map 8 MCP23S17 chips to listen to this address.
One board would have one MCP23S17 chip, 16 isolated inputs through 4 RJ45 sockets, 1 isolated DC-DC power to feed the input switches.

Board 3)
Plain GPIO input pins.
3, 5, 7, 13, 15, 16, 18, 22, 27, 28, 29, 31, 32, 33, 37
15 isolated inputs through 4 RJ45 sockets, 1 isolated DC-DC power to feed the input switches.

Board 4)
Extended SPI board for analog inputs. Joysticks, sliders

Board 5)
Extended SPI board for feedback outputs. LED bars, LEDs

Ethernet cables are cheap and easy to find. That is why it would be good to abandon screw terminals. You can just cut the cable on the other end and solder it to the pushbuttons, switches or rotary encoder. How you assemble the buttons, switches and rotary encoders is up to you. They are not soldered on the I/O board.

The easiest board to start with would be board 3. I assume that this board would be the most popular and perhaps the only board this project ever does. The price would probably be less than 10€ as the parts are not expensive or hard to get.

I have mainly switched over to the free KiCad for OpenSource PCB designs now that it is maintained by CERN. The quality and usability is top notch. And it is also nice to be able to distribute the pcb designs in a form that can be opened and edited by anybody.

Perhaps the design files could be stored on the QLC+ site once the design is complete so that anyone could manufacture these.
User avatar
mcallegari
Posts: 4461
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Hi Karri, everyone,
I believe this is an interesting discussion and I'm definitely into sponsoring anything that comes out of it.

I agree with Karri when he says that the QLC+ website could host a page dedicated to "certified" hardware gadgets targeting the Raspberry Pi or PCs.
I'm no hardware guy so I don't have enough skill to help in designing a PCB but since 15 years I live between naked boards of every kind so I think I can tell if a PCB has a good quality or not :)

I would say the page can host (for each gadget):
- the schematics
- the PCB layout
- pictures/videos of the assembled item
- instructions how to make it work with QLC+

Also, if a user is not able to assemble an item on his own, I would add some contacts to who invented the item to puirchase an assembled one. Obviously if you have the time and interest to support such thing.
So in this way you guys can make a few bucks out of your creations :)

Technical support can happen in a dedicated forum section or, if you prefer, via private emails to you.

So, to summarize, just tell me what code I have to write :D
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

I agree. Mentor is the most 'pro' software but it is also a nightmare to use. They bought the schematic entry software from another company which is and was terrible and made it worse!
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

I already kicked up the KiCad and added the connectors for board 3.

The basic idea is
QLCgpio3.png
QLCgpio3.png (3.91 KiB) Viewed 3445 times
The PCB would be 2mm thick and the cables could be secured with tie wraps. That is why the board is so long (and thick).

Once I get a little further you get the zip file with the project and the libraries. We could review and refine the design for a while.

The middle area on the board is for optic isolators and the dc-dc isolated power supply.

PS. silly me, the RJ45 connectors have to flip 180 degrees in order to get the cables going south and not north.
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Here is a first try on the schematics. There is just 12 input pins available. The rest are needed elsewhere. Comments?
Schematics.png
iamchrislaurie
Posts: 58
Joined: Mon Apr 27, 2015 11:27 am
Real Name: Chris Laurie

That's look cool!

I have been looking at another approach, using the GPIO pins directly via a 16 channel multiplexer like this one http://www.ti.com/product/cd74hc4067

In this case you would have many of them, all using the same 4 address pins simultaneously (an address bus) then you would need 1 pin per chip to read the values back. A 12 pin arrangement would allow 8 of these giving you 128 buttons/sliders - sliders would need some form of ADC.

This then avoids using the SPI bus altogether.

Thoughts about this? I am currently playing with this in a with a teensy 3.1 board (handles analog) and then create either a HID or MIDI device.

I guess I'm mentioning it here because I hope that whatever plug-in software is written, it would also make it possible to use this approach.
Post Reply