OpenWrt Forum Archive

Topic: Need help: WR703N: Send and receive IR with GPIOs

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Wouldn't it be nice if we could use the GPIOs on the WR703N to send and recive infrared remote control signals?

I wonder whether it would be possible to port
http://aron.ws/projects/lirc_rpi/
to work with the WR703N.

Here is someone who did something similar (send only) with a DIR-300 running OpenWRT:
http://www.roberteklund.org/projects/di … an-IR-diod

LIRC should even be able to operate 433 MHz radios...

Also, looking at this thread
https://forum.openwrt.org/viewtopic.php?id=735
there is a tarball
http://silverninja.net/~naz/lirc.tar.gz
which appears to contain a patch that includes a driver called
lirc_openwrt.c
that appears to do exactly what I need. Now the question is, how do we get this compiled for AA?

(Last edited by probono on 25 Dec 2013, 17:45)

Good idea, but it is not as easy as it looks at first sight...

First, on a purely hardware point of view, you will have to be careful, the GPIOs o nthe TL-WR703N are 2.7V only, NOT 5V nor even 3.3V tolerant.

You will have to adjust the IR receiver's output level to this voltage, the simplest is by using a resistor bridge. On the output side, you will have to make sure that a 2.7V drive level will fully turn on the IR LEDs too.

Basically, you will need 2 GPIO outputs and 1 GPIO input with interrupts. If you dan't want to mess with fine SMD soldering ,the easiest on the TL-WR703N would be to use the unmounted through-hole LED in parallele to the normal LED as the IR LED output GPIO, to wire the IR receiver in parallel on the RESET switch and to use the USB power (GPIO8) for powering the IR receiver.

Second, the kernel space driver: the proposed patch is using interrupts for the IR Receiver input, but AFAIK this is not implemented for the AR9331 SoC, only GPIO polling is working, so you will have to take the AR9331 datasheet and implement GPIO IRQs into the kernel first, or modify the driver to work with polled GPIOs, if it s possible.

Third, how to compile the stuff for AA: as explained above, this depends if you are using IRQs or polled GPIOs for the IR receiver's output: in the first case, this would require modifying the GPIOs handling in the AA kernel to support AR9331 GPIO IRQs and create a kmod-lirc-gpio kernel module for it. In the second case, only the additional kernel module is required.

In both cases, you will have to create a custom kernel package, check the Wiki:
http://wiki.openwrt.org/doc/howto/build
http://wiki.openwrt.org/doc/devel/start
http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk
http://wiki.openwrt.org/doc/devel/packages

Thanks Squonk. Didn't know about the 2.7V. Are you sure about the pins not being 3.3V tolerant? (Don't want to try ;-)

Right now I have an ATmega328p running an Arduino sketch hooked up to 3.3V power and have connected it to TP_IN and TP_OUT for serial connection, and it appears to work well for me. The ATmega328p in turn is connected to a TSOP infrared reciver and an IR LED. By removing the ATmega328p I could bring down the BOM somewhat.

Do I really have to build the whole kernel or can I just build a kernel module in a way that it is compatible with the stock BB packages?

(Last edited by probono on 26 Dec 2013, 13:20)

probono wrote:

Thanks Squonk. Didn't know about the 2.7V. Are you sure about the pins not being 3.3V tolerant? (Don't want to try ;-)

Actually, the I/O supply voltage is 2.5 V +/-10% (2.25 V to 2.75 V), see table 7.2 page 307 in AR9331 datasheet:
Censored

According to the same datasheet, the tolerance to 3.3 V is not specified, the only given GPIO characteristics are the logic level threshold voltages in table 7.4 page 308.

probono wrote:

Right now I have an ATmega328p running an Arduino sketch hooked up to 3.3V power and have connected it to TP_IN and TP_OUT for serial connection, and it appears to work well for me. The ATmega328p in turn is connected to a TSOP infrared reciver and an IR LED. By removing the ATmega328p I could bring down the BOM somewhat.

Yes, but just a 2.4k head/7.5k foot resistor divider will not cost that much, and you will be on the safe side for the IR receiver side. On the IR LED side, you'd better put several IR LEDs in series to get a sufficient range, and in this case, a transistor with a base series resistor is required anyway.

probono wrote:

Do I really have to build the whole kernel or can I just build a kernel module in a way that it is compatible with the stock BB packages?

Kernel version/name includes a hash checksum of config options, and the kernel modifications will depend on that checksum as it is part of the kernel version/name. The goal is to ensure that the kmods to be installed have been compiled using exactly the same options as the main kernel:
https://forum.openwrt.org/viewtopic.php … 69#p180769

I may be wrong, but as you will need a new config option for your kmod-lirc-gpio module, ypu won't be able to get the exact same options as in the stock BB kernel...

But IMHO, the biggest problem is related to GPIO IRQ handling for an AR9331 kernel.

Squonk wrote:

I may be wrong, but as you will need a new config option for your kmod-lirc-gpio module, ypu won't be able to get the exact same options as in the stock BB kernel...

This kind of stuff really drives me insane. Isn't the whole purpose of a "SDK" to compile binary compatible software after all?

Anyhow, I may be going down this route for receiving:
http://wiki.openwrt.org/doc/howto/lirc-audio_alsa
and use the USB sound card's microphone input for the TSOP.

Still, I would like to use a GPIO for sending, with a transistor, IR LED, and resistor.

(Last edited by probono on 28 Dec 2013, 20:46)

Ouch...

# Automatically installed Ubuntu 12.04.2 LTS, Precise Pangolin 32-bit on VMWare
# Exact same error on Fedora 20 32-bit on VMware

# Install prerequisites
sudo apt-get install subversion git build-essential libncurses5-dev zlib1g-dev gawk flex

# Download and unpack the SDK of the released OpenWrt version
wget "http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2"
tar xfvz OpenWrt-SDK*
cd OpenWrt-SDK*

# Get the makefiles of the packages
./scripts/feeds update -a

# Patch the lirc makefile so that it contains the audio_alsa driver
nano ./feeds/packages/utils/lirc/Makefile
# Manually replace 
# --with-driver="mceusb" 
# with 
# --with-driver="audio_alsa"

# Build
make package/lirc/compile V=s

# Gives:
# configure: error: C compiler cannot create executables
# See `config.log' for more details.

EDIT: Inspecting config.log showed that I had to install ccache. Thereafter, I ran into problems (it complained about missing headers and finally said something along the lines of "the driver cannot installed for this system". I just went ahead and deleted the areas concerning these files and the error in ./build_dir/linux-ar71xx_generic/lirc-0.8.7/configure, and voila, i was almost able to compile lirc packages with audio_alsa enabled.

But now I get

Package lirc is missing dependencies for the following libraries:
libasound.so.2

However, it is there:
./staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib/libasound.so.2

(Last edited by probono on 28 Dec 2013, 22:47)

In recent kernels there is also a driver Linux/drivers/media/rc/gpio-ir-recv.c

config IR_GPIO_CIR
    tristate "GPIO IR remote control"
    depends on RC_CORE
    ---help---
       Say Y if you want to use GPIO based IR Receiver.

       To compile this driver as a module, choose M here: the module will
       be called gpio-ir-recv.

Can we use this in OpenWrt?

About the GPIO interrupts, isn't that what https://dev.openwrt.org/browser/trunk/t … 71xx/irq.c is all about?

Also, I see that https://github.com/GBert/openwrt-misc/t … /gpio-test appears to be working with GPIO interrupts on the AR9331?

Also, there appears to be a patch for FreeBSD which implements it at http://lists.freebsd.org/pipermail/free … 02323.html

(Last edited by probono on 1 Jan 2015, 13:12)

There now seems to be code to handle IRQs/Interrupts on the GPIOs:
https://github.com/mrtos/gpio-irq-handler

So would it be possible to implement IR receiving now?

(Last edited by probono on 30 Jul 2015, 08:41)

Still no one?

The discussion might have continued from here.