Page 1 of 1

send ir signal with arduino mega

Posted: Sun Feb 16, 2020 3:17 pm
by volvodidi
Hi,
i tried to send ir Raw code with arduino mega, but not out of the programm memory PROGMEM but out of a integer
i declared:
const unsigned int AC_irSignalON[] = {3208,9868,576,1532,532,492,524,524,544,516,528,1552,528,492,548,504,524,508,524,508,524,508,528,504,528,496,544,500,544,1548,528,512,500,532,528,508,524,508,520,1540,524,508,496,540,496,544,496,544,496,536,524,508,524,1532,548,1536,528,516,524,};
but it is to slow. i get 60 values, but the timing doesn`t fit.
my idea is to record ir Signal with Arduino Mege on SD card, read it from SD card and send it. but first off all i try to send the signal out off an integer.
is it possible?
here is the skech:

Code: Select all

/*
 * IRremote: IRsendRawDemo - demonstrates sending IR codes with sendRaw
 * An IR LED must be connected to Arduino PWM pin 3. (Defualt configuration for UNO class Arduinos)
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 *
 * IRsendRawFlash - added by AnalysIR (via www.AnalysIR.com), 11 April 2016
 *
 * This example shows how to send a RAW signal, from flash instead of SRAM, using the IRremote library.
 *
 * It is more efficient to use the sendNEC style function to send NEC signals.
 * Use of sendRaw_Flash here, serves only as an example of using the function to save SRAM with RAW signals.
 * 
 * Typical Uses: Allows users to store a significant number of signals in flash for sending, without using up SRAM.
 *               This is particularly important for sending RAW AC signal. Typically only one or 2 AC signals could be stored in SRAM using the traditional sendRAW function.
 *               With this function a large number of RAW AC signals can be stored & sent from Flash on a standard Arduino, with no material SRAM overhead.
 *               For even more Flash & signal storage, consider using a Mega1280/2560 with 128K/256K of available Flash vs the standard of 32k bytes.
 *
 * SRAM usage: On the Author's dev system the Arduino IDE 1.6.8 reported only 220 SRAM usage & 8,052 bytes of Flash storage used for this sketch.
 *             In contrast, only one of the signals below will fit on a standard UNO using the example sendRAW function of IRremote (using SRAM to store the signal)
 */


#include <IRremote.h>

IRsend irsend; //Pin 9 on Mega

//const unsigned int AC_irSignalON[] PROGMEM = {3208,9868,576,1532,532,492,524,524,544,516,528,1552,528,492,548,504,524,508,524,508,524,508,528,504,528,496,544,500,544,1548,528,512,500,532,528,508,524,508,520,1540,524,508,496,540,496,544,496,544,496,536,524,508,524,1532,548,1536,528,516,524,}; //AnalysIR Batch Export (IRremote) - RAW
const unsigned int AC_irSignalON[] = {3208,9868,576,1532,532,492,524,524,544,516,528,1552,528,492,548,504,524,508,524,508,524,508,528,504,528,496,544,500,544,1548,528,512,500,532,528,508,524,508,520,1540,524,508,496,540,496,544,496,544,496,536,524,508,524,1532,548,1536,528,516,524,}; //AnalysIR Batch Export (IRremote) - RAW


void setup() {
  sendRAW_Flash(AC_irSignalON, sizeof(AC_irSignalON)/sizeof(int),38); //send AC signal #3 @ 38kHz
}

void loop() {
  
}
     
     void sendRAW_Flash(const unsigned int * signalArray, unsigned int signalLength, unsigned char carrierFreq) {

  irsend.enableIROut(carrierFreq); //initialise the carrier frequency for each signal to be sent
  
  for (unsigned int i=0;i<signalLength;i++){
    //tmp=pgm_read_word_near(&signalArray[i]);
   // tmp=cleanPanasonic(tmp); //not needed
    if (i & 1) irsend.space(pgm_read_word_near(&signalArray[i]));
    else irsend.mark(pgm_read_word_near(&signalArray[i]));
  }
  irsend.space(1);//make sure IR is turned off at end of signal

}
Dieter

Re: send ir signal with arduino mega

Posted: Sun Feb 16, 2020 7:20 pm
by AnalysIR
Hi Dieter

2 issues with your code (There may be others...but fix these first)
1. remove the railing comma from the array 524,}; ====> 524};
2. You are sending from flash so use the progmem definition (which you have commented out in the code you posted)


Also, this signal decodes as Friedrich28AC on AnlaysIR. So it looks good as is. To improve things use the 'Clean History' feature under Menu->Power Tools to clean the timings before exporting the signal from analysIR.

Its OK to save signals on a flash drive, but it is likely the timings will be a bit off, unless you clean them up in AnalysIR first or use an IR Learner like our recently announced LearnIRv3 which captures accurately to a few uSecs. (A standard IR receiver can be +/- 200uSecs).

If the signals do not change often then there is enough spare flash on the mega to store all your signals in flash, without the need for a flash drive.

Re: send ir signal with arduino mega

Posted: Sun Feb 16, 2020 8:00 pm
by volvodidi
Now i have made some changes in the code, the Signal contains 60 pulses, but the timing is lost.
Chanal2 is send with PROGMEM, Channel1 with the modified code.

i trie to build a freely-programmable timer switch with arduino to control my LG AC.

Dieter

Code: Select all

#include <IRremote.h>

IRsend irsend; //Pin 9 on Mega

//const unsigned int AC_irSignalON[] PROGMEM = {3208,9868,576,1532,532,492,524,524,544,516,528,1552,528,492,548,504,524,508,524,508,524,508,528,504,528,496,544,500,544,1548,528,512,500,532,528,508,524,508,520,1540,524,508,496,540,496,544,496,544,496,536,524,508,524,1532,548,1536,528,516,524}; //AnalysIR Batch Export (IRremote) - RAW
unsigned int AC_irSignalON[] = {3208,9868,576,1532,532,492,524,524,544,516,528,1552,528,492,548,504,524,508,524,508,524,508,528,504,528,496,544,500,544,1548,528,512,500,532,528,508,524,508,520,1540,524,508,496,540,496,544,496,544,496,536,524,508,524,1532,548,1536,528,516,524}; //AnalysIR Batch Export (IRremote) - RAW


void setup() {
  sendRAW_Flash(AC_irSignalON, sizeof(AC_irSignalON)/sizeof(int),38); //send AC signal #3 @ 38kHz
}

void loop() {
  
}
     
     void sendRAW_Flash(unsigned int * signalArray, unsigned int signalLength, unsigned char carrierFreq) {

  irsend.enableIROut(carrierFreq); //initialise the carrier frequency for each signal to be sent
  
  for (unsigned int i=0;i<signalLength;i++){
    //tmp=pgm_read_word_near(&signalArray[i]);
   // tmp=cleanPanasonic(tmp); //not needed
    if (i & 1) irsend.space(&signalArray[i]);
    else irsend.mark(&signalArray[i]);
  }
  irsend.space(1);//make sure IR is turned off at end of signal

}


Re: send ir signal with arduino mega

Posted: Sun Feb 16, 2020 8:49 pm
by AnalysIR
try changing this

Code: Select all

    if (i & 1) irsend.space(&signalArray[i]);
    else irsend.mark(&signalArray[i]);
to

Code: Select all

    if (i & 1) irsend.space(signalArray[i]);
    else irsend.mark(signalArray[i]);
removing the ampersand (&)

Re: send ir signal with arduino mega

Posted: Mon Feb 17, 2020 3:36 pm
by volvodidi
thats it, it works. :-)
And now the next step to fill the unsigned int AC_irSignalON from SD.
Dieter

Re: send ir signal with arduino mega

Posted: Mon Feb 17, 2020 4:05 pm
by AnalysIR
cool :)

Re: send ir signal with arduino mega

Posted: Mon Feb 28, 2022 12:22 pm
by richiii1
Thanks for the helpful information