IR remote control for Raspberry Pi
Project description
PiIR
IR remote control for Raspberry Pi.
PiIR is a client program for pigpio, the excellent hardware-timed GPIO library.
Some code are taken from its sample program irrp.py
.
Features
- Records and plays IR remote control code.
- Decodes and encodes NEC, Sony, RC5, RC6, AEHA, Mitsubishi, Sharp and Nokia formats.
- Dumps decoded and prettified data to help you analyze your air conditioner's remote.
- Both command-line and programmatic control.
Requirements
- Raspberry Pi (any model where pigpio works should work)
- IR LED and/or receiver on GPIO (see Hardware section)
- Python >= 3.6
- Running pigpiod daemon
Installation
sudo pip3 install PiIR
Start pigpio daemon.
sudo systemctl enable pigpiod
sudo systemctl start pigpiod
Command line usage
In the following example, the transmit GPIO is 17 and the receive GPIO is 22. You may need to change them to fit your hardware configuration.
Recoding
piir record --gpio 22 --file light.json
This asks key names on your remote and to press the keys.
Name of the key (blank to finish): on
Press the key named "on".
Press the same key again to verify.
Name of the key (blank to finish): off
Press the key named "off".
Press the same key again to verify.
Name of the key (blank to finish):
Saved to "light.json".
Alternatively you can give key names in the command-line like this:
piir record --gpio 22 --file light.json on off cool warm bright dark full night
The resulted data is saved to light.json
.
The file will look like this:
{
"format": {
"preamble": [
8,
4
],
"coding": "ppm",
"zero": [
1,
1
],
"one": [
1,
3
],
"postamble": [
1
],
"pre_data": "2C 52",
"timebase": 430,
"gap": 75000
},
"keys": {
"on": "09 2D 24",
"off": "09 2F 26",
"cool": "39 90 A9",
"warm": "39 91 A8",
"bright": "09 2A 23",
"dark": "09 2B 22",
"full": "09 2C 25",
"night": "09 2E 27"
}
}
Playing
piir play --gpio 17 --file light.json off
This sends IR signal for off
from light.json
.
Analyzing
piir dump --gpio 22
This prints decoded data of received signal like this:
{
"preamble": [
8,
4
],
"coding": "ppm",
"zero": [
1,
1
],
"one": [
1,
3
],
"postamble": [
1
],
"pre_data": "01 10 00 40 BF FF 00 CC 33",
"post_data": "00 FF 80 7F 03 FC 01 FE 88 77 00 FF 00 FF FF 00 FF 00 FF 00 FF 00",
"byte_by_byte_complement": true,
"timebase": 420,
"gap": 49000,
"data": "92 42 64 00 00 00 00 00 53 F1 00"
}
It removes pre/post data and byte-by-byte complement from data
, so you can focus on the actual data changes.
It shold help analyzing data from stateful remotes such as air conditioners.
An example of programmatic data generation using this result can be found in piir/remotes
.
For more options try -h
.
API
Sending
To send an IR signal recorded in a file:
import piir
remote = piir.Remote('light.json', 17)
remote.send('off')
The first argument of Remote
can be a content of JSON instead of a file name.
You can also send arbitrary data like this:
remote.send_data('09 2E 27')
or
remote.send_data(bytes([0x09, 0x2E, 0x27]))
Recording
from piir.io import receive
from piir.decode import decode
keys = {}
while True:
data = decode(receive(22))
if data:
break
keys['keyname'] = data
receive
returns raw pulses as a list
.
It may be noise and other meaningless pulses.
decode
tries to decode it as remote data and returns a dict
if successful, otherwise returns None
.
When you recorded enough key data, you can call prettify
to consolidate them into a JSON data that can be fed to Remote
.
from piir.prettify import prettify
import json
print(json.dumps(prettify(keys), indent=2))
{
"format": {
"preamble": [
16,
8
],
"coding": "ppm",
"zero": [
1,
1
],
"one": [
1,
3
],
"postamble": [
1
],
"byte_by_byte_complement": true,
"timebase": 560,
"gap": 76000,
"carrier": 38000
},
"keys": {
"keyname": "80 12"
}
}
For more information, consult piir/cli.py.
Hardware
I'm using Raspberry Pi Zero WH with four IR LEDs. Each LED is driven by a transistor connected to GPIO 17 at a measured current of 120mA.
On an unrelated note, the big gold thing is a carbon dioxide sensor.
Also onboard is a 38KHz IR receiver from Sharp, connected to GPIO 22.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PiIR-0.2.5.tar.gz
.
File metadata
- Download URL: PiIR-0.2.5.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9c2f5b754b6060a4461edbc6e89cf79d1fcf1c8bf127221ed94466c57358cab |
|
MD5 | bf91540d7f45d60c4ced4891fb4b325f |
|
BLAKE2b-256 | decd52db0dba41e857210f4adc3c510f86748e5d6a0325ed0bd507478a25ba16 |
File details
Details for the file PiIR-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: PiIR-0.2.5-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7291a4df887f211083b0ff4b4bad5c8ac5cf72ce3f0171973aa651e4b44b4b5 |
|
MD5 | 878c9a040fbb5f6b827c147d07f5dba3 |
|
BLAKE2b-256 | 65f71f28e80816630e2f1562a5d61272b87c1a300130ba82e0a9b79006a89f4a |