Skip to main content

IR remote control for Raspberry Pi

Project description

PiIR

CI

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. 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

To send an IR signal recorded in a file:

import piir

remote = piir.Remote('light.json', 17)
remote.send('off')

You can also send arbitrary data like this:

remote.send_data('09 2E 27')

or

remote.send_data(bytes([0x09, 0x2E, 0x27]))

TODO: write more

Hardware

Photo

I'm using Raspberry Pi Zero WH with four IR LEDs. Each LED has a measured current of 120mA, switched by a transitor connected to GPIO 17.

On an unrelated note, the big gold thing is a carbon dioxide sensor.

Schematic of LED

Also onboard is a 38KHz IR receiver from Sharp, connected to GPIO 22.

Schematic of receiver

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

PiIR-0.2.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PiIR-0.2.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file PiIR-0.2.2.tar.gz.

File metadata

  • Download URL: PiIR-0.2.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for PiIR-0.2.2.tar.gz
Algorithm Hash digest
SHA256 abfa2cac6b5978fc873526f6a237c8f0c17555e8ac5c31f5b1afb69204cb5f6d
MD5 f81d946c68f59ff8c54cf9142a8dbe59
BLAKE2b-256 7383a4e7b300f8f9d66e110a300e1958f29ce928504e862cd005d2b2a7aac0b5

See more details on using hashes here.

File details

Details for the file PiIR-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: PiIR-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for PiIR-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e4341b052b30d277a5e3c1a1e3bab3ee1061a02fa7f9f7051c244476fb46a8e3
MD5 b63cd50c37f1947b0a5fba677e0bf485
BLAKE2b-256 47207b5a29a91ddaa13f597a9a06ef9ed60b52567bb1886a162a698d1d6a6ac9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page