16 Apr 2017, 00:00

RaspberryPi Infrared Remote Control, Controlled Using a Web Server

DRAFT

TV Remote

  1. Setup electronic; 1x 200ohm resistor, 1x 10k ohm resistor, 1x transistor (any NPN should work) and 1 Infrared LED (http://www.raspberry-pi-geek.com/Archive/2015/10/Raspberry-Pi-IR-remote)

    Fig 1 Fig 2

  2. Install and configure lirc

    sudo apt-get install lirc

    sudo nano /etc/modules

    # /etc/modules: kernel modules to load at boot time.
    #
    # This file contains the names of kernel modules that should be loaded
    # at boot time, one per line. Lines beginning with "#" are ignored.
    
    
    lirc_dev
    lirc_rpi gpio_out_pin=22
    

    sudo nano /etc/lirc/hardware.conf

    # /etc/lirc/hardware.conf
    #
    # Arguments which will be used when launching lircd
    LIRCD_ARGS="--uinput"
    
    
    #Don't start lircmd even if there seems to be a good config file
    #START_LIRCMD=false
    
    
    #Don't start irexec, even if a good config file seems to exist.
    #START_IREXEC=false
    
    
    #Try to load appropriate kernel modules
    LOAD_MODULES=true
    
    
    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"
    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"
    MODULES="lirc_rpi"
    
    
    # Default configuration files for your hardware if any
    LIRCD_CONF=""
    LIRCMD_CONF=""
    

    Create a configuration file for your remote (http://lirc-remotes.sourceforge.net/remotes-table.html). Here’s mine for a Sharp Aquos TV:

    # brand:                       Sharp
    # model no. of remote control: GA840WJSA
    # devices being controlled by this remote: Sharp Aquos LED TV
    #
    
    
    begin remote
    
    
        name  Sharp
        bits           15
        flags SPACE_ENC|CONST_LENGTH
        eps            30
        aeps          100
    
    
        one           320  1750
        zero          320   700
        ptrail        321
        gap          64241
        toggle_bit_mask 0x0
        toggle_mask    0x3FF
        min_repeat    2
    
    
        begin codes
            KEY_POWER                0x41A2
            KEY_DISPLAY              0x4362
            KEY_POWER_SOURCE         0x460E
            KEY_REWIND               0x448E
            KEY_PLAY                 0x450E
            KEY_FASTFORWARD          0x468E
            KEY_PAUSE                0x46CE
            KEY_PREV_CHAPTER         0x44CE
            KEY_STOP                 0x470E
            KEY_NEXT_CHAPTER         0x474E
            KEY_RECORD               0x458E
            KEY_OPTION               0x444E
            KEY_SLEEP                0x4162
            KEY_POWER_SAVING         0x47B2
            KEY_REC_STOP             0x478E
            KEY_1                    0x4202
            KEY_2                    0x4102
            KEY_3                    0x4302
            KEY_4                    0x4082
            KEY_5                    0x4282
            KEY_6                    0x4182
            KEY_7                    0x4382
            KEY_8                    0x4042
            KEY_9                    0x4242
            KEY_DOT                  0x4572
            KEY_0                    0x4142
            KEY_ENT                  0x4342
            KEY_CC                   0x40B2
            KEY_AV_MODE              0x407E
            KEY_VIEW_MODE            0x4016
            KEY_FLASHBACK            0x43D2
            KEY_MUTE                 0x43A2
            KEY_VOLUMEUP             0x40A2
            KEY_VOLUMEDOWN           0x42A2
            KEY_CHANNELUP            0x4222
            KEY_CHANNELDOWN          0x4122
            KEY_INPUT                0x4322
            KEY_AQUOS_NET            0x4726
            KEY_MENU                 0x4012
            KEY_DOCK                 0x475A
            KEY_UP                   0x43AA
            KEY_LEFT                 0x42BE
            KEY_ENTER                0x43BE
            KEY_RIGHT                0x41BE
            KEY_DOWN                 0x406A
            KEY_EXIT                 0x433E
            KEY_RETURN               0x40BE
            KEY_FAVORITE             0x47C6
            KEY_SURROUND             0x41DA
            KEY_AUDIO                0x4062
            KEY_FREEZE               0x432A
            KEY_RED                  0x4236
            KEY_GREEN                0x42C9
            KEY_YELLOW               0x4336
            KEY_BLUE                 0x40B6
    
    
        end codes
    
    
    end remote
    
  3. Reboot and start lircd

    sudo reboot
    sudo lircd --device /dev/lirc0
    
  4. Test lircd, send number 1

    irsend SEND_ONCE Sharp key_1
    
  5. Setup uwsgi server (https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04)

    sudo apt-get update
    sudo apt-get install python-pip python-dev
    sudo pip install virtualenv
    mkdir ~/tvremote
    cd ~/tvremote
    virtualenv tvremoteenv
    source tvremoteenv/bin/activate
    pip install uwsgi flask
    
  6. Install Static files

    extract this archive into your home directory ~/tvremote.

  7. Create and start uwsgi service (https://blog.frd.mn/how-to-set-up-proper-startstop-services-ubuntu-debian-mac-windows/)

    sudo cp ~/tvremote/uwsgi /etc/init.d/
    sudo update-rc.d uwsgi defaults
    sudo service uwsgi start
    
  8. Ready to test, point browser to your RPi’s IP address

    http://192.168.2.51:8080/index.html
    

Remote control screenshot