OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › RF switching – code additions for OSPi interval program? › Re: Re: RF switching – code additions for OSPi interval program?
Ray
First of all, the Arduino programs should be pretty easy to adapt to RPi by using wiringPi. In particular, the Arduino RC-Switch library works with wiringPi, and it provides a lot of powerful functions. Note that Rich’s sprinklers_pi program is written in wiringPi.
Now, since Dan’s interval program is written in Python, you will need to convert the code to Python. It’s also fairly straightforward. Below is an example: connect the RF transmitter to +5V, GND, and GPIO pin 17 on RPi, and you need to modify the signal (signature and command) to fit your specific remote socket.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
SEND_PIN = 17
SIGNATURE = 0b0000111101010101
COMMAND = 0b11110001
DELAYSHORT = 160
DELAYLONG = 500
OVERHEAD = 0 # overhead time (in us) for calling GPIO.output and time.sleep. If 0 doesn't work, try 125
def ookPulse(on,off):
GPIO.output(SEND_PIN,True)
time.sleep((on-OVERHEAD)/1000000.0)
GPIO.output(SEND_PIN,False)
time.sleep((off-OVERHEAD)/1000000.0)
def pt2262Send(signature,command):
for k in range(0,16):
for i in range(0,16):
if((signature>>(15-i)) & 0x1):
ookPulse(DELAYLONG, DELAYSHORT)
else:
ookPulse(DELAYSHORT, DELAYLONG);
for i in range(0,8):
if((command>>(7-i)) & 0x1):
ookPulse(DELAYLONG, DELAYSHORT)
else:
ookPulse(DELAYSHORT, DELAYLONG)
ookPulse(DELAYSHORT, DELAYLONG)
time.sleep(.005)
def main():
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(SEND_PIN,GPIO.OUT)
while True:
pt2262Send(SIGNATURE,COMMAND)
time.sleep(5)
main()