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

Using latches instead of SPI is technically ok.

But the http://elinux.org/RPi_Low-level_peripherals describes what kind of support for GPIO is in the kernel. This text also mentions the Arduino style of accessing pins over I2C and SPI networks.

In the schematics I posted you may notice the texts WiringPi XX. These numbers are the Arduino-style pins recognized automatically by the wiringPi libraries. There is also C-libraries that support pin numbering directly over SPI devices.

The benefit with SPI or I2C chips is that they support internal pullups, mode change to inputs or outputs and interrupts.

The multiplexing approach requires constant polling of the data which is not currently in the mainstream of Raspberry Pi. So I am afraid that there would be poor software support and we would have to maintain more code if we take the latch approach. And I am a bit lazy...

But if someone has started to support libraries using latch techniques I have nothing against this approach either.

Here is a small snippet of the SPI approach. This is a very straight forward way to deal with extended I/O. And there is very little code to maintain. I could have used the individual I/O pin approach here that might have been easier to read. But now I decided to write the code using byte reads for faster speed. So there exists also a pin-by-pin API. As well as python APIs if you don't like C.

Python is a good choice for sending OSC messages to QLC+ as there is a generic OSC library available.

Code: Select all

void spiSetup (int speed)
{
  if ((myFd = wiringPiSPISetup (SPI_CHAN, speed)) < 0)
  {
    fprintf (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) ;
    exit (EXIT_FAILURE) ;
  }
}

// Write a byte to the SPI I/O pins
void writereg(int chip, int reg, unsigned char data)
{
  unsigned char buf[3];
  int status;
  int i;
  buf[0] = (0x40 | (chip << 1)) & 0xff;
  buf[1] = reg & 0xff;
  buf[2] = data;
  status = wiringPiSPIDataRW(0, buf, 3);
}

// Read a byte from the SPI I/O pins
unsigned char readreg(int chip, int reg)
{
  unsigned char buf[3];
  int status;
  buf[0] = (0x41 | (chip << 1)) & 0xff;
  buf[1] = reg & 0xff;
  buf[2] = 0;
  status = wiringPiSPIDataRW(0, buf, 3);
  return buf[2];
}

void setDataInputs()
{
  writereg(0, 0, 0xff); // IODIRA all bits as inputs
  writereg(0, 6, 0xff); // IODIRA set pullups active
}
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

Hi Karrika,

Could I recommend 10nF 50V capacitors to ground on the switch inputs and small diodes across the opto LEDs? This would make the circuit bomb proof in terms of ESD and connection to the mains etc. Diodes could be BAS16s or BAV99s (surface mount) or 1N4001s (through hole but a lot bigger).
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Hi boxy,

Thanks for the reminder. I added surface mount caps and diodes.

Here is the layout so far. This is still not completed but gives an rough idea. The size of the board is 50mm x 100mm.
The 4 holes on the top part are for securing the pcb to the chassis.
The 6 holes at the bottom is for securing the Ethernet cables with some plastic tie wraps. The pcb will be very thick (2mm) to support the cable ties.
The flat cable coming in from the Raspberry Pi 2 may come directly from the RPi or from some other future module like DMX. The cable to the right goes to the next board in this series.
GPIObuffer.png
If you have improvements or concerns about the mechanics please add a comment.
User avatar
mcallegari
Posts: 4462
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Hey guys, I have implemented a GPIO plugin for QLC+.

Would you be willing to help testing it ?
Basically it's meant to run on the Raspberry Pi.
stef35
Posts: 18
Joined: Thu Jun 25, 2015 6:35 pm
Real Name: stephane

Hello

I would be pleased to help the project by testing this plugin?
Just tell me how i can help

mcallegari wrote:Hey guys, I have implemented a GPIO plugin for QLC+.

Would you be willing to help testing it ?
Basically it's meant to run on the Raspberry Pi.
enterius
Posts: 7
Joined: Thu Oct 22, 2015 10:36 am
Location: Cracow, Poland
Real Name: Krzysztof
Contact:

Hi Massimo.

I would like to help with testing GPIO plugin as I'm very interested in using it in my applications. Unfortunately I can't find any documentation for this plugin and I'm kind of lost about how to use it. So please feel free to write to me with some instructions and i will do all the needed testing.
I already soldered some micro-switches and LEDs to GPIO connector, but I have no idea how to bind them to any buttons and functions in QLC+.

Best regards
Krzysztof
mcallegari wrote:Hey guys, I have implemented a GPIO plugin for QLC+.

Would you be willing to help testing it ?
Basically it's meant to run on the Raspberry Pi.
User avatar
mumbles
Posts: 113
Joined: Thu Jul 16, 2015 4:39 am
Location: Central USA
Real Name: Justin

This sounds like an interesting project!

Do you think it's possible to get this circuit to fit on a 65x56mm pcb to meet the official HAT requirements?

This would make it easier to adapt CAD files to print cases. And in most cases itd fit existing Pi cases.

https://www.raspberrypi.org/blog/introd ... y-pi-hats/

My daily job as a customer system integrator and my dealings with RJ45 connections for a big majority of equipment has taught me, the zip ties could actually cause 2 flaws 1) RJ45 jacks to be pulled off the PCB due to the ziptie pulling down on RJ45 plug causing the back of the jack to pull up on solder joints. This tension combined with even a little ambient vibration will eventually cause failure to the pins inside the RJ45, solder connections of RJ45. 2) makes it difficult to release lock/ set on RJ45 plug.

There is an industry standard that states cables should not be fastened any closer than 6 inches to termination. This is to prevent the above issues.
OSX 10.10.5 QLC+ 4.9.1
Surface Pro4 Windows 10
Raspberry Pi B OLA 0.95
Raspberry Pi 2B QLC+

Swisson XMt-350
Chauvet RDM2Go
Enttec Pro Mk2
ultraDMX Micro
FTDI USB-RS485-WE-1800-BT XLR

Korg nanoKONTROL2
Korg nanoPAD2
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

The HAT idea sounds good. Very good actually. I would love to fit isolated DMX out and as many isolated GPIO pins as possible. Thanks for a great idea.

Combined with the new 7" LCD this would be a very nice unit. A 10" cabinet with clamped cables coming out of one end. I love it!
QLC+HAT2.png
QLC+HAT2.png (10.05 KiB) Viewed 2702 times
The big connector would be DMX out, the small one an extension for expanding through serial bus. At the bottom two sockets for 8 input switches.

Drawing the circuits tonight :)
--
Karri
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Here is the layout and wires of the brand new DiscoHAT. :D
DiscoHat.png
It has an isolated DMX output and 8 isolated input switches. The edge connector has ws2801 bits.

I would like to have QLCplus and HAT in the name of the board. But on the other side it becomes too long. Perhaps DiscoHAT would be good?

There is also an eeprom for the linux driver that populates the used bits at boot time into the Device tree as the HAT specs require.

I sent in an order of 10 pcb's earlier today. Within a few weeks I should have the protos ready. The price is "cheap". Less than 50€, more than 10€. The idea is to have a single 100 boards production run that should cover the need of DiscoHAT's for all eternity ;)
User avatar
mcallegari
Posts: 4462
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

karrika wrote:Here is the layout and wires of the brand new DiscoHAT. :D
Looks awesome Karri !
In the end will it have a "passthrough" strip to pack another hat over it ?
Is it for RPi 40 PIN IO only or will it be possible to plug it also on older RPi 1 ?
From the mechanical point of view, do you have screw holes in the same positions of the RPi ones ? Otherwise a floating board can easily get broken and can damage the RPi too.
Will you send one to me ? :)

How about calling it QLC+HAT ? :)
I'm actually kidding, since you are designing a generic board, not specific to QLC+ :)

Last thing: have you seen this post ? Basically I need to understand if the Eurolite adapter works or not on OSX.
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Hi Massimo,

the beauty in the HAT is that the mechanics is standardized. The screw holes match exactly and there are cut-outs for the camera flat cable and also the DSI display flat cable.

Stacking is very interesting. The HAT has no pins at all. The connector is a flat one with holes only. If you want a stackable HAT you put in a 40-pin female socket with 10mm pins upside down on Raspberry Pi. When you assemble the HAT the pins go through the HAT connector and you have all the pins available for the next HAT module.

You can use either 40 pin or 26 pin connectors. So all HAT modules are automatically compatible with both Raspberry Pi type boards.

You will get the first prototype for free as soon as I have it :)

What I really love in this design is that it fits my theatre perfectly. With 8 push buttons I get everything I need.

- doorbell
- phone
- indoor scene light switch on/off
- all lights on / screen lights only
- window sun simulation day/night
- music 1 introduction
- music 2 intermission
- music 3 end of show

I did notice your question for testing OSX. Looking for a Mac nearby to get it done.

--
regards,
Karri

PS. The design is done with the free KiCad software that is maintained by CERN. This HAT is supposed to be part of QLC+ so that people can use and improve on it. Should the design files go into the GitHub or just be uploaded somewhere? All the component libraries, design and project files are human readable ASCII.

project file:

Code: Select all

update=pe 16. lokakuuta 2015 22.12.52
version=1
last_client=eeschema
[pcbnew]
version=1
LastNetListRead=
UseCmpFile=1
PadDrill=0.600000000000
PadDrillOvalY=0.600000000000
PadSizeH=1.500000000000
PadSizeV=1.500000000000
PcbTextSizeV=1.500000000000
PcbTextSizeH=1.500000000000
PcbTextThickness=0.300000000000
ModuleTextSizeV=1.000000000000
Schematics:

Code: Select all

Title "Isolated GPIO inputs board"
Date "17 oct 2015"
Rev "1"
Comp "QLC+"
Comment1 "by Karri Kaksonen 2015"
Comment2 "this design is Open Sourced. You are free to use this in part of your own projects"
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L CONN_20X2 P1
U 1 1 55717DFC
P 10050 4800
F 0 "P1" H 10050 5850 60  0000 C CNN
F 1 "CONN_20X2" V 10050 4800 50  0000 C CNN
F 2 "" H 10050 4800 60  0000 C CNN
PCB layout:

Code: Select all

(kicad_pcb (version 3) (host pcbnew "(2013-jul-07)-stable")

  (general
    (links 152)
    (no_connects 0)
    (area 107.361686 78.29084 175.140055 158.109355)
    (thickness 1.6)
    (drawings 35)
    (tracks 658)
    (zones 0)
    (modules 55)
    (nets 41)
  )

  (page A3)
  (layers
    (15 F.Cu signal)
    (0 B.Cu signal)
    (16 B.Adhes user)
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

I am still waiting for the PCBs to arrive. They should come on Monday. Meanwhile I invested 31€ in a web site + domain and started to write the documentation in there. I know that the site is still science fiction as the board does not even exist yet.

In any case I will make 10 units. One for Massimo and two for me. The rest are still up for sale.

There is still lots of tests to be done for the Device Tree activation, GPIO pins plugin, DMX output, SPI led output. So the project will not be advertised before the boards are soldered and tested to work.

If you want to have a look at DiscoHAT just click on http://discohat.com

There is one question about the orientation of the DMX cable.

The current plan is to let it stick up straight from the board like here:

Image

The connector plus cable take a lot of space. The alternative is to deliver the DMX connector unsoldered. Then the user could solder a 3 pin cable to the board and mount the DMX socket on the cabinet. Perhaps I make this an option.

Please don't pay attention to the price on the shop tab. It is just a placeholder and that is why I put it so high that nobody would order it ;)

Until it is available of course. Then the real price is calculated from the cost of the chips.

I wrote everything on the web site last Sunday. When I get the real boards I will add photos.
User avatar
mcallegari
Posts: 4462
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Wow Karri, you're doing such an amazing job on that board !

Due to my limited electronics knowledge, I find difficult to imagine how the connectors will be placed, but I've got a few questions:
1- you mentioned a DMX connector. I suppose it is for DMX output right ? And I suppose it will work with the UART plugin, right ? (have you already tested it ?)

2- how does the SPI connector look like ? In my limited SPI experience I found that it would be very useful to have a connector with screws. Something like this.

3- as far as I understand you are planning to "export" GPIO PINs via RJ45 connectors ?
That means you need to have another custom PCB on the other end to bring GPIO signals into push buttons.
I mean, without a hat, you just need 2 wires and a breadboard to control a GPIO. A total electronics noob like me would go for the easiest solution.
The most common usage of GPIO is a footpedal, where you need 8 strong push buttons.
Maybe an optional connector with screws would be nice here too, so one can easily carry GPIOs around with just a generic multi-wire cable.

4- you mentioned the device tree. Why ? Isn't the one provided by my image (so by Raspbian) generic enough ?

This for now :)
I LOVE the TARDIS and sonic screwdriver thing ! hehe, it seems I'm not the only Whovian here then ;)
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

Hi Massimo,

thanks for the positive comment.

I got the boards and chips. Unfortunately the footprints of the chips did not match the board. So I will make only one for testing it electrically. So there is again a few weeks delay on this project. Drawing the corrected version and ordering PCB's. It is quite cheap as I don't need new chips.

So to the answers.

1) DMX out connector will work with the UART output. Not tested yet but I will test it now before making the next version of the board.

2) Your idea of the SPI connector is nice. I will use that.

3) The GPIO pins are exported via an Ethernet cable because of two things:
- easy to find locally in any lengths
- uses little space

When you cut the end of the cable you find 4 twisted pairs of wire. One pair is then soldered to one switch. So for my demo project I need just a 1m cable cut in the middle to get 2 cables for the switches.

If you want you can also buy RJ45 wall sockets for your switches. Then you do not need to cut the cable but can create a very modular switch system.

4) The Device Tree is mandatory for all products you want to call a HAT. It populates the SPI driver at bootup if it does not exists. It can also set the used GPIO pins to inputs and turn off the pull-ups already at boot time. In reality this is nonsense as we need to do all this for the early Raspberry Pi versions anyway. But if it makes the Raspberry Pi core developers happy why not do it. The big idea is to allow you to stack hats. When you have a HAT module you can see in the /proc/device-tree/hat/. Another thing is that the device-tree GPIO pins can also be used for power-on/power-off functionality and there is even some support for interrupt capability for the pins. I don't know all details yet. Time to do some studying.

The TARDIS turned out really great. I have to post some pictures on my web site. The laminated surface of the design is just perfect. I still need to design some cool smooth lighting for it as it is mostly operated in the dark.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

What's the matter with the ICs? have you got wide SO instead of narrow or TSSOP packages by mistake? Shouldn't be a show stopper.
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

A version of the opto in SO16 package is the SFH6916 from Vishay. This is just of £2 each though from Farnell in the UK.


http://www.vishay.com/optocouplers/list/product-83687/
User avatar
mcallegari
Posts: 4462
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

karrika wrote:3) The GPIO pins are exported via an Ethernet cable because of two things:
- easy to find locally in any lengths
- uses little space
Yep, I totally get the idea and the convenience of using RJ45 plugs and cables but my point was regarding usability.

Once the hat is mounted, you cannot access the Pi IO connector anymore (unless you planned to use a bypass connector as we discussed before) so the only way to use GPIOs is via RJ45.
My question was: will you provide also schematics to build a GPIO "daughter board" where one can easily solder a RJ45 connector and access GPIOs in a wider place ?
I am still thinking about a footpedal, where pedals must be quite big and quite strong.

Another side question: is there a limitation to the length of GPIO wires ? If you provide RJ45, then people will surely buy 50 meters cables and expect them to work ! Obviously I will be the first one to tell them they're dumb. ;)
boxy
Posts: 306
Joined: Tue Apr 21, 2015 8:18 am
Real Name: Robert Box

50m shouldn't be a problem. It's twisted pair cable and if a screen is used it'll be very tough. Earth loops could be an issue with screened cable so it is important not to ground it at the far end, same as DMX.

A related question would be: Are these inputs debounced to prevent spurious triggering? I would suggest 3 samples of the input in a row every 1-5ms or so to confirm a change in state. I expect the GIO inputs are polled regularly?
User avatar
mcallegari
Posts: 4462
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

boxy wrote:A related question would be: Are these inputs debounced to prevent spurious triggering? I would suggest 3 samples of the input in a row every 1-5ms or so to confirm a change in state. I expect the GIO inputs are polled regularly?
Yes, polled every 50ms. At the moment the GPIO plugin works on status change detection, so spurious signals can be a problem.
User avatar
karrika
Posts: 60
Joined: Tue May 12, 2015 6:50 am
Real Name: Karri Kaksonen

The schematics will be publicly available as well as the KiCad production files. The wire can be long. I will at least test it with 30 m and 60m. There is a series resistor around 920 ohm and a parallel capacitor 10nF that should take care of key bounces and spurious effects by killing resonance. The cable itself has a typical resistance of 0.188 Ohm/m. The voltage 5V comes from an isolated power supply and goes to the opto and the switch. I plan to run around 4mA to the switch. The voltage drop of the opto is 1.2V leaving 3.8V for the cable.

Also the DMX is isolated in this design so there are no earth loops making the system much more robust. There is no screen ground option on the DiscoHAT RJ45 cables.

The opto can only take 6V reverse spikes without breaking so I also add a bypass reverse diode to protect the opto.

Because we definitely do not want any spurious signal to trigger a scene I would love to build hysteresis into the input code. Perhaps you have to read the switch N times and get the same result before you trigger the scene. For me it is very important that my sentimental scene does not suddenly turn into a full light scene with Can-can music because of a glitch on the wire.

The Raspberry Pi also has a new GPIO interrupt class that could be used. I don't know enough of it yet.

Now is a good time to come with advice. I will be testing the design with the crappy boards I have and then I plan to make the bright and shining perfect DiscoHAT :)

Actually I do not need it before our next play in May, 2016 as we will mainly be working on the new play for a few months now.

Here is a picture of my wiring setup.

Image
Post Reply