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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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