PDA

View Full Version : how to trigger events on Rpi from gpio pins?



declan slater
April 1st, 2016, 04:23 PM
Hey Ron,

I can get a single event change to happen on the Rpi only when manually running this lua script...

How can I get this script to be automatically scanned all the time (like everything else), so it can trigger events?

(I really tried to figure it out, but I am really bad at lua, and my wife really hates me spending my time trying figure it out...)

My TV has a usb port that sends 5v when it is on and 0v when it is off, I'd like to use that to trigger a gpio on my rpi using a voltage divider (3 - 1k resistors in series across the 5v, the 3.3v gpio output tapped off of 2 of them..) - it works great! I tried to use the ports on the pir-1, using a SSR (Solid State Relay), but I could not get it to trigger it correctly as a single pulse when it turned on, then another single pulse when it was turned off (so I can trigger single events). I need to send (an IR code to turn my power amp on/off and a separate http get command to turn on/off my sub amp) when the tv is turned on/off with it's power button or the remote.

I see that you just posted something very similar, and much better using an arduino, but I only have the Pi for this task.

Thanks!

here's the code I use...


local raspi = require("raspi")

if not luaWiringPi then
require('luaWiringPi')
luaWiringPi.setup()
end

raspi.export( 24 )
raspi.direction( 24, false )
local payload = raspi.read( 24 )
if payload == 1 then
gir.triggerEvent("TVon", 18, Promixis.Event.MOD_ON, payload)
elseif payload == 0 then
gir.triggerEvent("TVoff", 18, Promixis.Event.MOD_ON, payload)
end

Ron
April 1st, 2016, 04:41 PM
Yeah the RPI code currently doesn't do async notifications. But if you can handle a 1 second delay ( or something like that ) try the attached script. It sets up the pin and polls it every second. If the level is different from what it saw last it will generate an event.

declan slater
April 1st, 2016, 05:54 PM
Thanks Ron!

It works great, other than the constant "Girder/Triggered" messages flooding the logger...

I can't seem to figure out how to ditch that, any way you know of?

Thanks for the help! I'm looking forward to some new updates, now that you have an Rpi3!



Yeah the RPI code currently doesn't do async notifications. But if you can handle a 1 second delay ( or something like that ) try the attached script. It sets up the pin and polls it every second. If the level is different from what it saw last it will generate an event.

Ron
April 1st, 2016, 07:00 PM
What is the pattern of the events?

(Alternating) -> On then Off then On etc,
(Steady On) -> On On On On
(Steady Off) -> Off, Off, Off

Ron
April 1st, 2016, 07:01 PM
Aah never mind I see what messages you mean, the "Triggered" message that means the Action trigger. Yes we can change that...

Ron
April 1st, 2016, 07:07 PM
Try the attached GML.

declan slater
April 11th, 2016, 11:08 PM
Thanks Ron!

I'm working on trying it out now, it seems to work, but the odd thing is that it can sense when the tv is on just fine, and the script works great for that, but when it turns off, the script turns the amp off, and a minute later turns it back on, then about 4 minutes later, it turns it off again.

Thanks for the help though!

Ron
April 12th, 2016, 08:10 AM
Since the input pins have a really high impedance, it is possible that a charge is building up causing it to read high input. Maybe hook a multi-meter over the 3.3v part of your circuit and leave it there to see if the voltage rises after a while.