maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Accessories (https://talk.maemo.org/forumdisplay.php?f=17)
-   -   Infrared over Headphones (https://talk.maemo.org/showthread.php?t=89967)

Copernicus 2013-05-01 08:46

Infrared over Headphones
 
I've recently been researching how to access the infrared hardware on the newest crop of Android phones, and stumbled across something interesting -- there have already been several attempts to port the LIRC server to Android. This surprised me, because up to now most Android devices lacked IR; however, all these ports were using LIRC's audio interface.

"Audio interface? What audio interface?", I asked.

As it turns out, there's a surprisingly simple way to generate IR signals via a sound card. Not being a hardware person, I've been ignoring the various hardware hacks described on the LIRC website; however, it seems that this particular hack is usable on cell phone devices. In fact, at least one group has put together a battery-boosted version of the audio-jack IR transmitter.

Also interesting to me is that there is an infrared receiver device also able to be connected to a sound card.

The possibilities are intriguing; this could be an easy way to bring IR to phones like the N9 or the upcoming Jolla phone. Also, having an IR receiver could allow the N900 to be turned into a "learning remote".

However, as I may have mentioned, I'm clueless when it comes to hardware. A question for those who are not: just how tricky do these LIRC hardware hacks look to you? What sort of risks do you think they pose when used with a cell phone? And, about how expensive would you expect the final product to be? :) The "Irdroid" device appears to be selling for $36, and I'm thinking of picking one up asap to get my own app (Pierogi) working with it, but it'd be nice to be able to offer these audio IR ports at a somewhat lower price...

HtheB 2013-05-01 10:00

Re: Infrared over Headphones
 
you mean something like this?

http://www.mactech.com/content_image...9848426816.jpg

check out:
http://www.mactech.com/2004/08/06/ip...remote-control
and
http://www.instructables.com/id/DIY-...r-iPhone-iPod/

nokiabot 2013-05-01 10:35

Re: Infrared over Headphones
 
Hold your breath man i told you keep up the devlopment when asking a java one.
Coz there is to be a wave of ir devices by chineese oems followed by brands:)
i personally saw 2 tabs and a phone with ir port.
Also i saw a andro or java?? Might be propetiary tab with kick stand having a seperate media remote insted.
Cant comment on the ext ir as when i asked today they said it a scam but saw a guy using one they asked him he said it works limited possiblites::

your universe just got a byte better:)

p.s. Dn ask about those devices. They are chineese gadgets who always come with something intresting to sell there products some are good enough even saw a device much earlier with ir gesture sensor..

pichlo 2013-05-01 12:16

Re: Infrared over Headphones
 
It is very simple to make and there is no way to justify the $38 tag. DIY production would be about $5 if you buy all the components, although most hobbyists will be able to bash it together for free from random bits they've found in the drawer. And it's cool because sending an IR signal is as simple as playing a prerecorded audio.

There are no risks to the phone that I can think of. The load the LEDs represent is about a quarter of a load presented by your average headset, so they won't damage your audio output. The LEDs do, however, require a bit higher voltage (even though less current) than the headphones. Which means there might be the risk of the phone not producing a high enough output to light them up. Does anyne know what the max audio power is? Anyway, if it turns out not enough then a boosted version would do the trick. And while we are playing with the boost, we can as well double the IR frequency with no changes to the phone, at the cost of using 4 LEDs instead of 2.

The input might be a challenge though. How I wish there was an external mic or line in on my phone!

Copernicus 2013-05-01 16:22

Re: Infrared over Headphones
 
Quote:

Originally Posted by pichlo (Post 1340417)
The input might be a challenge though. How I wish there was an external mic or line in on my phone!

Er, the earphones that come with the N900 have a microphone (for use in talking on the phone) -- wouldn't that mechanism work just as well for general audio input?

sixwheeledbeast 2013-05-01 16:46

Re: Infrared over Headphones
 
This covers my thoughts on IR power I guess you haven't read it?
http://talk.maemo.org/showthread.php?t=25998

Personally I would look at investigating Bluetooth Infrared transceivers.
After my attempts at making a IR repeater failed due to too much IR noise, bluetooth would solve this and the range issue in one.

Copernicus 2013-05-01 18:37

Re: Infrared over Headphones
 
Quote:

Originally Posted by sixwheeledbeast (Post 1340475)
This covers my thoughts on IR power I guess you haven't read it?
http://talk.maemo.org/showthread.php?t=25998

Nope, I missed that one. :) I guess that's why the Irdroid dongle has includes a battery...

Quote:

Personally I would look at investigating Bluetooth Infrared transceivers.
Yeah, I suppose I should look into that as well. I've been trying to avoid Bluetooth for a while, it seems like a lot more hassle to work with than IR. :)

Estel 2013-06-06 14:07

Re: Infrared over Headphones
 
Hey, it's great idea! If you manage to come up with writing/porting some software to control it, I'll gladly patch-up a receiver and transmitter and send it to you, of course as a donation.

As you've said, it might be nice idea to boost N900 Ir output power:
http://cache.gizmodo.com/assets/reso...er_tvbgone.jpg

...while still keeping "brain" processed by N900 (like with Pierogi), allowing much better functions, than any "learning remote" in universe (like stateful AC control).

Keeping my thumbs for it!

/Estel

pichlo 2013-06-06 15:40

Re: Infrared over Headphones
 
Quote:

Originally Posted by Copernicus (Post 1340471)
Er, the earphones that come with the N900 have a microphone (for use in talking on the phone) -- wouldn't that mechanism work just as well for general audio input?

I wonder what the frequency response of that mic input is. I would not expect it to go far beyond 15kHz, and even that is very optimistic. It is probably limited to something like 4kHz, just enough for speech. The carrier frequency on many remotes go to tens of kHz.

Copernicus 2013-06-06 16:16

Re: Infrared over Headphones
 
Quote:

Originally Posted by Estel (Post 1349989)
Hey, it's great idea! If you manage to come up with writing/porting some software to control it, I'll gladly patch-up a receiver and transmitter and send it to you, of course as a donation.

Actually, I'm kind of late to the game with this. The LIRC server has apparently had support for this particular gadget for some years. (Of course, this also means that Irreco & co. have as well, as they are all using the LIRC server.)

So, in short, your N900 can already control it. :)

Let me see if I can't get the same support into Pierogi. I can probably get the software to you faster than you can get the hardware to me... :) :) (Of course, adding "learning" functionality to Pierogi is another question, that'll take a lot more effort.)

Copernicus 2013-06-06 16:23

Re: Infrared over Headphones
 
Quote:

Originally Posted by pichlo (Post 1350011)
I wonder what the frequency response of that mic input is. I would not expect it to go far beyond 15kHz, and even that is very optimistic. It is probably limited to something like 4kHz, just enough for speech. The carrier frequency on many remotes go to tens of kHz.

Yeah, the most common carrier frequencies I've seen are around 33 kHz, 38 kHz, and 55 kHz. On the other hand, since we're just receiving IR here, it isn't 100% necessary to be able to recognize the carrier spikes; their only purpose, really, is to help separate the signal from the noise. If we can at least pick out the "on" and "off" periods in the signal, that is sufficient to learn commands, and that generally doesn't require nearly as much accuracy...

Estel 2013-06-07 01:19

Re: Infrared over Headphones
 
Quote:

Originally Posted by Copernicus (Post 1350021)
Actually, I'm kind of late to the game with this. The LIRC server has apparently had support for this particular gadget for some years. (Of course, this also means that Irreco & co. have as well, as they are all using the LIRC server.)

So, in short, your N900 can already control it. :)

Well, for sure Irreco and co doesn't have it in their source code - probably require talking with LIRC server directly?

Quote:

Originally Posted by Copernicus (Post 1350021)
Let me see if I can't get the same support into Pierogi. I can probably get the software to you faster than you can get the hardware to me... :) :)

Haha, that's for sure, considering how fast you're with implementing ideas into nicely working and polished programs :)

In this case, it's even better - I would like to test any "monstrosity" I've created before sending it to you, as I've never build something like that before. By briefly looking at example schematics found in NET, it's so simple, that could be used to teach kids as "my first project with soldering iron", but you never know until you actually start to patch it up ;)

/Estel

Swordfish II 2015-05-28 02:06

Re: Infrared over Headphones
 
Hey Copernicus did you ever end up converting pierogi files to audio to support this?

I recently made one of these audio ir transmitters with a 3.5mm jack and 2 ir leds taken from a remote. A few tv-b-gone wav files and it is working nicely for on/off of select tv's. Range is pretty good, about that of a normal remote.

But I would love to have more functionality which pierogi has. Most of the LIRC is based around an input to create an output file...haven't been able to figure out how to convert the LIRC output conf to a wav.

Copernicus 2015-05-28 02:30

Re: Infrared over Headphones
 
Quote:

Originally Posted by Swordfish II (Post 1471693)
Hey Copernicus did you ever end up converting pierogi files to audio to support this?

Nope, I never did. As I may have mentioned, I'm kinda clueless about hardware. :) On the other hand, I did finally pick up a USB IR dongle that works beautifully with Linux on my PC, so I've finally started encoding the pile of remote controls I've been stacking up here for years... :) It looks like I might be able to connect PIerogi to USB IR for free, if it follows the same protocol LIRC uses.

But yeah, setting up the audio-IR interface shouldn't be that hard, either. The trick is just to create an audio waveform that matches the carrier signal being used by the remote (most often, this is something like a 38 kHZ frequency). Then, you just send that audio waveform when you want the LED on, and go silent when you want it off. So it isn't really a matter of encoding the entire command as a .wav file, just the carrier signal.

Anyway, I'm pretty sure that LIRC does support this already, although I'm sketchy on the details; so there should be some way to get LIRC running on it right now...

pichlo 2015-05-28 12:03

Re: Infrared over Headphones
 
3 Attachment(s)
Quote:

Originally Posted by Copernicus (Post 1471694)
The trick is just to create an audio waveform that matches the carrier signal being used by the remote (most often, this is something like a 38 kHZ frequency).

38kHz sounds tricky but it is actually easier than you think, provided the line output is high enough.

LEDs need some minimum voltage to light up. Imagine an audio line playing a sine waveform and an LED connected between the live end and the ground (remember a protective resistor, but the audio output's internal impedance should suffice in this simple scenario). At the points where the waveform level is below the threshold, the LED will be dark. Where the level exceeds the threshold, it will be lit up, like this:

Attachment 37138

Now connect a second LED anti-parallel to the first one. It will act exactly the same as the first one, only on the negative part of the waveform:

Attachment 37139

However the receiver does not know that the light comes from two LEDs and not one. It knows nothing about the original sine waveform either. All it can see is light pulses.

Note that the light pulses come at a frequency that is double the frequency of the original waveform:

Attachment 37140

You can double the frequency again (to 4x the original waveform) by using the above arrangement in e.g. the left channel, the same on the right channel (i.e. 4 LEDs altogether) and playing the waveform through the two channels phase shifted by 90°.

Swordfish II 2015-05-28 16:43

Re: Infrared over Headphones
 
I have figured out my issue converting IR to audio :). Irscrutinizer is pretty nifty, and 44100 Sample freq 2 channels 8 bits works well and keeps files small.

One question that maybe you could answer for me, Going through the LIRC database I see two different formats if you will. In one (usually in LIRC 0.6 or earlier) codes are very long, like this:
KEY_1 0x0000000000000144 # Was: 1

But in the newer LIRC format (usually 0.8 or higher) codes are expressed like this:

KEY_1 0x8877 # Was: ONE

Audio encoded as is, I know the top format works (tested it on my tv), but I am not sure the bottom format works...is the bottom format a shorthand to get rid of all those zeros?

As a side note, if you would like to add this to pierogi, I am willing to share my audio files (and would like to convert your files for my own personal use, not for distro)

Copernicus 2015-05-28 17:47

Re: Infrared over Headphones
 
Quote:

Originally Posted by Swordfish II (Post 1471744)
One question that maybe you could answer for me, Going through the LIRC database I see two different formats if you will. In one (usually in LIRC 0.6 or earlier) codes are very long, like this:
KEY_1 0x0000000000000144 # Was: 1

But in the newer LIRC format (usually 0.8 or higher) codes are expressed like this:

KEY_1 0x8877 # Was: ONE

Audio encoded as is, I know the top format works (tested it on my tv), but I am not sure the bottom format works...is the bottom format a shorthand to get rid of all those zeros?

Hmm. I don't know much about earlier versions of LIRC; but, for most config files, the value provided for the key is the "code" that gets sent in the command. I don't really see how you can translate "0x0000000000000144" directly into an audio file that does something to your TV; you need to have the additional info at the top of the LIRC file in order to decipher how the command is encoded as IR pulses. For example, an LG tv config file will have something like this:

Code:

begin remote

  name  LG_MKJ61842704_TV
  bits          16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header      9069  4455
  one          597  1651
  zero          597  531
  ptrail        591
  repeat      9055  2222
  pre_data_bits  16
  pre_data      0x20DF
  gap          108123
  toggle_bit_mask 0x0

      begin codes
...
          KEY_1                    0x8877
...
      end codes
end remote

You can read this as follows:

Bits: this remote sends 16 bits of "command" data for each key pressed. Flags: the bits are "space encoded", meaning that the value of each bit (zero or one) is determined by the length of time the IR led is on or off; "constant length" means that, regardless of how long a single sequence of bits takes to finish, the next sequence will start at a fixed time after the start of the current one. (The "eps" and "aeps" values are only of interest when receiving commands, so I generally ignore them.)

The "header" specifies that, before any bits are sent, the LED should be left on for 9069 uSec, and off for 4455 uSec. (These are values determined by LIRC's "irrecord" utility off of a physical remote control; they may vary from the official timings for this protocol, but probably not enough to matter.) The "one" specifies that the binary bit "1" is sent by turning the IR on for 597 uSec and off for 1651 uSec, and the "zero" specifies that a "0" bit is on for 597 uSec and off for 531 uSec. (Again, these are a bit off from the official values, but close enough not to matter.) Finally, after the entire sequence has been sent, a last "on" pulse of 591 uSec is sent, and then the IR is kept off until the next sequence starts.

(The "repeat" value describes a special feature of the NEC protocol, which I'll skip here.)

The "gap", in this case, describes the amount of time, in uSec, between the start of one full sequence of pulses and the start of the next. (If the "CONST_LENGTH" flag hadn't been set, the gap would be the time from the end of one sequence to the beginning of the next.)

Now, we get to the interesting part. Before we start sending the "command" bits, we need to send the "device" bits. In this case, these are the 16 bits of "pre_data". In hexadecimal, they are shown as 0x20DF; so, in binary, that should be 0010000011011111. For each of these bits, you would now turn the LED on and off corresponding to the on/off times defined above.

Then, you can now send the command for the key. In this case, KEY_1 is 0x8877; which, in binary, should be 1000100001110111. Again, these get converted to IR timings using the values for 1 and 0 defined above.

So, in total, the IR should be flipped on and off once for the header, thirty-two more times for all the "device" and "command" bits, then flipped on once more for the trailing bit and then turned off until the next command starts.

Quote:

As a side note, if you would like to add this to pierogi, I am willing to share my audio files (and would like to convert your files for my own personal use, not for distro)
Thanks! But, I don't think there is really a question of maintaining individual audio files here; both the LIRC and Pierogi construct their timing strings dynamically as needed. It'd be awfully unwieldy otherwise! All I really need to do is set up Pierogi to switch that particular sound on and off (in a precise enough manner to match the LED timings); everything else should fall into place after that...

jellyroll 2015-05-28 21:16

Re: Infrared over Headphones
 
I know that the infrared security is messed up but still don't understand why infrared is disappeared on de modern days cell phones. I got a Palm OS device that can read and write infrared signals. Now I'm happy to use Pierogi on the N900.

Swordfish II 2015-05-28 21:49

Re: Infrared over Headphones
 
Quote:

Originally Posted by Copernicus (Post 1471751)
Hmm. I don't knand how it convertsow much about earlier versions of LIRC; but, for most config files, the value provided for the key is the "code" that gets sent in the command. I don't really see how you can translate "0x0000000000000144" directly into an audio file that does something to your TV; you need to have the additional info at the top of the LIRC file in order to decipher how the command is encoded as IR pulses. For example, an LG tv config file will have something like this:

Code:

begin remote

  name  LG_MKJ61842704_TV
  bits          16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header      9069  4455
  one          597  1651
  zero          597  531
  ptrail        591
  repeat      9055  2222
  pre_data_bits  16
  pre_data      0x20DF
  gap          108123
  toggle_bit_mask 0x0

      begin codes
...
          KEY_1                    0x8877
...
      end codes
end remote

You can read this as follows:

Bits: this remote sends 16 bits of "command" data for each key pressed. Flags: the bits are "space encoded", meaning that the value of each bit (zero or one) is determined by the length of time the IR led is on or off; "constant length" means that, regardless of how long a single sequence of bits takes to finish, the next sequence will start at a fixed time after the start of the current one. (The "eps" and "aeps" values are only of interest when receiving commands, so I generally ignore them.)

The "header" specifies that, before any bits are sent, the LED should be left on for 9069 uSec, and off for 4455 uSec. (These are values determined by LIRC's "irrecord" utility off of a physical remote control; they may vary from the official timings for this protocol, but probably not enough to matter.) The "one" specifies that the binary bit "1" is sent by turning the IR on for 597 uSec and off for 1651 uSec, and the "zero" specifies that a "0" bit is on for 597 uSec and off for 531 uSec. (Again, these are a bit off from the official values, but close enough not to matter.) Finally, after the entire sequence has been sent, a last "on" pulse of 591 uSec is sent, and then the IR is kept off until the next sequence starts.

(The "repeat" value describes a special feature of the NEC protocol, which I'll skip here.)

The "gap", in this case, describes the amount of time, in uSec, between the start of one full sequence of pulses and the start of the next. (If the "CONST_LENGTH" flag hadn't been set, the gap would be the time from the end of one sequence to the beginning of the next.)

Now, we get to the interesting part. Before we start sending the "command" bits, we need to send the "device" bits. In this case, these are the 16 bits of "pre_data". In hexadecimal, they are shown as 0x20DF; so, in binary, that should be 0010000011011111. For each of these bits, you would now turn the LED on and off corresponding to the on/off times defined above.

Then, you can now send the command for the key. In this case, KEY_1 is 0x8877; which, in binary, should be 1000100001110111. Again, these get converted to IR timings using the values for 1 and 0 defined above.

So, in total, the IR should be flipped on and off once for the header, thirty-two more times for all the "device" and "command" bits, then flipped on once more for the trailing bit and then turned off until the next command starts.



Thanks! But, I don't think there is really a question of maintaining individual audio files here; both the LIRC and Pierogi construct their timing strings dynamically as needed. It'd be awfully unwieldy otherwise! All I really need to do is set up Pierogi to switch that particular sound on and off (in a precise enough manner to match the LED timings); everything else should fall into place after that...

Yeah I understand how the LIRC files work (just shortened things to show the part relevant) it just seems weird to me how some LIRC keys are incredibly long (goldstar for instance) and some are short (like the LG example you gave). Guess I'll just have to test more.

Swordfish II 2015-05-28 21:53

Re: Infrared over Headphones
 
Quote:

Originally Posted by jellyroll (Post 1471778)
I know that the infrared security is messed up but still don't understand why infrared is disappeared on de modern days cell phones. I got a Palm OS device that can read and write infrared signals. Now I'm happy to use Pierogi on the N900.

They disappeared for a while since IRDa functionality was replaced by Bluetooth. They are making a comeback these days in the high end tablets and phones (Galaxy S 4/5) but are only transmitters and the sole purpose is as a tv remote.

Copernicus 2015-05-28 22:06

Re: Infrared over Headphones
 
Quote:

Originally Posted by Swordfish II (Post 1471779)
it just seems weird to me how some LIRC keys are incredibly long (goldstar for instance) and some are short (like the LG example you gave).

Ah! Yeah, if you look at the top of that particular Goldstar config file, you'll see the line:

Code:

  bits          12
This means that only the last twelve bits of that code are significant (i.e., 0x144). The rest are ignored.

Swordfish II 2015-05-29 03:11

Re: Infrared over Headphones
 
AH HA! Thank you!

So correct me if I am mistaken but the 0x8877 (example you gave) could also be expressed as 0x0000000000008877 with the 16bit header

Copernicus 2015-05-29 06:57

Re: Infrared over Headphones
 
Quote:

Originally Posted by Swordfish II (Post 1471788)
So correct me if I am mistaken but the 0x8877 (example you gave) could also be expressed as 0x0000000000008877 with the 16bit header

Yup, you can pile on as many leading zeros as you want. :)

pichlo 2015-05-29 10:16

Re: Infrared over Headphones
 
Quote:

Originally Posted by Swordfish II (Post 1471780)
They disappeared for a while since IRDa functionality was replaced by Bluetooth. They are making a comeback these days in the high end tablets and phones (Galaxy S 4/5) but are only transmitters and the sole purpose is as a tv remote.

Except, at least in my personal experience, IrDA actually works. Bluetooth usually does not.


All times are GMT. The time now is 08:13.

vBulletin® Version 3.8.8