Skip to content

Commit 71d9a2c

Browse files
committed
Examples
1 parent bd19150 commit 71d9a2c

File tree

31 files changed

+245
-143
lines changed

31 files changed

+245
-143
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ jobs:
6060
- arduino:mbed:nano33ble
6161
- arduino:mbed_rp2040:pico
6262
- rp2040:rp2040:arduino_nano_connect
63-
- ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
64-
- ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
65-
- ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
63+
# - ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
64+
# - ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
65+
# - ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
6666
- MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os_flto,clock=8MHz_internal # ATmega128
6767
- SparkFun:avr:promicro
68-
- megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
69-
- megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal
68+
# - megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
69+
# - megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal
7070
- esp8266:esp8266:d1_mini:eesz=4M3M,xtal=80
7171
- esp32:esp32:featheresp32:FlashFreq=80
7272
- esp32:esp32:esp32c3
@@ -176,43 +176,43 @@ jobs:
176176
#
177177
# megaTinyCore
178178
#
179-
- arduino-boards-fqbn: megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
180-
arduino-platform: megaTinyCore:megaavr
181-
platform-url: http://drazzy.com/package_drazzy.com_index.json
182-
sketches-exclude: AllProtocolsOnLCD,UnitTest # UnitTest region `text' overflowed by 997 bytes
183-
build-properties: # the flags were put in compiler.cpp.extra_flags
184-
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=360
185-
186-
- arduino-boards-fqbn: megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal
187-
arduino-platform: megaTinyCore:megaavr
188-
platform-url: http://drazzy.com/package_drazzy.com_index.json
189-
sketches-exclude: AllProtocolsOnLCD
190-
build-properties: # the flags were put in compiler.cpp.extra_flags
191-
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=360
179+
# - arduino-boards-fqbn: megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
180+
# arduino-platform: megaTinyCore:megaavr
181+
# platform-url: http://drazzy.com/package_drazzy.com_index.json
182+
# sketches-exclude: AllProtocolsOnLCD,UnitTest # UnitTest region `text' overflowed by 997 bytes
183+
# build-properties: # the flags were put in compiler.cpp.extra_flags
184+
# IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=360
185+
186+
# - arduino-boards-fqbn: megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal
187+
# arduino-platform: megaTinyCore:megaavr
188+
# platform-url: http://drazzy.com/package_drazzy.com_index.json
189+
# sketches-exclude: AllProtocolsOnLCD
190+
# build-properties: # the flags were put in compiler.cpp.extra_flags
191+
# IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=360
192192

193193
#
194194
# ATTinyCore
195195
#
196-
- arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
197-
platform-url: http://drazzy.com/package_drazzy.com_index.json
198-
required-libraries: ATtinySerialOut
199-
sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
200-
build-properties: # the flags were put in compiler.cpp.extra_flags
201-
SimpleSender: -DSEND_PWM_BY_TIMER
202-
203-
- arduino-boards-fqbn: ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
204-
platform-url: http://drazzy.com/package_drazzy.com_index.json
205-
required-libraries: ATtinySerialOut
206-
sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
207-
build-properties: # the flags were put in compiler.cpp.extra_flags
208-
SimpleSender: -DSEND_PWM_BY_TIMER
209-
210-
- arduino-boards-fqbn: ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
211-
platform-url: http://drazzy.com/package_drazzy.com_index.json
212-
required-libraries: ATtinySerialOut
213-
sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
214-
build-properties: # the flags were put in compiler.cpp.extra_flags
215-
SimpleSender: -DSEND_PWM_BY_TIMER
196+
# - arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
197+
# platform-url: http://drazzy.com/package_drazzy.com_index.json
198+
# required-libraries: ATtinySerialOut
199+
# sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
200+
# build-properties: # the flags were put in compiler.cpp.extra_flags
201+
# SimpleSender: -DSEND_PWM_BY_TIMER
202+
203+
# - arduino-boards-fqbn: ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
204+
# platform-url: http://drazzy.com/package_drazzy.com_index.json
205+
# required-libraries: ATtinySerialOut
206+
# sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
207+
# build-properties: # the flags were put in compiler.cpp.extra_flags
208+
# SimpleSender: -DSEND_PWM_BY_TIMER
209+
210+
# - arduino-boards-fqbn: ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
211+
# platform-url: http://drazzy.com/package_drazzy.com_index.json
212+
# required-libraries: ATtinySerialOut
213+
# sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino
214+
# build-properties: # the flags were put in compiler.cpp.extra_flags
215+
# SimpleSender: -DSEND_PWM_BY_TIMER
216216

217217
#
218218
# MegaCore
@@ -235,15 +235,13 @@ jobs:
235235

236236
- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
237237
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
238-
# arduino-platform: esp32:[email protected] # latest 2.x version as of 5/2024
239238
sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))'
240239
build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled!
241240
IRremoteExtensionTest: -MMD -c # see https://github.com/espressif/arduino-esp32/issues/8815
242241
All: -DRAW_BUFFER_LENGTH=750 -MMD -c
243242

244243
- arduino-boards-fqbn: esp32:esp32:esp32c3
245244
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
246-
# arduino-platform: esp32:[email protected] # latest 2.x version as of 5/2024
247245
sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))'
248246
build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled!
249247
IRremoteExtensionTest: -MMD -c # see https://github.com/espressif/arduino-esp32/issues/8815
@@ -287,7 +285,7 @@ jobs:
287285

288286
- arduino-boards-fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off,sercom4=include
289287
platform-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
290-
sketches-exclude: AllProtocolsOnLCD,UnitTest,ReceiveAndSendDistanceWidth # No print(uint64_t,.) available
288+
sketches-exclude: AllProtocolsOnLCD,UnitTest,ReceiveAndSendDistanceWidth,ReceiveDemo,SimpleReceiverForHashCodes # No print(uint64_t,.) available
291289
build-properties: # the flags were put in compiler.cpp.extra_flags
292290
All: -DRAW_BUFFER_LENGTH=750
293291

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Protocols can be switched off and on by defining macros before the line `#includ
138138
- Protocol values comply to **protocol standards**.<br/>
139139
NEC, Panasonic, Sony, Samsung and JVC decode & send LSB first.
140140
- Supports **Universal Distance protocol**, which covers a lot of previous unknown protocols.
141-
- Compatible with **tone()** library. See the [ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/21b5747a58e9d47c9e3f1beb056d58c875a92b47/examples/ReceiveDemo/ReceiveDemo.ino#L159-L169) example.
141+
- Compatible with **tone()** library. See the [ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298) example.
142142
- Simultaneous sending and receiving. See the [SendAndReceive](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendAndReceive/SendAndReceive.ino#L167-L170) example.
143143
- Supports **more platforms**.
144144
- Allows for the generation of non PWM signal to just **simulate an active low receiver signal** for direct connect to existent receiving devices without using IR.
@@ -446,7 +446,7 @@ On a long press, the **SamsungLG protocol** does not repeat its frame, it sends
446446
## RAM usage of different protocols
447447
The `RAW_BUFFER_LENGTH` determines the length of the **byte buffer** where the received IR timing data is stored before decoding.<br/>
448448
**100** is sufficient for standard protocols **up to 48 bits**, with 1 bit consisting of one mark and space.
449-
We always require additional 4 btes, 1 byte for initial gap, 2 bytes for header and 1 byte for stop bit.
449+
We always require additional 4 bytes, 1 byte for initial gap, 2 bytes for header and 1 byte for stop bit.
450450
- **48** bit protocols are PANASONIC, KASEIKYO, SAMSUNG48, RC6.
451451
- **32** bit protocols like NEC, SAMSUNG, WHYNTER, SONY(20), LG(28) require a **buffer length of 68**.
452452
- **16** bit protocols like BOSEWAVE, DENON, FAST, JVC, LEGO_PF, RC5, SONY(12 or 15) require a **buffer length of 36**.
@@ -519,7 +519,8 @@ If you do not know which protocol your IR transmitter uses, you have several cho
519519
<br/>
520520
521521
# Sending IR codes
522-
If you have a device at hand which can generate the IR codes you want to work with (aka IR remote), **it is recommended** to receive the codes with the [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino), which will tell you on the serial output how to send them.
522+
If you have a device at hand which can generate the IR codes you want to work with (aka IR remote),
523+
**it is recommended** to receive the codes with the [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino), which will tell you on the serial output how to send them.
523524
524525
```
525526
Protocol=LG Address=0x2 Command=0x3434 Raw-Data=0x23434E 28 bits MSB first
@@ -568,9 +569,15 @@ http://www.harctoolbox.org/IR-resources.html
568569
569570
570571
# Tiny NEC receiver and sender
571-
For applications only requiring NEC, NEC variants or FAST -see below- protocol, there is a special receiver / sender included,<br/>
572+
For applications only requiring NEC, NEC variants or FAST -see below- protocol, there is a special receiver / sender included,
572573
which has very **small code size of 500 bytes and does NOT require any timer**.
573574
575+
## Principle of operation
576+
The receiver uses a **pin change interrupt** for on-the-fly decoding which limits the choice of protocols.<br/>
577+
On each level change, the current level and the time since the last change are used to incrementally decode the protocol.<br/>
578+
With this operating principle, we **always need a stop bit**!
579+
The level change caused by this stop bit triggers the final decoding and the call of the optional **user-provided callback function** `handleTinyReceivedIRData()`.
580+
574581
Check out the [TinyReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tinyreceiver--tinysender) and [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#irdispatcherdemo) examples.<br/>
575582
Take care to include `TinyIRReceiver.hpp` or `TinyIRSender.hpp` instead of `IRremote.hpp`.
576583
@@ -651,7 +658,7 @@ On some boards where a software timer is available, the software timer is used.<
651658
Be aware that the hardware timer used for receiving should not be used for `analogWrite()`.<br/>
652659
Especially **motor** control often uses the `analogWrite()` function and will therefore stop the receiving if used on the pins indicated [here](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage).<br/>
653660
On the Uno and other AVR boards the receiver timer ist the same as the tone timer. Thus receiving will stop after a `tone()` command.
654-
See [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/b962db8f4e47408df01474a57f313f5a6bbe39a1/examples/ReceiveDemo/ReceiveDemo.ino#L257) how to deal with it, i.e. how to use `IrReceiver.restartTimer()`.
661+
See [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298) how to deal with it, i.e. how to use `IrReceiver.restartTimer()`.
655662

656663
## Receiving sets overflow flag.
657664
The flag `IRDATA_FLAGS_WAS_OVERFLOW` is set, if `RAW_BUFFER_LENGTH` is too small for all the marks and spaces of the protocol.
@@ -693,7 +700,7 @@ On my Arduino Nanos, I always use a 100 &ohm; series resistor and one IR LED :gr
693700

694701
## Minimal CPU clock frequency
695702
For receiving, the **minimal CPU clock frequency is 4 MHz**, since the 50 &micro;s timer ISR (Interrupt Service Routine) takes around 12 &micro;s on a 16 MHz ATmega.<br/>
696-
The TinyReceiver, which reqires no polling, runs with 1 MHz.<br/>
703+
The TinyReceiver, which requires no polling, runs with 1 MHz.<br/>
697704
For sending, the **default software generated PWM has problems on AVR running with 8 MHz**. The PWM frequency is around 30 instead of 38 kHz and RC6 is not reliable. You can switch to timer PWM generation by `#define SEND_PWM_BY_TIMER`.
698705

699706
## Bang & Olufsen protocol
@@ -712,7 +719,7 @@ The **[SimpleReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob
712719
A simple example can be tested online with [WOKWI](https://wokwi.com/projects/338611596994544210).
713720

714721
#### SimpleReceiverForHashCodes
715-
The **[SimpleReceiverForHashCodes](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino)** uses only the hash decoder.
722+
The **[SimpleReceiverForHashCodes](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino)** uses only the hash decoder.
716723
It converts all IR frames longer than 6 to a 32 bit hash code, thus enabling receiving of unknown protocols.<br/>
717724
See: http://www.righto.com/2010/01/using-arbitrary-remotes-with-arduino.html
718725

@@ -747,7 +754,7 @@ Sends all available protocols at least once.
747754
Demonstrates **receiving while sending**.
748755

749756
#### ReceiveAndSend
750-
Record and **play back last received IR signal** at button press. IR frames of known protocols are sent by the approriate protocol encoder. `UNKNOWN` protocol frames are stored as raw data and sent with `sendRaw()`.
757+
Record and **play back last received IR signal** at button press. IR frames of known protocols are sent by the appropriate protocol encoder. `UNKNOWN` protocol frames are stored as raw data and sent with `sendRaw()`.
751758

752759
#### ReceiveAndSendDistanceWidth
753760
Try to decode each IR frame with the *universal* **DistanceWidth decoder**, store the data and send it on button press with `sendPulseDistanceWidthFromArray()`.<br/>
@@ -915,7 +922,7 @@ If you can provide **examples of using a periodic timer for interrupts** for the
915922
# Timer and pin usage
916923
The **receiver sample interval of 50 &micro;s is generated by a timer**. On many boards this must be a hardware timer. On some boards where a software timer is available, the software timer is used.<br/>
917924
On **ESP8266** `timer1` is used for receive interrupts, which makes it incompatible to the Servo and other libraries.<br/>
918-
On **ESP32** `hw_timer_t` is used for receive interrupts and `ledc` channel 0 is used for generating the IR PWM.
925+
On **ESP32** `hw_timer_t` is used for receive interrupts.
919926

920927
Every pin can be used for receiving.<br/>
921928
If software PWM is selected, which is default, every pin can also be used for sending. Sending with software PWM does not require a timer!
@@ -1000,7 +1007,7 @@ For non AVR boards/platforms you must look for the appropriate section guarded b
10001007

10011008
### Stop and start timer
10021009
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**.
1003-
An example can be seen [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/21b5747a58e9d47c9e3f1beb056d58c875a92b47/examples/ReceiveDemo/ReceiveDemo.ino#L159-L169), where the IR timer is restarted after the tone has stopped.
1010+
An example can be seen [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298), where the IR timer is restarted after the tone has stopped.
10041011

10051012
```c++
10061013
IrReceiver.stopTimer(); // Stop timer consistently before calling tone() or other functions using the timer resource.
@@ -1014,7 +1021,7 @@ This works on AVR boards like Uno because each call to` tone()` completely initi
10141021
If you define `SEND_PWM_BY_TIMER`, the send PWM signal is forced to be generated by a hardware timer on most platforms.<br/>
10151022
By default, the same timer as for the receiver is used.<br/>
10161023
Since each hardware timer has its dedicated output pin(s), you must change timer or timer sub-specifications to change PWM output pin. See [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp)<br/>
1017-
**Exeptions** are currently [ESP32, ARDUINO_ARCH_RP2040, PARTICLE and ARDUINO_ARCH_MBED](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/39bdf8d7bf5b90dc221f8ae9fb3efed9f0a8a1db/examples/SimpleSender/PinDefinitionsAndMore.h#L273), where **PWM generation does not require a timer**.
1024+
**Exeptions** are currently [ESP32, ARDUINO_ARCH_RP2040, PARTICLE and ARDUINO_ARCH_MBED](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleSender/PinDefinitionsAndMore.h#L334), where **PWM generation does not require a timer**.
10181025
10191026
## Why do we use 30% duty cycle for sending
10201027
We [do it](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRSend.hpp#L1192) according to the statement in the [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf):
@@ -1049,7 +1056,7 @@ Created with sigrok PulseView with IR_NEC decoder by DjordjeMandic.<br/>
10491056
# Quick comparison of 5 Arduino IR receiving libraries
10501057
**This is a short comparison and may not be complete or correct.**
10511058
1052-
I created this comparison matrix for [myself](https://github.com/ArminJo) in order to choose a small IR lib for my project and to have a quick overview, when to choose which library.<br/>
1059+
I created this comparison matrix for [myself](https://github.com/ArminJo) in order to choose a small IR library for my project and to have a quick overview, when to choose which library.<br/>
10531060
It is dated from **24.06.2022** and updated 10/2023. If you have complains about the data or request for extensions, please send a PM or open a discussion.
10541061
10551062
[Here](https://github.com/crankyoldgit/IRremoteESP8266) you find an **ESP8266/ESP32** version of IRremote with an **[impressive list of supported protocols](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md)**.

0 commit comments

Comments
 (0)