Skip to content

Commit 94fa49a

Browse files
committed
Improved LG protocol and added class Aircondition_LG. Improved ir_DistanceProtocol.cpp to support more than 32 bits.
1 parent ed94895 commit 94fa49a

File tree

16 files changed

+709
-288
lines changed

16 files changed

+709
-288
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ jobs:
112112

113113
- arduino-boards-fqbn: megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
114114
platform-url: http://drazzy.com/package_drazzy.com_index.json
115-
sketches-exclude: MinimalReceiver,IRDispatcherDemo,MicroGirs # digitalWriteFast.h not available for this board
115+
sketches-exclude: MinimalReceiver,IRDispatcherDemo,MicroGirs,UnitTest # digitalWriteFast.h not available for this board
116116

117117
- arduino-boards-fqbn: digistump:avr:digispark-tiny:clock=clock16
118118
platform-url: https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json
119119
required-libraries: ATtinySerialOut
120-
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino
120+
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino
121121

122122
- arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
123123
platform-url: http://drazzy.com/package_drazzy.com_index.json

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ If you use an (old) Arduino core that does not use the `-flto` flag for compile,
5050
- Now there is an **IRreceiver** and **IRsender** object like the well known Arduino **Serial** object.
5151
- Just remove the line `IRrecv IrReceiver(IR_RECEIVE_PIN);` and/or `IRsend IrSender;` in your program, and replace all occurrences of `IRrecv.` or `irrecv.` with `IrReceiver`.
5252
- Since the decoded values are now in `IrReceiver.decodedIRData` and not in `results` any more, remove the line `decode_results results` or similar.
53-
- Like for the Serial object, call [`IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L38) or `IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK);` instead of the `IrReceiver.enableIRIn();` or `irrecv.enableIRIn();` in setup().
53+
- Like for the Serial object, call [`IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L38)
54+
or `IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK);` instead of the `IrReceiver.enableIRIn();` or `irrecv.enableIRIn();` in setup().
5455
- Old `decode(decode_results *aResults)` function is replaced by simple `decode()`. So if you have a statement `if(irrecv.decode(&results))` replace it with `if (IrReceiver.decode())`.
55-
- The decoded result is now in in `IrReceiver.decodedIRData` and not in `results` any more, therefore replace any occurrences of `results.value` and `results.decode_type` (and similar) to `IrReceiver.decodedIRData.decodedRawData` and `IrReceiver.decodedIRData.protocol`.
56+
- The decoded result is now in in `IrReceiver.decodedIRData` and not in `results` any more, therefore replace any occurrences of `results.value` and `results.decode_type` (and similar) to
57+
`IrReceiver.decodedIRData.decodedRawData` and `IrReceiver.decodedIRData.protocol`.
5658
- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L126).
5759
- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`.
5860

5961
# Do not want to convert your 2.x program and use the 3.x library version?
60-
The 3.x versions try to be backwards compatible, so you can easily run your old examples. But some functions like e.g. `sendNEC()` -see below- could not made backwards compatible, so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
62+
The 3.x versions try to be backwards compatible, so you can easily run your old examples. But some functions like e.g. `sendNEC()` -see below- could not made backwards compatible,
63+
so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
6164
If you program look like:
6265
```
6366
IRrecv irrecv(RECV_PIN);
@@ -80,7 +83,8 @@ void loop() {
8083
```
8184
it runs on the 3.x version as before. But only the following decoders are available then: Denon, JVC, LG, NEC, Panasonic, RC5, RC6, Samsung, Sony.
8285
The `results.value` is set by the decoders for **NEC, Panasonic, Sony, Samsung and JVC** as MSB first like in 2.x!<br/>
83-
- The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC. Use them to send your **old MSB-first 32 bit IR data codes**.
86+
- The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first,
87+
which is not the standard for NEC and JVC. Use them to send your **old MSB-first 32 bit IR data codes**.
8488
In the new version you will send NEC (and other) commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.
8589

8690
# How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes
@@ -98,7 +102,8 @@ Example:
98102
Please do not use the old send*Raw() functions for sending like e.g. `IrSender.sendNECRaw(0xE61957A8,2)`,
99103
even if this functions are used in a lot of **(old)** tutorials. They are only kept for backward compatibility and unsupported and error prone.<br/>
100104
**Much better** is to use the **new structured functions** with address and command parameters like e.g. `IrSender.sendNEC(0xA8, 0x19, 2)`.
101-
Especially if you are able to receive these remote codes and get the address and command values. You will discover that **the address is a constant** and the commands sometimes are sensibly grouped.
105+
Especially if you are able to receive these remote codes and get the address and command values.
106+
You will discover that **the address is a constant** and the commands sometimes are sensibly grouped.
102107

103108
# FAQ
104109
- IR does not work right when I use **Neopixels** (aka WS2811/WS2812/WS2812B) or other libraries blocking interrupts for a longer time (> 50 us).<br/>
@@ -112,7 +117,7 @@ In turn, this stops the IR interrupt handler from running when it needs to. Ther
112117
- The **minimal CPU frequency** for receiving is 4 MHz, since the 50 us timer ISR takes around 12 us on a 16 MHz ATmega.
113118

114119
# Minimal version
115-
For applications only requiring NEC protocol, there is a receiver which has very **small codesize of 500 bytes and does NOT require any timer**. See the MinimalReceiver and IRDispatcherDemo example how to use it. Mapping of pins to interrupts can be found [here](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/src/TinyIRReceiver.hpp#L307).
120+
For applications only requiring NEC protocol, there is a receiver which has very **small code size of 500 bytes and does NOT require any timer**. See the MinimalReceiver and IRDispatcherDemo example how to use it. Mapping of pins to interrupts can be found [here](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/src/TinyIRReceiver.hpp#L307).
116121

117122
# Handling unknown Protocols
118123
## Disclaimer
@@ -154,8 +159,11 @@ In order to fit the examples to the 8K flash of ATtiny85 and ATtiny88, the [Ardu
154159
### SimpleReceiver + SimpleSender
155160
This examples are a good starting point.
156161

157-
### ReceiveDemo + SendDemo
158-
More complete examples for the advanced user.
162+
### ReceiveDemo
163+
Receives all protocols and play a beep on each packet received. By connecting pin 5 to ground, you can see the raw values for each packet.
164+
165+
### SendDemo
166+
Sends all available protocols at least once.
159167

160168
### ReceiveAndSend + UnitTest
161169
ReceiveDemo + SendDemo in one program. **Receiving while sending**.
@@ -180,6 +188,12 @@ Control a relay (connected to an output pin) with your remote.
180188
### IRremoteExtensionTest
181189
Example for a user defined class, which itself uses the IRrecv class from IRremote.
182190

191+
### SendLGAirConditionerDemo
192+
Example for sending LG air conditioner IR codes controlled by Serial input.<br/>
193+
By just using the function `bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter)` you can control the air conditioner by any other command source.<br/>
194+
The file *acLG.h* contains the command documentation of the LG air conditioner IR protocol. Based on reverse engineering of the LG AKB73315611 remote.
195+
![LG AKB73315611 remote](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/LG_AKB73315611.jpg)
196+
183197
### ReceiverTimingAnalysis
184198
This example analyzes the signal delivered by your IR receiver module.
185199
Values can be used to determine the stability of the received signal as well as a hint for determining the protocol.<br/>
@@ -189,7 +203,8 @@ Click on the receiver while simulation is running to specify individual NEC IR c
189203

190204
# Compile options / macros for this library
191205
To customize the library to different requirements, there are some compile options / macros available.<br/>
192-
Modify it by commenting them out or in, or change the values if applicable. Or define the macro with the -D compiler option for global compile (the latter is not possible with the Arduino IDE, so consider using [Sloeber](https://eclipse.baeyens.it).
206+
Modify it by commenting them out or in, or change the values if applicable.
207+
Or define the macro with the -D compiler option for global compile (the latter is not possible with the Arduino IDE, so consider using [Sloeber](https://eclipse.baeyens.it).
193208

194209
| Name | File | Default value | Description |
195210
|-|-|-|-|
@@ -209,7 +224,6 @@ Modify it by commenting them out or in, or change the values if applicable. Or d
209224
| `IR_SEND_DUTY_CYCLE` | IRremoteInt.h | 30 | Duty cycle of IR send signal. |
210225
| `MICROS_PER_TICK` | IRremoteInt.h | 50 | Resolution of the raw input buffer data. |
211226
| `IR_USE_AVR_TIMER*` | private/IRTimer.hpp | | Selection of timer to be used for generating IR receiving sample interval. |
212-
213227
|-|-|-|-|
214228
| `IR_INPUT_PIN` | TinyIRReceiver.h | 2 | The pin number for TinyIRReceiver IR input, which gets compiled in. |
215229
| `IR_FEEDBACK_LED_PIN` | TinyIRReceiver.h | `LED_BUILTIN` | The pin number for TinyIRReceiver feedback LED, which gets compiled in. |
@@ -224,7 +238,7 @@ The modification must be renewed for each new IRremote library version!
224238

225239
### Modifying compile options with Sloeber IDE
226240
If you are using Sloeber as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
227-
![Sloeber settings](https://github.com/ArminJo/ServoEasing/blob/master/pictures/SloeberDefineSymbols.png)
241+
![Sloeber settings](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/SloeberDefineSymbols.png)
228242

229243
# Supported Boards
230244
Digispark boards are tested with the recommended [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) using `New Style` pin mapping for the pro board.
@@ -277,7 +291,7 @@ For the AVR platform the code to modify looks like:
277291
You **just have to modify the comments** of the current and desired timer line.
278292
But be aware that the new timer in turn might be incompatible with other libraries or commands.<br/>
279293
The modification must be renewed for each new IRremote library version, or you use an IDE like [Sloeber](https://github.com/Arduino-IRremote/Arduino-IRremote#modifying-compile-options-with-sloeber-ide).<br/>
280-
For other platforms you must modify the approriate section guarded by e.g. `#elif defined(ESP32)`.
294+
For other platforms you must modify the appropriate section guarded by e.g. `#elif defined(ESP32)`.
281295

282296
Another approach can be to share the timer **sequentially** if their functionality is used only for a short period of time like for the **Arduino tone() command**.
283297
An example can be seen [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/21b5747a58e9d47c9e3f1beb056d58c875a92b47/examples/ReceiveDemo/ReceiveDemo.ino#L159-L169), where the timer settings for IR receive are restored after the tone has stopped.

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I
1010
- Compiler switch USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN added.
1111
- Moved blink13() back to IRrecv class.
1212
- Added Kaseikyo convenience functions like sendKaseikyo_Denon().
13+
- Improved LG protocol and added class Aircondition_LG based on real hardware supplied by makerspace 201 (https://wiki.hackerspaces.org/ZwoNullEins) from Cologne.
14+
- Improved universal decoder for pulse width or pulse distance protocols to support more than 32 bits.
1315

1416
## 3.3.0
1517
- Fix errors if LED_BUILTIN is not defined.

examples/ReceiveDemo/ReceiveDemo.ino

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555

5656
// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
5757
// to compensate for the signal forming of different IR receiver modules.
58-
#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
58+
//#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
5959

60-
#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
60+
//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
6161

62+
//#define
6263
/*
6364
* First define macros for input and output pin etc.
6465
*/
@@ -134,15 +135,19 @@ void loop() {
134135
Serial.println();
135136
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604
136137
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
137-
IrReceiver.decodedIRData.flags = false; // yes we have recognized the flag :-)
138138
Serial.println(F("Overflow detected"));
139+
Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value in IRremoteInt.h to 750."));
140+
// see also https://github.com/Arduino-IRremote/Arduino-IRremote#modifying-compile-options-with-sloeber-ide
139141
# if !defined(ESP32) && !defined(ESP8266) && !defined(NRF5)
140142
/*
141143
* do double beep
142144
*/
143145
IrReceiver.stop();
144146
tone(TONE_PIN, 1100, 10);
145147
delay(50);
148+
tone(TONE_PIN, 1100, 10);
149+
delay(50);
150+
IrReceiver.start(100000); // to compensate for 100 ms stop of receiver. This enables a correct gap measurement.
146151
# endif
147152

148153
} else {

examples/SendDemo/SendDemo.ino

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,30 @@ void loop() {
131131
Serial.println(F("Send NEC 16 bit address=0xFB04 and command 0x08 with exact timing (16 bit array format)"));
132132
Serial.flush();
133133
const uint16_t irSignal[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560,
134-
560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560,
135-
560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560,
136-
1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, 1690, 560,
137-
1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 inverted 0 of command*/,
138-
560 /*stop bit*/}; // Using exact NEC timing
134+
560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690,
135+
560, 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560,
136+
560, 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560,
137+
1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560,
138+
1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing
139139
IrSender.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.
140140
delay(DELAY_AFTER_SEND);
141141
#endif
142142
/*
143143
* With sendNECRaw() you can send 32 bit combined codes
144144
*/
145-
Serial.println(
146-
F(
147-
"Send NEC / ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102)"));
145+
Serial.println(F("Send NEC / ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102)"));
148146
Serial.flush();
149147
IrSender.sendNECRaw(0x03040102, sRepeats);
150148
delay(DELAY_AFTER_SEND);
151149

150+
Serial.println(F("Send NEC with 16 bit address 0x0102 and 16 bit command 0x0304 with sendPulseDistanceWidthData()"));
151+
// Header
152+
IrSender.mark(9000);
153+
IrSender.space(4500);
154+
// LSB first + stop bit
155+
IrSender.sendPulseDistanceWidthData(560, 1680, 560, 560, 0x03040102, 32, PROTOCOL_IS_LSB_FIRST, SEND_STOP_BIT);
156+
delay(DELAY_AFTER_SEND);
157+
152158
/*
153159
* With Send sendNECMSB() you can send your old 32 bit codes.
154160
* To convert one into the other, you must reverse the byte positions and then reverse all positions of each byte.

0 commit comments

Comments
 (0)