Author Topic: making a simple IR transmitter  (Read 4780 times)

0 Members and 2 Guests are viewing this topic.

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3073
  • Country: us
Re: making a simple IR transmitter
« Reply #25 on: November 02, 2020, 02:17:29 pm »
You might be interested in this project:

https://youtu.be/taZQkVBzl-c

No code, unfortunately, but the details are discussed in depth.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ca
Re: making a simple IR transmitter
« Reply #26 on: November 02, 2020, 07:40:56 pm »
Hooray I think I got it working before destroying anything with my soldering iron. Just used a 270 ohm resistor. Seems pretty much how you do it. I encased it in glue gun to make it a bit more durable and safe.
« Last Edit: November 02, 2020, 08:43:13 pm by msuffidy »
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ca
Re: making a simple IR transmitter
« Reply #27 on: November 02, 2020, 10:39:10 pm »
Well either I have the wrong IR EM freq, or I missed the carrier. I have some ideas, but the code may have to be changed. I may just have to oscillate the current sample. Yup I just ran everything so fast it would be like a modulation and a test receiver got something.

I give up, I am starting over with a pure NEC protocol source that inputs the 32 bit transmission. Looks doable. It is not universal, but will allow me to quickly change the light puck, like 5hz or so I guess.
« Last Edit: November 03, 2020, 12:49:03 am by msuffidy »
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ca
Re: making a simple IR transmitter
« Reply #28 on: November 03, 2020, 04:12:49 am »
Well the good news is I seem to have it working, and I can use my arduino as a remote for the light puck. The bad news is my codes seem to be slightly different than the other one as per the linux ir-keytable response. It was doing NOTHING for a while until I experimented with lowering certain timings. I was relying on delay statements instead of using timer operations, and the execution time is different from the official timings.
The input string looks like this:
Y00010000111011110101000010101111Z
Here are the codes that concern me:
the real remote:
41426.337421: event type EV_MSC(0x04): scancode = 0x800a
mine:
42438.193464: event type EV_MSC(0x04): scancode = 0x80a
also:
https://web.ncf.ca/fs864/pickup/sketch_irled1-006.ino
« Last Edit: November 03, 2020, 08:01:02 am by msuffidy »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3073
  • Country: us
Re: making a simple IR transmitter
« Reply #29 on: November 03, 2020, 05:35:25 am »
Some immediate observations:

- digitalWrite has a lot of overhead. There are "fast" versions of digitalWrite/Read which do not have the overhead of a subroutine call or Arduino pin to AVR PORT bit conversion at run time. Just google "fast digitalWrite arduino".

- I am not sure about how delayMicroseconds is implemented, but I would use the avr library version:

https://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

which, with the proper compilation flags results in inline code.

- bit-banging the carrier signal is insane. I would set up a PWM pin to do that and then just enable or disable it every 562 us as needed.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ca
Re: making a simple IR transmitter
« Reply #30 on: November 03, 2020, 05:54:36 am »
Thanks for the comments, but hey it works so I am moving on now. I am going to make a c program that pwms between colorrs and some effects, and maybe even disco light applications. When I get some effects done I'll upload a video to youtube and post a link here.
« Last Edit: November 03, 2020, 08:08:05 am by msuffidy »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3073
  • Country: us
Re: making a simple IR transmitter
« Reply #31 on: November 03, 2020, 07:26:12 pm »
I went into the guts of this project:

https://github.com/z3t0/Arduino-IRremote

and extracted this code fragment which uses TIMER2 to generate the 38KHz signal on Arduino pin 3:

Code: [Select]
#include <Arduino.h>

#define SYSCLOCK F_CPU
#define IR_SEND_DUTY_CYCLE 50

#define TIMER_ENABLE_SEND_PWM    (TCCR2A |= _BV(COM2B1))    // Clear OC2B on Compare Match
#define TIMER_DISABLE_SEND_PWM   (TCCR2A &= ~(_BV(COM2B1))) // Normal port operation, OC2B disconnected.

static void timerConfigForSend(uint16_t aFrequencyKHz) {
    const uint16_t pwmval = (SYSCLOCK / 2000) / (aFrequencyKHz); // 2000 instead of 1000 because of Phase Correct PWM
    TCCR2A = _BV(WGM20); // PWM, Phase Correct, Top is OCR2A
    TCCR2B = _BV(WGM22) | _BV(CS20); // CS20 -> no prescaling
    OCR2A = pwmval;
    OCR2B = pwmval * IR_SEND_DUTY_CYCLE / 100;
}

void setup() {
  pinMode(3, OUTPUT);
  digitalWrite(3, 0);  // make sure it's low in between bursts
  timerConfigForSend(38);
}

void loop() {
  TIMER_ENABLE_SEND_PWM;
  delayMicroseconds(562);
  TIMER_DISABLE_SEND_PWM;
  delayMicroseconds(562*4);
}

The macro TIMER_ENABLE_SEND_PWM produces the 38KHz signal and TIMER_DISABLE_SEND_PWM reverts the pin to its configuration as a digital I/O pin.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ca
Re: making a simple IR transmitter
« Reply #32 on: November 03, 2020, 10:38:35 pm »
Here is the end product. Just some mood lighting. The source for this is at:
https://web.ncf.ca/fs864/pickup/lightfeeder.c

I figured out my code was different than the remote. It seems the nibbles on the first byte are reversed.






***Last note is that I went to the salvation army today and got a $1 remote and gave it another try for more distance with a smaller resistor. Originally I used a 270, and this time I used a 120. In all it works better, but only for like 2 more feet. It looks a bit more tidy. I tried to use a floppy header as a connector this time and light speaker wire.
« Last Edit: November 10, 2020, 04:33:11 am by msuffidy »
 

Offline VK3DRB

  • Super Contributor
  • ***
  • Posts: 2252
  • Country: au
Re: making a simple IR transmitter
« Reply #33 on: November 04, 2020, 11:38:58 am »
Consider using IrDA. Most remotes use IrDA because it saves power and ensures a high level of data integrity. Some low cost microcontrollers support IrDA encoding/decoding directly, but you can also use hardware that converts the IrDA format to a normal serial UART signal. This can be connected to a microcontroller UART or to a USB-serial converter like the FTDI-232.

I recently designed IR into a product. This application could not use the microcontroller because the IR to the UART had to be accessible if we had to get into bootloader mode. The IR transceiver chip is a TFBS4711 and the hardware encoder/decoder is a TIR1000. These are very easy to use and are cheap, with generally no extra logic required, other than a 16 x the UART baud rate frequency crystal (or just drive oscillator from a microcontroller). The frequency accuracy is not that critical, so you could an LMC555 timer if it is cheaper than a crystal. The TIR1000 can be mounted in any orientation. I have tested the circuit and it works a treat - even with bright LED/Fluoro interference. You can adjust the IR LED power and range from a few centimetres to several metres very easily by changing a resistor.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf