My Project on a Raspberry Pi 2 with Raspian stretch. I want use a GPIO pin to drive 3d shutter glasses (glasses hacked to receive 0 _3V square wave) Video playing on the HDMI port and A Pin goes on when one video frame completes then goes off when the next video frame completes.

Things I’ve tried. HDMI splitter then a VGA converter one of the HDMI’s. This works but requires a bit of electronics to clean up the signal to give me the square wave I want. I’m also hoping in the end to have more than one pin switching. Plus it seems to upset the RPI on occasions possible due to the and shaking between the PI and the monitor. So this solution doesn’t really cut it

Set up the DPI output and get the Vsync from pin 3. Then use mirroring software like rpi-fbcp or raspi2fb to show the same video on the HDMI and DPI at the same time. Main problem here is there is a varying time delay between the HDMI frames and the DPI frames. So they are not synchronised.

I’ve been searching the ol google for near a week now trying stuff but haven’t managed to bottom it.

As the video I’m showing is made up of still images made in to an MPG I could send the individual JPGs to the HDMI and put a pin toggle command between each frame but Python is too slow to get a decent frame rate (ie 60fps or more) . So a smart person maybe able to do this in C or something but it’s beyond me and I can’t find any example close enough on the net to figure it out…

I think it is probably very possible using the Video core API’s like DispmanX but I can’t understand how to use it and again can’t find any examples out there that are close enough for me to tinker with.

So I’m really open to suggestions…

Thanks for reading….

  • It is not clear (to me) what the inputs and outputs are. Something happens (end of frame?) which is meant to trigger something else (3D glasses?). Where and what is the input and where and what is the output? Preferably in terms relevant to the Pi such as GPIO X receives a pulse and then GPIO Y must be set low.
    – joan
    Mar 9, 2019 at 8:43
  • Hello Joan thanks for replying.. There wont be an input as such well nothing external to the RPI. The RPI will be playing a video with (omx probably) . The video will be set up to run at 60 frames per second. I want a GPIO pin to toggle between high and low each frame. My thoughts were if I could match the fps and the refresh rate and I can get at the video Vsync pulse then this may do it..
    – perfo
    Mar 10, 2019 at 0:25

1 Answer 1


My very rusty C programming skills (they never were that good) held me back here but I final cracked it.. now I have a GPIO pin with a nice square wave on syncronised to the VSync of the HDMI signal.. works super duper...

Just in case it helps others I've tagged the code on below. Other than installing wiringpi for the gpio bit everything else is already there.. of course I'm sure there is plenty of room for improvement

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <stdint.h>
#include "bcm_host.h"

int Toggle = 0;

void Vsync(DISPMANX_UPDATE_HANDLE_T update, void *arg)
  Toggle= !Toggle;

    if (wiringPiSetup () == -1)
      return 1 ;

    pinMode (11, OUTPUT) ;


    DISPMANX_DISPLAY_HANDLE_T display = vc_dispmanx_display_open(0);

    vc_dispmanx_vsync_callback(display, Vsync, NULL);
    while (1)
        digitalWrite (11, Toggle) ; 

    return 0;
  • Please accept your answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again and again after months.
    – Ingo
    Dec 7, 2019 at 10:19
  • I have tested on raspberry pi 4 and it compiles and links but the vsync is never triggered. I have confirmed I have vsync present with glxgears: Running synchronized to the vertical refresh I see you tested on rpi2. Any idea at which rpi version this functionality broke and if there is a way to address on the rpi4? Jun 17, 2023 at 4:22
  • 1
    Sorry Alex I haven’t a clue why it wouldn’t work on a rip 4 but there are a few differences in the hardware between the different versions so maybe it needs a specific answer to each board ? I may revisit this project in the near future so if you do find out how to do it on an RPI 4 I’d be very interested…
    – perfo
    Jun 18, 2023 at 9:55
  • @ingo - Thanks for the note. I didn’t think about clicking my own answer as the answer…done.
    – perfo
    Jun 18, 2023 at 10:57
  • Hi @perfo, thanks for the quick reply! I tested on a pi3 and a pi2 this weekend and cannot get vsync callback to trigger on either. Since now my hardware matches yours, I'm wondering if something in the library could have changed. Please let me know if you have any thoughts Jun 19, 2023 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.