Chat freely about anything...

User avatar
By OmarPoch
#82751 Hi to all
I have a project were i need store IR remote raw codes and to send them later.
I can get and send them by store the times to array.
The sections more important of my code is this

Code: Select all#include <IRremoteESP8266.h>
#include <IRSend.h>
#define maxLen 800
uint16_t rawData[maxLen];
....
// I store the code raw code into rawData here.
// If you are interested in this code, I've attached it
....
// then I send the raw data by use this sentence. It works well !!!!

irsend.sendRaw(rawData,800,38);



Now I want to store 8 raw Air Conditioners (with differents setups codes) into differents files, to get one of them when I need it. I can do it ussing a SD card, but I can not find how to do it ussing SPIFFS.

When I use SD card, I use this code
Code: Select all#include <SPI.h>
#include <SdFat.h>
SdFat sd;
SdFile irFile;

#define maxLen 800
uint16_t rawData[maxLen];

........
// to write array into a file

if (!irFile.open("cr1on.irc", O_RDWR | O_CREAT )) {
      sd.errorHalt("no se puede para grabar");
}

irFile.write(rawData,sizeof(rawData));
irFile.sync(); 
irFile.close();

.......

// then I send the raw data by use this sentence. It works well !!!!

if (!irFile.open("cr1on.irc", O_READ)) {
      sd.errorHalt("no se puede leer");
   }
    irFile.read(&rawData,sizeof(rawData));
  // close the file:
    irFile.close();

......
// then I send the raw data by use this sentence. It works well !!!!

irsend.sendRaw(rawData,800,38);



As I tell you, I can not find how to do it with SPIFFS. I only get text files examples and f.write sentences with unint8_t. But I need store uint16_t array.

Can you help me ?
Thanks a lot

Omar

PD This is the code that I use to get the raw IR Remote data and send it. It works very well !!!

Code: Select all/*
Author: AnalysIR
Revision: 1.0 - Initial release
Revision: 1.1 - update generic digitalPinToInterrupt to support most arduino platform

This code is provided to overcome an issue with Arduino IR libraries
It allows you to capture raw timings for signals longer than 255 marks & spaces.
Typical use case is for long Air conditioner signals.

You can use the output to plug back into IRremote, to resend the signal.

This Software was written by AnalysIR.

Usage: Free to use, subject to conditions posted on blog below.
Please credit AnalysIR and provide a link to our website/blog, where possible.

Copyright AnalysIR 2014-2019

Please refer to the blog posting for conditions associated with use.
http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/

Connections:
IR Receiver      Arduino
V+          ->  +5v
GND          ->  GND
Signal Out   ->  Digital Pin 2
(If using a 3V3 Arduino, you should connect V+ to +3V3)

Tested on UNO only
*/

#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include <IRremoteESP8266.h>
#include <IRSend.h>

#define LEDPIN 13
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800
#define rxPinIR D4 //pin D2 or D3 on standard arduinos. (other pins may be available on More mordern modules like MEga2560, DUE, ESP8266, ESP32)

uint16_t rawData[maxLen];

int rawDataLeng;

volatile  unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR

//IRrecv irrecv(5);
IRsend irsend(4);

void setup() {
  irsend.begin();
  Serial.begin(9600); //change BAUD rate as required
//  irrecv.enableIRIn();  // Start the receiver
 


  attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(F("Press the button on the remote now - once only"));
  delay(5000); // pause 5 secs
  if (x) { //if a signal is captured
    digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
    Serial.println();
    Serial.print(F("Raw: (")); //dump raw header format - for library
    Serial.print((x - 1));
    Serial.print(F(") "));
    detachInterrupt(digitalPinToInterrupt(rxPinIR));//stop interrupts & capture until finshed here
    for (int i = 1; i < x; i++) { //now dump the times
      if (!(i & 0x1)) Serial.print(F(""));
      Serial.print(irBuffer[i] - irBuffer[i - 1]);
      Serial.print(F(", "));
      rawData[i-1]=irBuffer[i] - irBuffer[i - 1];
    }
    rawDataLeng=x-1;
    rawData[x]={0}; // para darle final al string
    x = 0;
    Serial.println();
    Serial.println();
    digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
    attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
  }

  while(1){
   
   irsend.sendRaw(rawData,800,38); //Note the approach used to automatically calculate the size of the array. 
   Serial.print(rawDataLeng);Serial.println("  termine send");
   delay(5000); //In this example, the signal will be repeated every 5 seconds, approximately.
   ESP.wdtFeed();//resetea el wdt..hay que ponerlo SIEMPRE
  }

}

void rxIR_Interrupt_Handler() {
  if (x > maxLen) return; //ignore if irBuffer is already full
  irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions