Author Topic: GPIO / Schedule Questions  (Read 1217 times)

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
GPIO / Schedule Questions
« on: April 21, 2016, 03:22:39 PM »
Hi guys,
Can I use one GPIO pin to select between two sequences?  One will be static and the other will be animated.

Ideally I'd want to use a toggle switch to select which one to play and it would also need to read that switch at power-up.

Secondly, is there a way to dim the overall output at night?  It could be time-of-day determined or maybe a second GPIO hooked to a light sensor.
David...
da-share.com - the home of da_E131, da_DMX and other handy stuff

Offline Setarcos

  • Developer
  • ******
  • Join Date: Jan 2015
  • Location: San Jose, CA
  • Posts: 293
  • Kudos: 6
Re: GPIO / Schedule Questions
« Reply #1 on: April 22, 2016, 01:51:07 PM »
Hi David,

Yes, you can start a playlist (which contains one or more sequences) via an event that is triggered via one of the GPIO pins and runs a script (as opposed to an effect). Different events can be triggered for both rising (0->1) and falling (1->0) logic levels. I assume you would want the playlist to loop, so have a look at the StartRepeatingPlaylist.sh script in the script repository for reference. You probably also want to stop playback on the previous playlist before starting the new playlist (see StopPlaylist.sh and StopPlaylistGracefully.sh for how to do this).

I am not certain the event would trigger on FPP startup as the logic level isn't changing so you probably want some other way to run a script that reads the GPIO pin state and starts the corresponding playlist independently of the rising/falling GPIO triggered events. One suggestion is to have a different playlist that is in the schedule to run continuously that contains a single script that calls the fpp binary with the '-g' flag in input mode (e.g. fpp -g <GPIO>,Input,0) which will return the current GPIO value for a given <GPIO>. The script would then use this value to terminate the current playlist and start the corresponding playlist (this could be a potential race condition that would terminate the script before it was allowed to finish). Alternatively you could have the script run from rc.local in the system init scripts.

As far as dimming the overall output based on time of day, I don't know of a way to do this with native functionality in FPP. Some controllers like the F16v2 allow you to control string and virtual string output intensity. Just brainstorming, but there is undoubtedly a programmatic way to control this externally. The only alternative I can think of is to have different sequences that are used for nighttime v.s. daytime that have the correspondingly reduced output intensities.

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #2 on: April 22, 2016, 04:37:06 PM »
Thanks for the tips on the scripts.  I found the triggers but wasn't sure about what happens at startup.

For the dimming, I was hoping to be able to adjust the scale without re-rendering the sequences.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 7,928
  • Kudos: 141
Re: GPIO / Schedule Questions
« Reply #3 on: April 23, 2016, 01:40:10 AM »

For the dimming, I was hoping to be able to adjust the scale without re-rendering the sequences.

Adding the ability to dim on the fly is on my TODO list,  but it probably won't get into FPP this year.  It's easy for FPP to shove 100,000+ channels worth of data out every 50ms, but applying a dimming calculation to those 100,000 channels would cause a big increase in CPU utilization.  I'm not in favor of having to "re-dim" the data every time the sequence is played, that just eats CPU constantly, so I would like to setup something to cache the dimmed sequence data so that there is no CPU penalty to play the dimmed sequence again.  I would prefer to go one step further and pre-cache the pre-dimmed sequence so that we don't have to take a CPU hit the first time we play the dimmed sequence.  I've given it a little bit of thought, and am accounting for this kind of idea in the playlist rewrite I am working on.  One of the desired features of the new playlist code is to allow you to specify 'branches' of the playlist that are executed only if an expression or decision evaluates to true.  One of these expressions would be time based, so you could say "if it is past 9PM, then set the volume to 75%", or "if it is past 10PM, then set the brightness to 80%", "if it is past 11PM, then set the brightness to 60%", etc..
-
Chris

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #4 on: April 23, 2016, 02:44:48 AM »
Yeah, the pre-crunching of level data is what I had in mind.  Doing it on-the-fly seems excessive.

I've updated fpp on my test setup to version 1.8 so will have a play with scripts for now.

Offline mlevings

  • Newbie
  • *
  • Join Date: Jan 2014
  • Location:
  • Posts: 33
  • Kudos: 1
Re: GPIO / Schedule Questions
« Reply #5 on: April 28, 2016, 12:43:36 PM »
I'm very interested in the script to re-read the gpio inputs after a reboot and trigger a sequence.  I set up a buddy with a fpp/matrix at is business that triggers an "open" or "closed" on the matrix based on the output of his alarm system.  It works perfectly except for going off every sunday at midnight.  It stays off until the alarm is disarmed on Monday morning and works fine until the next Sunday.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 7,928
  • Kudos: 141
Re: GPIO / Schedule Questions
« Reply #6 on: June 01, 2016, 01:08:53 PM »
Install the UserCallbackHook.sh script from the script repository and edit the script to put your commands in the "postStart" section and they will get run after fppd is started at boot time.

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #7 on: March 19, 2017, 07:27:04 PM »
I'm finally getting back to this project.  I have the GPIO 22 pin starting two different playlists now (rising and falling) and it works well.

I've also grabbed the UserCallbackHook.sh script but am uncertain of is how to read the GPIO 22 pin state there so I can fire the correct event.

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #8 on: March 20, 2017, 12:37:20 AM »
After some more reading and fiddling I ended up creating a script to read the gpio pin and launch the appropriate playlist for each switch state.

Code: [Select]
#!/bin/sh

# If you want to start on a specfic numbered entry in the playlist
# then put the entry number inside the quotes on the line below
STARTITEM=""

SW_STATE=$(gpio read 3)

if [ $SW_STATE -eq 0 ]
then
PLAYLISTNAME="Starburst Blue"
else
PLAYLISTNAME="Static Blue"
fi

fpp -c stop

fpp -p "${PLAYLISTNAME}" ${STARTITEM}


I use the same event / script for both rising and falling actions of the pin and that works well.

What I'm stuck on is how to call my SwitchCheck.sh script from within the UserCallbackHook.sh script.

If I paste the code from the SwitchCheck.sh script into the UserCallbackHook.sh script it works at boot time, but I'd rather have the actual selection logic in just one place (SwitchCheck.sh).
« Last Edit: March 20, 2017, 02:38:04 AM by David_AVD »

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 7,928
  • Kudos: 141
Re: GPIO / Schedule Questions
« Reply #9 on: March 20, 2017, 10:54:56 AM »
What I'm stuck on is how to call my SwitchCheck.sh script from within the UserCallbackHook.sh script.

If I paste the code from the SwitchCheck.sh script into the UserCallbackHook.sh script it works at boot time, but I'd rather have the actual selection logic in just one place (SwitchCheck.sh).

Instead of pasting the code, add this line to your UserCallbackHook.sh script:

Code: [Select]
${FPPHOME}/media/scripts/SwitchCheck.sh

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #10 on: March 20, 2017, 02:58:50 PM »
Ah, of course.  It's a path issue?  I'll try that.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 7,928
  • Kudos: 141
Re: GPIO / Schedule Questions
« Reply #11 on: March 20, 2017, 09:00:50 PM »
I think you could also run it via the eventScript wrapper which sets the path for you, but either way you are giving the full path to a script.

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #12 on: March 20, 2017, 10:45:39 PM »
Your solution worked a treat.  Thanks very much for the help.  :)

Offline David_AVD

  • Jr. Member
  • **
  • Join Date: Jul 2014
  • Location: Victoria Point (QLD - Australia)
  • Posts: 53
  • Kudos: 0
    • da-Share
Re: GPIO / Schedule Questions
« Reply #13 on: July 15, 2017, 03:57:41 PM »
I've had this pi deployed for a few months now and generally it works fine.

One thing that does happen is that the sequence stops every couple of weeks.  Toggling the GPIO pin to run the sequence selection scrip brings it back to life.

I don't have IP access to it without traveling, but I gather that fpp is still running and it simply stopped playing for some reason.  Any ideas?

 

Back to top