View Full Version : wakeup pin, reminder
korda
12-13-2008, 08:44 AM
Kevin, did you have a chance to test my scripts I emailed 2 weeks ago?
This is all about wakeup engine on pin change.
The problem was - the engine does not go to sleep(1,0), if called from inside timer hook. I believe the problem is the engine firmware related.
I need an answer asap, as our clients are waiting on us as well...
Or suggest another way to put engine to power saving mode with wakeup on pin change - the engine would not last on the batteries as a remote control application, if we do not have power saving mode.
kbanks
12-15-2008, 08:36 AM
I emailed you a response last week. Here is the text of that email.
Vlad:
I finally had a chance to take a quick look at one of your attached scripts.
I see that you are not using the Synapse supplied pinWakeup.py code, but instead have created your own customized variant.
At a glance, it looks like your intent in doing so was to allow you to use your own pin numbering system.
However, your code that calls the functions is using the standard Synapse GPIO numbering.
Because of this, you are not enabling “wakeup” on the pins you intend to.
Because of that, your sleep(x,0) calls are not doing what you want. The “core” code disallows sleep(x,0) if no wakeup pins have been enabled.
Kevin
korda
12-15-2008, 09:42 AM
Kevin,
Thank you for response.
Somehow I did receive email with your answers to my questions.
I see now that the pin numbers were not the ones you expect for sleep(1,0) to work. I will correct this today and let you know the results.
Thank you again.
korda
12-15-2008, 12:50 PM
Kevin,
I reworked transmitter script according to your suggestions above and now engine goes to sleep but never wakes up. To wake up, I have to power cycle or erase script via direct COM port connection.
Here is my script as it looks now, and I am going to email it as well.
See my comments in red.
def startup():
global countdown
global receiverAddress
receiverAddress = "\x00\x2f\x48"
# set button pins to INPUT
setPinDir (1, False)
setPinDir (2, False)
setPinDir (5, False)
setPinDir (6, False)
# monitor button pins
monitorPin(1, True)
monitorPin(2, True)
monitorPin(5, True)
monitorPin(6, True)
wakeupOn(1, True, True)
wakeupOn(2, True, True)
wakeupOn(5, True, True)
wakeupOn(6, True, True)
# sleep(1, 0) #NEVER WAKES UP on pin change if this line is enabled!
def buttonPress(port, state):
global countdown
rpc(receiverAddress, 'receiveState', port, state)
countdown = 50 #5.0 delay seconds before sleep
################################################## ##############
def timer100ms(currentMs):
global countdown
if countdown > 0:
countdown -= 1
if countdown == 0:
sleep(1, 0) #ONCE THIS LINE EXECUTED - IT DOES NOT WAKE UP!
################################################## ##############
def wakeupOn(pin, isEnabled, polarity): # default to enabling, falling edge
"""Controls "wakeup" feature for the specified GPIO (1,2,5,6,9 or 10)"""
canSetPolarity = True # default to the most common case
if pin==1:
mask = 0x01
canSetPolarity = False
elif pin==2:
mask = 0x02
canSetPolarity = False
elif pin==5:
mask = 0x10
elif pin==6:
mask = 0x20
elif pin==9:
mask = 0x40
elif pin==10:
mask = 0x80
else:
return # only pins 1,2,5,6,9 and 10 can do this trick
if canSetPolarity: # only pins 5,6,9 and 10 can do this trick
if polarity:
poke(0x16, peek(0x16) | mask) # 0x16 is KBI1SC
else:
poke(0x16, peek(0x16) & ~mask)
if isEnabled:
poke(0x17, peek(0x17) | mask) # 0x17 is KBI1PE
else:
poke(0x17, peek(0x17) & ~mask)
# Event Handlers
snappyGen.setHook(SnapConstants.HOOK_STARTUP, startup)
snappyGen.setHook(SnapConstants.HOOK_GPIN, buttonPress)
snappyGen.setHook(SnapConstants.HOOK_100MS, timer100ms)
mgenti
12-15-2008, 01:45 PM
I tried loading part of your script on to one of my proto broards and had to make a few modifications. On the proto board itself I had to remove the jumpers for the LEDs since you are using pins 1 & 2. In the script I had to enable the pullups on pins 1,2, and 6. Here is what I used to test:
from synapse.pinWakeup import *
def startup():
# set button pins to INPUT
setPinDir (1, False)
setPinDir (2, False)
setPinDir (5, False)
setPinDir (6, False)
#Make sure unused pins aren't floating
setPinPullup(1, True)
setPinPullup(2, True)
#Pin 5 on the proto board when jumpered for push button has a pullup
setPinPullup(6, True)
# monitor button pins
monitorPin(1, True)
monitorPin(2, True)
monitorPin(5, True)
monitorPin(6, True)
wakeupOn(1, True, True)
wakeupOn(2, True, True)
wakeupOn(5, True, True)
wakeupOn(6, True, True)
sleep(1, 0) #NEVER WAKES UP on pin change if this line is enabled!
rpc('\x00\x00\x0c', 'imawake', True)
snappyGen.setHook(SnapConstants.HOOK_STARTUP, startup)
korda
12-15-2008, 01:56 PM
Do you mean enabling pull ups makes a difference for a sleep(1,0)?
I this REQUIRED for this instruction to work - input pullup and make to GND when pressed?
The main reason I am using external pull downs - to minimize battery drain.
My buttons make connection to VCC when pressed...
mgenti
12-15-2008, 02:05 PM
Do you mean enabling pull ups makes a difference for a sleep(1,0)?
I this REQUIRED for this instruction to work - input pullup and make to GND when pressed?
I had to enable the pull ups on my proto board since I didn't have those pins connected to anything so they were floating.
The main reason I am using external pull downs - to minimize battery drain.
My buttons make connection to VCC when pressed...
Pins 1 and 2 will only wakeup the node on a falling edge, as mentioned on line 25 in pinWakup.py
korda
12-15-2008, 02:31 PM
Mark,
I have tried to duplicate your setup with pull-ups enabled, and I am using small square proto board and green terminals on the side.
I have enabled internal pull ups on ports 1, 2, 5, 6 and with nothing connected outside voltage reads as 3.2, 3.2, 0, 0.
All jumpers are removed, except two power jumpers.
Why gpio 5, 6 is not responding on setPinPullup(n, True) on the small board?
korda
12-15-2008, 02:44 PM
never mind previous post, I found that command wakeupOn(5, True, True) makes input go LOW. The same for port 6. Why is that?
My target is to wake up engine when any of 4 buttons is pressed or released and transmit RPC to receiver engine. Then go back to sleep to save power.
How can this be done?
mgenti
12-15-2008, 02:47 PM
Why gpio 5, 6 is not responding on setPinPullup(n, True) on the small board?
According to the docs for the chip we are using in the RF Engine, if you are monitoring for rising edge wakeup (like in your example) the pullups become pull downs.
korda
12-15-2008, 02:53 PM
That makes sense now, but it is sure confusing as hell.
I will try again...
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.