Skip to content

Commit 82b7fea

Browse files
committed
Keyes IR remote script, GoPiGo and scratch example added
1 parent e757b29 commit 82b7fea

File tree

9 files changed

+597
-71
lines changed

9 files changed

+597
-71
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
##IR remote control
22

3-
### Thisfolder contains the files to control the GoPiGo with and IR remote similar to the one used with TV and AC's
3+
### This folder contains the files to setup and control the GoPiGo with and Keyes IR remote
44

55
**_Files:_**
6-
- **gopigo_ir_control_test.py** : Used to test and record the button presse on the remote
6+
- **ir_recv_example.py** : Used to test button press on the IR remote
77
- **gopigo_ir_control_bot.py** : Program to control the GoPiGo using the IR Remote
8-
- **setup.py** : Installation file for the GoPiGo (use only if you are not using Dexter Industries SD Card)
8+
- **/script/ir_install.sh** : Installation file for IR remote control
9+
10+
**Connection:_**
11+
Connect the IR receiver to the Serial port on the GoPiGo. This will act as a pass through to the IR signals to the Serial pins.
12+
IR receiver Hardware v1.0 and back have the IR receiver connected to white wire and v1.1 and v1.2 have it connected to the Yellow wire, so the GPIO changes
13+
14+
**Installation:_**
15+
- Make the ir_install.sh executable: sudo chmod +x ir_install.sh
16+
- Run the install script: sudo ./ir_install.sh
917

1018
**Usage:_**
11-
First run the **gopigo_ir_control_test.py** and find out the IR codes for the button press on the remote.
19+
Run the **ir_recv_example.py** to check if the remote is working properly
1220

13-
Once you have found the unique code in each of the button press, program them in the **gopigo_ir_control_bot.py** to control the GoPiGo when you press the buttons on the remote
21+
Then run **gopigo_ir_control_bot.py** to control the GoPiGo when you press the buttons on the remote

Software/Python/ir_remote_control/gopigo_ir_control_bot.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,44 @@
22
##################################################
33
# GoPiGo IR remote control
44
#
5-
# This example is for controlling the GoPiGo with an IR remote similar to the one with AC and TV's
5+
# This example is for controlling the GoPiGo with an Keyes IR remote
66
#
77
# History
88
# ------------------------------------------------
99
# Author Date Comments
10-
# Karan 1 June 15 Initial Authoring
11-
#
10+
# Karan 01 June 15 Initial Authoring
11+
# Karan 21 Aug 15 Updated to use LIRC
1212
# These files have been made available online through a Creative Commons Attribution-ShareAlike 3.0 license.
1313
# (http://creativecommons.org/licenses/by-sa/3.0/)
1414
##################################################
15-
16-
# Identify the unique strings from the IR_remote test program and use them to control the GoPiGo
17-
# Sample inputs from the remote
18-
# [70, 34, 9, 25, 6, 64, 4, 1, 0, 43, 42, 0, 0, 0, 0, 0, 0, 0, 0, 255]
19-
# [70, 34, 9, 25, 6, 64, 4, 1, 0, 210, 211, 0, 0, 0, 0, 0, 0, 0, 0, 255]
20-
# [70, 34, 9, 25, 6, 64, 4, 1, 0, 82, 83, 0, 0, 0, 0, 0, 0, 0, 0, 255]
21-
# [69, 35, 8, 25, 6, 64, 4, 1, 0, 242, 243, 0, 0, 0, 0, 0, 0, 0, 0, 255]
22-
# [70, 34, 9, 25, 6, 64, 4, 1, 0, 82, 83, 0, 0, 0, 0, 0, 0, 0, 0, 255]
15+
# Connect the IR receiver to the Serial port on the GoPiGo
16+
# Run the install script before you start
17+
2318
import gopigo
2419
import time
20+
import lirc
2521

26-
# Assign pin 15 or A1 port to the IR sensor
27-
gopigo.ir_recv_pin(15)
28-
print "Press any button on the remote to control the GoPiGo"
22+
sockid = lirc.init("keyes", blocking = False)
2923

24+
print "Press any button on the remote to control the GoPiGo"
3025
while True:
31-
ir_data_back=gopigo.ir_read_signal()
32-
if ir_data_back[0]==-1: #IO Error
33-
pass
34-
elif ir_data_back[0]==0: #Old signal
35-
pass
36-
else:
37-
sig=ir_data_back[1:] #Current signal from IR remote
38-
if sig[9]==82 and sig[10]==83: #Assign the button with 82 and 83 in position 9 and 10 in the signal to forward command
26+
sig= lirc.nextcode() # press 1
27+
if len(sig) !=0:
28+
print sig[0]
29+
30+
if sig[0]=="KEY_UP": #Assign the button with 82 and 83 in position 9 and 10 in the signal to forward command
3931
print "fwd"
4032
gopigo.fwd()
41-
elif sig[9]==114 and sig[10]==115:
33+
elif sig[0]=="KEY_LEFT":
4234
print "left"
4335
gopigo.left()
44-
elif sig[9]==242 and sig[10]==243:
36+
elif sig[0]=="KEY_RIGHT":
4537
print "right"
4638
gopigo.right()
47-
elif sig[9]==210 and sig[10]==211:
39+
elif sig[0]=="KEY_DOWN":
4840
print "back"
4941
gopigo.bwd()
50-
elif sig[9]==43 and sig[10]==42:
42+
elif sig[0]=="KEY_OK":
5143
print "Stop"
5244
gopigo.stop()
5345
time.sleep(.1)

Software/Python/ir_remote_control/gopigo_ir_control_test.py

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
##################################################
3+
# IR remote control example
4+
#
5+
# This example is for controlling the GoPiGo with an Keyes IR remote
6+
#
7+
# History
8+
# ------------------------------------------------
9+
# Author Date Comments
10+
# Karan 21 Aug 15 Initial Authoring
11+
# These files have been made available online through a Creative Commons Attribution-ShareAlike 3.0 license.
12+
# (http://creativecommons.org/licenses/by-sa/3.0/)
13+
##################################################
14+
import lirc
15+
#initialize the IR daemon
16+
sockid = lirc.init("keyes", blocking = False)
17+
while True:
18+
#Wait for the next IR code to arrive. The codes are queued in a buffer before printing
19+
a= lirc.nextcode()
20+
if len(a) !=0:
21+
print a[0]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
########################################################
2+
# /etc/lirc/hardware.conf
3+
#
4+
# Arguments which will be used when launching lircd
5+
LIRCD_ARGS="--uinput"
6+
7+
# Don't start lircmd even if there seems to be a good config file
8+
# START_LIRCMD=false
9+
10+
# Don't start irexec, even if a good config file seems to exist.
11+
# START_IREXEC=false
12+
13+
# Try to load appropriate kernel modules
14+
LOAD_MODULES=true
15+
16+
# Run "lircd --driver=help" for a list of supported drivers.
17+
DRIVER="default"
18+
# usually /dev/lirc0 is the correct setting for systems using udev
19+
DEVICE="/dev/lirc0"
20+
MODULES="lirc_rpi"
21+
22+
# Default configuration files for your hardware if any
23+
LIRCD_CONF=""
24+
LIRCMD_CONF=""
25+
########################################################
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
echo " _____ _ ";
3+
echo " | __ \ | | ";
4+
echo " | | | | _____ _| |_ ___ _ __ ";
5+
echo " | | | |/ _ \ \/ / __/ _ \ '__| ";
6+
echo " | |__| | __/> <| || __/ | ";
7+
echo " |_____/ \___/_/\_\\__\___|_| _ _ ";
8+
echo " |_ _| | | | | (_) ";
9+
echo " | | _ __ __| |_ _ ___| |_ _ __ _ ___ ___ ";
10+
echo " | | | '_ \ / _\` | | | / __| __| '__| |/ _ \/ __|";
11+
echo " _| |_| | | | (_| | |_| \__ \ |_| | | | __/\__ \ ";
12+
echo " |_____|_| |_|\__,_|\__,_|___/\__|_| |_|\___||___/ ";
13+
echo " ";
14+
echo " ";
15+
echo " "
16+
printf "WELCOME TO IR RECEIVER SETUP FOR THE GOPIGO.\nPlease ensure internet connectivity before running this script.\nNOTE: Reboot Raspberry Pi after completion.\nPress ENTER to begin..."
17+
read
18+
19+
echo " "
20+
echo "Check for internet connectivity..."
21+
echo "=================================="
22+
wget -q --tries=2 --timeout=20 http://google.com
23+
if [ $? -eq 0 ];then
24+
echo "Connected"
25+
else
26+
echo "Unable to Connect, try again !!!"
27+
exit 0
28+
fi
29+
30+
echo " "
31+
echo "Installing Dependencies"
32+
echo "======================="
33+
sudo apt-get update
34+
sudo apt-get install lirc python-lirc
35+
36+
echo " "
37+
echo "Copying Config Files"
38+
echo "===================="
39+
sudo cp hardware_copy.conf /etc/lirc/hardware.conf
40+
sudo cp lircd_keyes.conf /etc/lirc/lircd.conf
41+
sudo cp lircrc_keyes /etc/lirc/lircrc
42+
echo "Files copied"
43+
44+
echo " "
45+
echo "Enabling LIRC"
46+
echo "======================="
47+
48+
if grep -q "lirc_dev" /etc/modules; then
49+
echo "Lib dev already present"
50+
else
51+
sudo echo "lirc_dev" >> /etc/modules
52+
echo "Lib dev added"
53+
fi
54+
55+
while true ; do
56+
echo ""
57+
echo "Check the hardware version of the IR receiver printed on the IR receiver module"
58+
echo "->Press 1 if the version is 1.0 or below"
59+
echo "->Press 2 if the version is 1.1 or above"
60+
printf "\nInput: "
61+
read INPUT
62+
# v1.0 and back have the IR receiver connected to white wire and v1.1 and v1.2 have it connected to the Yellow wire, so the GPIO changes
63+
if [ $INPUT -eq 1 ] ; then
64+
if grep -q "lirc_rpi gpio_in_pin=15" /etc/modules; then
65+
echo "Lib Rpi GPIO already present"
66+
67+
elif grep -q "lirc_rpi gpio_in_pin=14" /etc/modules; then
68+
sed -e s/"lirc_rpi gpio_in_pin=14"//g -i /etc/modules
69+
sudo echo "lirc_rpi gpio_in_pin=15" >> /etc/modules
70+
echo "Lib Rpi GPIO changed from pin 14 to 15"
71+
72+
else
73+
sudo echo "lirc_rpi gpio_in_pin=15" >> /etc/modules
74+
echo "Lib Rpi GPIO added"
75+
fi
76+
77+
if grep -q "dtoverlay=lirc-rpi,gpio_in_pin=15" /boot/config.txt; then
78+
echo "LIRC for Kernel 3.18 already present"
79+
80+
elif grep -q "dtoverlay=lirc-rpi,gpio_in_pin=14" /boot/config.txt; then
81+
sed -e s/"dtoverlay=lirc-rpi,gpio_in_pin=14"//g -i /boot/config.txt
82+
sudo echo "dtoverlay=lirc-rpi,gpio_in_pin=15" >> /boot/config.txt
83+
echo "LIRC for Kernel 3.18 changed from pin 14 to 15"
84+
85+
else
86+
sudo echo "dtoverlay=lirc-rpi,gpio_in_pin=15" >> /boot/config.txt
87+
echo "LIRC for Kernel 3.18 added"
88+
fi
89+
break
90+
91+
elif [ $INPUT -eq 2 ] ; then
92+
if grep -q "lirc_rpi gpio_in_pin=14" /etc/modules; then
93+
echo "Lib Rpi GPIO already present"
94+
95+
elif grep -q "lirc_rpi gpio_in_pin=15" /etc/modules; then
96+
sed -e s/"lirc_rpi gpio_in_pin=15"//g -i /etc/modules
97+
sudo echo "lirc_rpi gpio_in_pin=14" >> /etc/modules
98+
echo "Lib Rpi GPIO changed from pin 15 to 14"
99+
100+
else
101+
sudo echo "lirc_rpi gpio_in_pin=14" >> /etc/modules
102+
echo "Lib Rpi GPIO added"
103+
fi
104+
105+
if grep -q "dtoverlay=lirc-rpi,gpio_in_pin=14" /boot/config.txt; then
106+
echo "LIRC for Kernel 3.18 already present"
107+
108+
elif grep -q "dtoverlay=lirc-rpi,gpio_in_pin=15" /boot/config.txt; then
109+
sed -e s/"dtoverlay=lirc-rpi,gpio_in_pin=15"//g -i /boot/config.txt
110+
sudo echo "dtoverlay=lirc-rpi,gpio_in_pin=14" >> /boot/config.txt
111+
echo "LIRC for Kernel 3.18 changed from pin 15 to 14"
112+
113+
else
114+
sudo echo "dtoverlay=lirc-rpi,gpio_in_pin=14" >> /boot/config.txt
115+
echo "LIRC for Kernel 3.18 added"
116+
fi
117+
break
118+
else
119+
echo "Invalid choice"
120+
fi
121+
done
122+
123+
echo " "
124+
echo "Please restart the Raspberry Pi for the changes to take effect"
125+
echo " _____ ______ _____ _______ _____ _______ "
126+
echo " | __ \| ____|/ ____|__ __|/\ | __ \__ __|"
127+
echo " | |__) | |__ | (___ | | / \ | |__) | | | "
128+
echo " | _ /| __| \___ \ | | / /\ \ | _ / | | "
129+
echo " | | \ \| |____ ____) | | |/ ____ \| | \ \ | | "
130+
echo " |_| \_\______|_____/ |_/_/ \_\_| \_\ |_| "
131+
echo " "
132+
echo "To Restart type 'sudo reboot'"

0 commit comments

Comments
 (0)