Sending RAW IR signal by bit
Posted: Wed Jun 12, 2024 2:42 pm
Hello, everyone. I'm trying to send IR signals to a Gree AC. My raw data is very long and arduino couldn't support all the data of temperatures, therefore I had to figure out how the arrays were changing depending on the temperature. I did that and I created a code that changes the binary version of turn OFF command to the binary array of any temperature I want. So if I choose 16, the function will change the binary array to the binary array of temperature 16. Then there comes the problem I'm facing right now.
After I have the corret binary array to the temperature I want, I send that to a function that I created called SendRawByBit, which was supposed to work similarly to the sendRaw function, but it's not working and I don't know why. I'm reading the documentation and I don't quite understand everything... I think the problem might be related to the irsend.mark and irsend.space methods. I'm probrably missing something...
I know that is not the ideal to send the temperature to my sendRawByBit function, but in this case, I have very long arrays and when I convert to bytes, I get 25 bytes + 1 final bit. And this final bit changes if the temperature is 28. But anyway, I know that this code sends the right arrays because I already printed everything and compared with my original raw arrays and they are the same. So that's why I believe the problem is with mark and space methods. I read on the documentation that mark depends on the correct implementation of delayMicroseconds() and micros() for time pause... But I don't know what I need to change for it to work.
A normalized raw array looks like this:
Raw: 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700,40000, 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 40000, 9000, 4500, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700
All the raw arrays when converted to binary follow this sequence:
700 1650 = 1
700 700 = 0
Hh - header (9000,4000)
S = short (20000)
L = long (40000)
p - 700
Hh (35bits) pS (32bits) pLHh(35bits) pS (32bits) pLHh (35bits) pS (32bits).
The idx on the previous code is to keep track of where I need to put all those headers, short, long, and p values...
Thanks a lot.
After I have the corret binary array to the temperature I want, I send that to a function that I created called SendRawByBit, which was supposed to work similarly to the sendRaw function, but it's not working and I don't know why. I'm reading the documentation and I don't quite understand everything... I think the problem might be related to the irsend.mark and irsend.space methods. I'm probrably missing something...
Code: Select all
#define HEADER_MARK 9040
#define HEADER_SPACE 4450
#define MARK_DURATION 700
#define SHORT_PAUSE 700
#define LONG_PAUSE 1650
#define SHORT_DELAY 20000
#define LONG_DELAY 40000
#define TOTAL_BYTES 25
#define MESSAGE_BITS (TOTAL_BYTES*8)+1
void sendRawByBit(byte byte_array[], int khz, int temp) {
IrSender.enableIROut(khz);
// Sending Header
IrSender.mark(HEADER_MARK);
IrSender.space(HEADER_SPACE);
int idx = 2;
for (int byteIndex = 0; byteIndex < TOTAL_BYTES; byteIndex++) {
for (int bitIndex = 0; bitIndex < 8; bitIndex++) {
//700 20000
if(idx== 72 || idx == 212|| idx == 352){
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_DELAY);
idx++;
idx++;
}
//700 40000
if(idx == 138 || idx == 278){
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_DELAY);
idx++;
idx++;
}
//9040 4450
if(idx == 140 || idx == 280){
IrSender.mark(HEADER_MARK);
IrSender.space(HEADER_SPACE);
idx++;
idx++;
}
// Getting current bit
int bit = (byte_array[byteIndex] >> (7 - bitIndex)) & 1;
if (bit == 1) {
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_PAUSE);
idx++;
idx++;
} else {
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_PAUSE);
idx++;
idx++;
}
}
}
// Sending final bit
if(temp == 28){
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_PAUSE);
}else{
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_PAUSE);
}
//sending final 700
IrSender.space(SHORT_PAUSE);
}
A normalized raw array looks like this:
Raw: 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700,40000, 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 40000, 9000, 4500, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700
All the raw arrays when converted to binary follow this sequence:
700 1650 = 1
700 700 = 0
Hh - header (9000,4000)
S = short (20000)
L = long (40000)
p - 700
Hh (35bits) pS (32bits) pLHh(35bits) pS (32bits) pLHh (35bits) pS (32bits).
The idx on the previous code is to keep track of where I need to put all those headers, short, long, and p values...
Thanks a lot.