peterhinch / micropython_ir Goto Github PK
View Code? Open in Web Editor NEWNonblocking device drivers to receive from IR remotes and for IR "blaster" apps.
License: MIT License
Nonblocking device drivers to receive from IR remotes and for IR "blaster" apps.
License: MIT License
Hi, I have recently started using Micropython and am currently using a Raspberry Pi Pico to control an LED strip via button press and timer using your library.
After initial tests with the repl and manual testing of the functions, I have found that when I call these functions using the Timer and Pin.irq functions provided by Micropython, it only works as long as there is only one transmit (Test 1).
Even one sleep prevents the transmit from taking place and the LED strip from lighting up when the function is called up by a timer or by pressing a button (test 2).
When the same function is called up manually, the transmit works (test 3).
It is particularly bad if I have a function in which several transmits are to take place, e.g. if the LED strip is to be switched on and set to the lowest brightness level. After the first transmit has been run through without sending anything, the Pico no longer responds because it seems to be stuck in the loop "while self.busy():" of the transmit function within the ".../micropython_ir-master/ir_tx/init.py" file. The only way to regain access to the Pico is to perform a manual hard reset by briefly disconnecting the Pico from the power supply. (Test 4)
Is the module not timer and button IRQ compatible or how can I get it to work?
This is how I proceed:
git clone https://github.com/peterhinch/micropython_ir
rshell -p /dev/ttyACM0
cp -r micropython_ir-master/ir_tx/ /pyboard/
repl
### repl ###
# Basic configuration
from machine import Pin, Timer
from ir_tx.nec import NEC
import time
PIN_IR_TRANSMITTER = Pin(17, Pin.OUT, value=0)
IR_ADDRESS = 0xef00
IR_DATA_ON = 0x03
IR_DATA = 0x03
nec = NEC(PIN_IR_TRANSMITTER)
def timer_or_btn_test(timer_or_pin):
global IR_ADDRESS, IR_DATA_ON
print("ON Before")
nec.transmit(IR_ADDRESS, IR_DATA_ON)
print("ON After")
Timer().init(mode=Timer.ONE_SHOT, period=200, callback=timer_or_btn_test)
btn = Pin(9, Pin.IN, Pin.PULL_DOWN)
btn.irq(trigger=Pin.IRQ_RISING, handler=timer_or_btn_test)
result:
output:
>>> ON Before
ON After
def timer_or_btn_test(timer_or_pin):
global IR_ADDRESS, IR_DATA_ON
print("ON Before")
nec.transmit(IR_ADDRESS, IR_DATA_ON)
time.sleep(0.1)
print("ON After")
Timer().init(mode=Timer.ONE_SHOT, period=200, callback=timer_or_btn_test)
btn = Pin(9, Pin.IN, Pin.PULL_DOWN)
btn.irq(trigger=Pin.IRQ_RISING, handler=timer_or_btn_test)
result:
output:
>>> ON Before
ON After
def timer_or_btn_test():
global IR_ADDRESS, IR_DATA_ON
print("ON Before")
nec.transmit(IR_ADDRESS, IR_DATA_ON)
time.sleep(0.1)
print("ON After")
timer_or_btn_test()
result:
output:
>>> timer_or_btn_test()
ON Before
ON After
def timer_or_btn_test(timer_or_pin):
global IR_ADDRESS, IR_DATA_ON
print("ON Before")
nec.transmit(IR_ADDRESS, IR_DATA_ON)
print("ON After")
for x in range(0, 16):
print("IR_DATA Before {}".format(x))
nec.transmit(IR_ADDRESS, IR_DATA)
print("IR_DATA After {}".format(x))
Timer().init(mode=Timer.ONE_SHOT, period=200, callback=timer_or_btn_test)
btn = Pin(9, Pin.IN, Pin.PULL_DOWN)
btn.irq(trigger=Pin.IRQ_RISING, handler=timer_or_btn_test)
result:
output:
>>> ON Before
ON After
IR_DATA Before 0
I was having great success with this library on a RPI Pico. However, I've switched to an ESP32-S2 Adafruit Feather in order to take advantage of its ESP-NOW features and I'm finding I just can't read from my IR sensor any longer. I'm using a KeyeStudio Digital IR Reciever Module.
https://learn.adafruit.com/adafruit-esp32-s2-feather/overview
https://wiki.keyestudio.com/Ks0026_keyestudio_Digital_IR_Receiver_Module
I've tired all sorts of pins. I've tried both my simple RC car NEC8 remote and my NEC16 Roku remote. In both cases, the edge length is always 69 instead of 68 and it fails to parse the messages.
Am I just simply out of luck due to using an ESP32 platform? I am experiencing this trouble when no wifi is in use.
Hello @peterhinch , I've been working with your IR module and for a reason I've not been able to determine, I can't capture or send IR signals that will work with the VIZIO IRs.
My dev box is a Ubuntu Linux laptop and I'm using a Raspberry PI Pico. Also, using
https://smile.amazon.com/gp/product/B01E20VQD8/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
I've done some research and it may be that VIZIO and maybe VIZIO is using NEC. Is this different from NEC_8 or NEC_16?
If this is currently unsupported, could VIZIO IR support be added.
I also tried the code for Unsupported protocols.
from ir_rx.acquire import test
import ujson
lst = test() # May report unsupported or unknown protocol
with open('burst.py', 'w') as f:
ujson.dump(lst, f)
Where does the burst.py write to?
Many thanks Peter.
Jeff
Sorry for the basic questions:
I'm a nursing assistant in a long-term care home, and have been working on a media centre project for residents with dementia. Integral to this is building a simplified remote, as residents tv remotes have been overcomplicated. The remote I'm building is going to have only 2 buttons (power, channel), and a buzzer that can be remotely pinged so it's easier to find (people lose their remotes all the time).
Browsing through the code of this library has been very illuminating but confusing. However, I have been able to run the test.py program and run test() to send NEC codes through my pi pico w to control the media centre. I use the media centre to change keycaps based on the test program's signals.
Using the existing test.py program code, how can I bypass the test selection and automatically run the test() remote for NEC protocol?
Hi there - first of all, thank you so much for this brilliant library! I am, however, having a bit of trouble. I am trying to receive NEC codes on an ESP32 with a VS1838b receiver. The code works perfectly - until I connect the ESP32 to the Wifi. While the ESP32 is connecting to the access point, I get a handful of "Error: overrun" errors followed by a few dozen "Invalid start pulse" errors, even though no IR transmission is taking place. Once the Wifi is connected, I am unable to receive any NEC codes at all (every so often, I will get a slew of spurious "Invalid start pulse" messages).
I have tried the default pin (23) and a number of others - changing the pin made no difference. I've also tried running the ESP32 at different clock speeds (from the default 160MHz up to 240MHz), but this also didn't seem to make any difference either. It's almost like there is 'noise' on the GPIO pins caused by Wifi, or the Wifi is causing latency issues which mess up the reading of the IR pulses, but I lack the skill to investigate much more deeply. Do you have any ideas/suggestions? Potentially I could 'offload' the wifi stuff to a second board, maybe an ESP8266, and communicate via I2C, but that feels like an especially nasty hack. Any advice most gratefully received!
Hello sir, hope you are doing well in this pandemic situation, and thank you for your library.
My problem:
I'm using Arduino UNO as a Transmitter that sends NEC data every 0.5 sec and using PICO (rp2040) as a receiver but problem is that most of the time my Pico gives an error like invalid start bit or overrun, I know what this error is but this should not occur...
I'm facing this issue for the past 2-3 days, I'm using TSOP1838, and it's working perfectly fine in Arduino as a receiver, but I want to implement it on Pico.
I also tried to measure the raw NEC signal and I found that pico is missing some bits. I have copy-pasted values on a spreadsheet and compared them.
necdata(mpython).xlsx
I don't know whether this is the right place to post a question since you are the author of this code, I posted here.
Thank you have a nice day :)
Dear Peter, first thanks of all for all your hard work getting this to work in mPython.
Is there any way I could capture an infrared key and save the pulses. And later on replay this IR key?
I'm building a device where you can simply scan the IR key so it will be usuable with all kinds of remotes.
Kind regards,
Rik
I'm sure this is the wrong place. But I'm doing it anyway.
Thanks! Thanks for building these drivers.
I'm using the ir_tx library on a Raspberry Pi Pico. All I wanted was to turn a display on when I booted a computer. Seemed simple enough. It only took me two years to find the Pico, and another 6 months or so to figure out how to get the code together to make it do the one task I had in mind.
Your driver was perfect. Although, (you knew that was coming, didn't you?) it was a mind-bending journey for me to finally figure out what values to put where to get the output I needed.
I needed to see E817C7EA followed by 6897C7EA, but I had no clue how in the world to go about getting those strings.
I was using this as the contents of main.py in the Pico:
from machine import Pin
from ir_tx.nec import NEC
nec = NEC(Pin(17, Pin.OUT, value = 0))
nec.transmit(1, 2)
That was giving me: FD02FE01
Not being a computer scientist, I could not figure out how to get from that string to the ones I needed. I beat my head bloody against that brick wall until I staggered into a discovery: putting 0x in front of the strings I needed would produce the numbers I needed. I'm sure seasoned programmers will get a chuckle out of that. Google was no help to me on that one, so I was quite proud of myself when I figured it out. ;-)
So here's my final main.py for the Pico to do the job I want it to do:
from machine import Pin
from ir_tx.nec import NEC
import time
nec = NEC(Pin(17, Pin.OUT, value = 0))
addr = 0xc7ea
DAT = 0x17
rpt = 0x6897
nec.transmit(addr,DAT)
time.sleep(0.5)
nec.transmit(addr,rpt)
I also stumbled upon the fact that the output was backward from what I expected. Instead of addrDAT, it transmitted DATaddr. I still don't know why that's the case, but it is, apparently.
At any rate, I wanted to say thanks, and to share these bits of info with anyone who might benefit.
Cheers!
Hi @peterhinch
first of: THANK YOU for your awesome library, which made my life so much easier :-)
Buuuuuuuuuuut: I've got a problem and my troubleshooting capabilities are an an end ;-)
I built the following circuit
Raspberry Pi Pico
IR in TSOP 4838 @GPIO28
IR out TSAL 6100 VIS (10 Ohm resistor in place) @GPIO16
IR out amplified by BC547B on 3.3V
and imported your awesome library. After some trial and error and patching code for my particular pin setup I got it all working, I can now receive IR codes and send them out. For example my Sony TV now turns off and on using your software.
Problem is: My Yamaha AVR won't do the same. Yamaha uses NEC codes. I can properly receive the codes from my Yamaha remote (i.e. "Data 2a Addr 007e Ctrl 00"
for toggling the power). Thing is, when I send these codes using nec.transmit(0x7e,0x2a)
my AVR just does nothing :(
Since the Sony portion is working, I think, the circuit itself is working flawlessly.
Anyhow, I:
Do you have any idea, which tree I should bark up next?
I just downloaded your lib to try to control some things on my Raspberry Pi Pico, but my IDE complains about the __init__.py
is missing self.decode
on line 46.
What did I do wrong?
esp32.RMT module already updated, some arguments changed,
https://docs.micropython.org/en/latest/library/esp32.html?highlight=rmt#esp32.RMT
When ir_tx instance initialize, rise error below:
from ir_tx.nec import NEC
nec = NEC(Pin(23, Pin.OUT, value = 0))
Traceback (most recent call last):
File "stdin", line 1, in module
File "/lib/ir_tx/nec.py", line 17, in init
File "/lib/ir_tx/init.py", line 45, in init
TypeError: extra keyword arguments given
Hello,
I am starting with the basic Receiver Test on a RP Pico in order to read the Tx codes on a Samsung remote.
When I run the from ir_rx.test import test , I then selected test (8) as well as test(), and when it starts to run I receive the Error: bad block - see video- New Recording - 10/30/2022, 12:55:30 AM
I am using a 38kHz TSOP1738 - do you think that may be the issue? https://pdf1.alldatasheet.com/datasheet-pdf/view/26589/VISHAY/TSOP1738.html
I have tried a few different times with a few different results: sometimes it returns an "Invalid start Pulse" in between the running heartbeat. But I haven't been able to obtain a value that I can use for a transmitter.
Any suggestions are appreciated. I am not an expert at any of this, and learning every day through the process.
thank you,
Paul
I use /ir_rx/acquire.py receive several IR remote controllers via below:
from ir_rx.acquire import *
ira = IR_GET(Pin(23, Pin.IN))
ira.acquire()
Most IR remote controllers acquire success, but one of IR remote controller cause error below:
000 2428
Traceback (most recent call last):
File "/lib/ir_rx/acquire.py", line 47, in decode
IndexError: list index out of range
Traceback (most recent call last):
File "stdin", line 1, in "module"
File "/lib/ir_rx/acquire.py", line 91, in acquire
Wow, cool stuff Peter, I started with punchcards too and I'm amazed as well that we can run functions on a 5 Dollar ESP32 that may have required as super computer back then.
Just to add some information that may come in handy for you or somebody:
Keep on and enjoy!
In transmitter.md you have mentioned about two push buttons. Is that each of them is for sending different signal? How should we connect it?
I have a requirement of waking up the philips tv from standby, how can i achieve that?what is the value i supposed to transmit?
Sorry if it is a basic thing if i'm asking. I'm relatively new to this field.
Please let me know if you can help
When calling NEC.transmit(...)
method too fast, it will cause a deadlock on a RP2 platform (Pi Pico W). To solve the issue I added this check (I would of done a pull request but I don't have permission to do so.):
In ir_tx/__init__.py
, I added the busy check.
def trigger(self): # Used by NEC to initiate a repeat frame
if ESP32:
self._rmt.write_pulses(tuple(self._mva[0 : self.aptr]))
elif RP2:
if not self._rmt.busy(): # If called while busy, it causes dead-lock
self.append(STOP)
self._rmt.send(self._arr)
else:
self.append(STOP)
self.aptr = 0 # Reset pointer
self._cb(self._tim) # Initiate physical transmission.
Hello, I am trying to do some RX tests with this library on my ESP8266 (NodeMCUv3 clone), but I'm having some issues regarding pin interrupts, apparently not only with this library but in general, and I've already disabled WiFi entirely.
Something that makes what I'm doing even harder is that I'm not actually using an IR receiver module, but an hacked remote control with a wire soldered onto, instead of the IR LED, I searched online and apparently no one ever tried to do something like this (which is strange, an old remote made into wired seems a good idea to me for an inexpensive keypad with many buttons when you only have a couple of usable GPIO pins), so unknown problems surely occur...
Is it possible to use this library in a classic polling loop? Even just for doing tests, I will be okay with this, I don't actually know how well it would work in real programs but still, better than nothing, for now at least. Something along the lines of: in a loop, the Pin.value() is constantly being monitored every millisecond or so, if a value change is detected, then a function from this lib is called, lasting however many ms the IR signal would last, and the encoded command properly read.
Thanks to anyone helping me out!
Hi Peter,
First off I would really like to thank you for this IR lib.
I am using an M5StickC Plus device flashed with micropython on which I have attached an IR Receiver.
What I would like to achieve is being able to acquire an IR Remote signal and then display its protocol , address, and code (and display this information on the M5Stick screen).
I would like to be able to discover the protocol and then retrieve its address/code.
I guess I need a combination of your acquire.py and test.py examples.
So far I have slightly modified/simplified your acquire.py file so that I can just print out on the console the name of the protocol.
It is working fine.
Later I would like to get the address/code using the proper/matching protocol class.
My question for now is: say that I have identified the IR Remote is sending a NEC protocol, what would be the best way to modify the acquire.py file so that I can tell which NEC protocol this is about, NEC_8 or NEC_16? I will indeed need this information in order to call the right protocol class (and I would also like the user to know if it is NEC_8 or NEC_16)... of course same would apply for SONY
Thanks a lot for your answer!
Eric
Hello,
Thank you for this library!
I am trying to use this library on a Raspberry Pi Pico running the latest stable MicroPython.It properly decodes my IR remote codes: I am trying to allow repeat codes to send the last known received code (for Volume up and down, for example). Looking through the nec.py and the *args notation in the docs, I believe it is possible to specify but I cannot seem to make it work correctly. I get Traceback errors when I attempt to add the *arg "0" to the ir function. I have a little coding experience but overall I am quite new to this, so I apologize if this is in the wrong spot.
Thank you very much,
Mike
Hi,
Would it be possible when receiving data to auto detect the protocol ?
Wanting to control my tv via node-red/mqtt I installed your software on an esp32.
from machine import Pin
from ir_tx.philips import RC6_M0
pin = Pin(15, Pin.OUT, value = 1)
to_tv = RC6_M0(pin)
to_tv.transmit(0, 9) # 9 is BBC2
When I power up the esp32, everything works fine. However when I do a restart/stop backend via Thonny, the signal is transmitted twice, so I get 99 instead of 9.
Having spent several evenings tinkering, I have to give up.
Can you help me?
Hi Peter,
I haven't get a clear picture for to setup an IR emitter using RPI PICO.
RPI PICO and IR LED are enough for generating the signal or we need any external circuit or external board?
Hi,
I am trying to setup a Raspberry PI PiCo with an Iduino Infrared Receiver (http://www.mercateo.com/p/615-W632551/Iduino_1485322_IR_Empfaenger_Passend_fuer_Einplatinen_Computer_Arduino.html)
When I run the test procedure from acquire.py, I receive this error right after the start - without even pressing a button on my remote control:
`
from ir_rx.acquire import test
test()
Waiting for IR data...
000 8284
exception in decoding the burst data with length=1 duration=0 / [8284]
[8284]
`
I don't really understand, why the program is NOT waiting for infrared signals but is immediately trying to decode something, that is probably not even there. I did a change to the acquire.py to print out way more debugging Information and this is what I get:
`
from ir_rx.my_acquire import test
test()
rp2 setting Pin to 16
initializing local IR_GET class with pin=Pin(16, mode=IN) nedges=100 twait=100
Waiting for IR data...
local decode function called
edge is 10
length of burst is 9
dt is 8798
dt is 11257
actual length of burst [8798] is 1
duration is 0
the burst is: [8798] x: 000 e: 8798
near called with 8798 / target 9000
near called with 8798 / target 2400
near called with 8798 / target 889
near called with 8798 / target 2666
near called with 8798 / target 2000
near called with 8798 / target 4500
near called with 8798 / target 3500
near called with 8798 / target 0
exception in decoding the burst data with length=1 duration=0 / [8798]
[8798]
`
Interesting note here, the valueSs keep changing from call to call.
Can you give me a hint what's going on here?
Kind regards,
Christian
When the RP2 is under heavy load (high cpu/irq activity) it is possible for the the PIO interrupts which feed the transmit buffer to be delayed, resulting in malformed IR signals. This is particularly evident when wifi is active and data is is being transferred.
In the worst case delays of up to 30ms can be experienced.
Suggest that the existing PIO routines could be fed using DMA rather than interrupts.
In RC5, I believe up to 7F (127) should be acceptable. It seems to work if it's changed from 3F:
class RC5(IR):
valid = (0x1f, 0x3f, 1) # Max addr, data, toggle
MicroPython ESP32 port RMT support carrier now, can you update the code to use esp32.RMT built-in carrier function?
I am new to Micropython. I have a pi pico and the Thonny IDE. How do I install the ir_rx package on my pi pico. Does it go in the 'lib' folder?
Howdy.
I have 2 raspberry pi pico W's running:
MicroPython v1.22.1 on 2024-01-05; Raspberry Pi Pico W with RP2040
sitting a few inches away from each other.
Am able to run from ir_rx.test import test; test()
on the the first and point a IR remote to it and get data back if I press "OK" or any button whatsoever:
i.e Data 0x40 Addr 0x0000 Ctrl 0x00
Life is very joyful...
Next, I take the second pi pico and an "Adafruit High Power Infrared LED Emitter - STEMMA JST PH 2mm" and perform:
from machine import Pin
from ir_tx.nec import NEC
nec = NEC(Pin(15, Pin.OUT, value = 0))
nec.transmit(0,1)
(I've tried powering with 3.3 and 5.0 Volts - pin 36 and 40 respectively.) I have the proper stemma connectors and have
DC power to the V+ power in, ground for ground, and then a 3-5V logic level signal on the input pin as per Adafruit.
I see the red led light up on the adafruit emitter and instantly I can see the the first/pico receiver reports back "Error: bad block".
If I use the acquire method, I get some data back for nec.transmit(0,1)
:
>>> from ir_rx.acquire import test
>>> test()
Waiting for IR data...
000 8949
001 7174
002 1837
003 550
004 578
005 527
006 607
007 553
008 579
009 552
010 578
011 553
012 579
013 1680
014 582
015 1684
016 581
017 1683
018 552
019 1711
020 550
021 1690
022 574
023 1685
024 579
025 1708
026 7657
027 526
028 922
029 394
030 1263
031 151
032 297
033 500
034 604
035 528
036 605
037 528
038 604
039 524
040 606
041 526
042 607
043 1683
044 581
045 1683
046 553
047 1707
048 555
049 1685
050 578
051 1684
052 552
053 1709
054 553
055 1712
056 549
Unknown protocol start 8949 7174 Burst length 57 duration 70952
[8949, 7174, 1837, 550, 578, 527, 607, 553, 579, 552, 578, 553, 579, 1680, 582, 1684, 581, 1683, 552, 1711, 550, 1690, 574, 1685, 579, 1708, 7657, 526, 922, 394, 1263, 151, 297, 500, 604, 528, 605, 528, 604, 524, 606, 526, 607, 1683, 581, 1683, 553, 1707, 555, 1685, 578, 1684, 552, 1709, 553, 1712, 549]
For fun, I've tried sending all sorts of values. (have tried researching the NEC protocol and read some issues in this repo but I figured the second pico should report something other than 'bad block? - I claim no expertise here...)
My goal is to just send 'any' data really via IR from the first pico to the other. Then once received I can do things like turn an led on/off or call up the President (j/k) or what have you.
Apologies for my lack of EE training, I hope it is clear.
Thanks for any guidance
Hi @peterhinch ,
Thanks a lot for your great effort in writing this lib as there are not many good micropython for handling IR communication out there. I have tried your lib using my esp32 board with nearly the same hardware setup:
But the result is not very stable, it could not decode the key correctly many times it. Here is sample output:
Data 04 Addr fd00 Ctrl 00
Repeat code.
Data 09 Addr 0000 Ctrl 00
Repeat code.
Repeat code.
Error: bad block
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Error: bad block
Repeat code.
Repeat code.
Data 05 Addr 0000 Ctrl 00
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Error: bad block
Invalid start pulse
Repeat code.
Repeat code.
Repeat code.
Invalid start pulse
Invalid start pulse
Invalid start pulse
Invalid start pulse
Invalid start pulse
Repeat code.
Repeat code.
Invalid start pulse
Invalid start pulse
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Data 04 Addr 0000 Ctrl 00
Repeat code.
Repeat code.
Data 04 Addr 0000 Ctrl 00
Repeat code.
Repeat code.
Error: bad block
Repeat code.
Repeat code.
Data 04 Addr f700 Ctrl 00
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Error: bad block
Repeat code.
Repeat code.
Repeat code.
Repeat code.
Data 05 Addr 0000 Ctrl 00
Repeat code.
Data 01 Addr ff40 Ctrl 00
Repeat code.
Data 06 Addr fd00 Ctrl 00
Repeat code.
Repeat code.
Do you have any idea how to improve the result? Are you seeing the same on your side or yours is way better?
In advance i must warn you, i am a complete micropython beginner, and i would also like to thank you for making these packages.
Anyway I followed the instructions and gave the test a try:
from ir_rx.acquire import test
test()
And got a reading:
Waiting for IR data...
000 8986
001 4484
002 575
003 585
004 579
005 582
006 578
007 583
008 578
009 583
010 641
011 517
012 580
013 583
014 579
015 583
016 577
017 583
018 578
019 1658
020 581
021 1661
022 579
023 1656
024 582
025 1660
026 578
027 1659
028 579
029 1662
030 577
031 1662
032 574
033 1665
034 576
035 585
036 577
037 1658
038 580
039 1663
040 576
041 583
042 576
043 1660
044 581
045 582
046 579
047 583
048 577
049 584
050 576
051 1659
052 581
053 582
054 577
055 585
056 585
057 1650
058 582
059 583
060 579
061 1661
062 629
063 1606
064 582
065 1662
066 579
NEC
After that i gave the pyboard example a try but i am using an ESP32 minikit so i removed the PYB and LED lines:
import time
from machine import Pin
#REMOVED from pyb import LED
from ir_rx.nec import NEC_8 # NEC remote, 8 bit addresses
#REMOVED red = LED(1)
def callback(data, addr, ctrl):
if data < 0: # NEC protocol sends repeat codes.
print('Repeat code.')
else:
print('Data {:02x} Addr {:04x}'.format(data, addr))
ir = NEC_8(Pin('X3', Pin.IN), callback)
while True:
time.sleep_ms(500)
red.toggle()
And i got the following error:
Traceback (most recent call last):
File "<stdin>", line 14, in <module>
TypeError: can't convert str to int
This is line 14:
ir = NEC_8(Pin('X3', Pin.IN), callback)
Any idea on what is going wrong?
First of all thank you for the amazing work.
I've been playing with the library for a few days trying to emulate a YACIFBI Gree AC remote control. I'm using the test and Player sections to get and transmit the raw signal. I'm getting the raw signal from my remote, but transmitting to the AC doesn't seem to work (trying to turn it off for simplicity).
Any guidance would be greatly appreciate.
I'm connecting the IR led directly to a Pico pin with resistor if that matters.
I have a Flipper zero which im using to test and see if the IR led is actually transmitting. Saving the saved signal from the IR led to the flipper and playing directly to the AC has no result. Saving the signal from the remote directly to the flipper and playing to the AC does work.
Thanks in advance.
Following the example code on an ESP32 I get an "Error: overrun" every time I receive data but I don't know what causes this or how to prevent this error from happening. I am receiving data correctly confirmed using an oscilloscope. This issue happens using both NEC_16 and NEC_8.
Receiver code
import time
import machine
import gc
from ir_rx.nec import NEC_16
from ir_rx.print_error import print_error
def callback(data, addr, ctrl):
print("Callback is called")
if data < 0: # NEC protocol sends repeat codes.
print("Repeat code.")
else:
print("Data {:02x} Addr {:04x}".format(data, addr))
def test():
ir = NEC_16(machine.Pin(32, machine.Pin.IN), callback)
ir.error_function(print_error)
try:
i = 0
while True:
i += 1
print("Running: " + str(i))
time.sleep(5)
gc.collect()
except KeyboardInterrupt:
ir.close()
test()
Transmitter code for completeness (Works as expected as confirmed using oscilloscope).
import machine
from ir_tx.nec import NEC
button = 0
buttonPin = machine.Pin(26, machine.Pin.IN)
transmitter = NEC(machine.Pin(12, machine.Pin.OUT))
while 1:
if buttonPin.value() and not button:
button = 1
print("Button went low")
elif not buttonPin.value() and button:
button = 0
print("Button went high " + str(i))
i += 1
transmitter.transmit(1, i)
What exactly is causing this issue? And how can I prevent it from happening?
Hi,
I'm trying to get an old Apple Remote A1156 to work with my ESP32-C3.
I'm working with a Lolin Wemos ESP32-C3: https://www.wemos.cc/en/latest/c3/index.html
Micropython: MicroPython v1.22.0 on 2023-12-27; LOLIN_C3_MINI with ESP32-C3FH4
I tried: from ir_rx.test import test
And test() or test(1) result in crash and reboot.
I finally tried: from ir_rx.acquire import test
which gave me this output:
>>>
MPY: soft reboot
MicroPython v1.22.0 on 2023-12-27; LOLIN_C3_MINI with ESP32-C3FH4
Type "help()" for more information.
>>> from ir_rx.acquire import test
>>> test()
Waiting for IR data...
Guru Meditation Error: Core 0 panic'ed (Store access fault). Exception was unhandled.
Core 0 register dump:
MEPC : 0x40047a74 RA : 0x420024b2 SP : 0x3fca7ea0 GP : 0x3fc97c00
TP : 0x3fc6e63c T0 : 0x4203a93e T1 : 0x00000000 T2 : 0xffffffff
S0/FP : 0x0000000e S1 : 0x3fcddf5c A0 : 0x00000000 A1 : 0x31da05cc
A2 : 0x0000000c A3 : 0x00001e00 A4 : 0x00000008 A5 : 0x600c2000
A6 : 0x00010000 A7 : 0x00000000 S2 : 0x00001000 S3 : 0x00000000
S4 : 0x0000000c S5 : 0x00000020 S6 : 0x3fca7ec8 S7 : 0x3fcddf4c
S8 : 0x74737973 S9 : 0x00000020 S10 : 0x00000001 S11 : 0x00000000
T3 : 0x00000052 T4 : 0x00000fa0 T5 : 0x0000013a T6 : 0x00000002
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x31da05cc
MHARTID : 0x00000000
Stack memory:
3fca7ea0: 0x00000020 0x000000c8 0x00000000 0x00000000 0x3fcaa394 0x3fcaa370 0xffc1ffff 0x7fffffff
3fca7ec0: 0x00000000 0x00000003 0x003e0000 0x00000000 0x00000000 0x00000001 0x00000002 0x00000000
3fca7ee0: 0x3fca7f3c 0x3c14187c 0x00000004 0x3c141000 0x3c141000 0x000004c7 0x3fcaa150 0x3fcaaf66
3fca7f00: 0x3fffffff 0x3ffffffe 0x40000000 0x3fca7f64 0x80000000 0x00000001 0x3fcaa370 0x42006b0c
3fca7f20: 0x00000020 0x009354f4 0x00010000 0x00000000 0x3fcaa3a0 0x00000064 0x000003e8 0x00000006
3fca7f40: 0x3fffffff 0x3ffffffe 0x40000000 0x00000003 0x3fca8148 0x00000001 0x3c141884 0x4200f34a
3fca7f60: 0x3c141000 0x0000001f 0x00000003 0x3fca814c 0x3fffffff 0x3ffffffe 0x40000000 0x3fcaacd0
3fca7f80: 0x000000c0 0x3fca8144 0x3fcaaf67 0x40382f12 0x3fffffff 0x3ffffffe 0x3fca8170 0x3fca8130
3fca7fa0: 0x3c14888c 0x3fc9ae5c 0x3fca816c 0x00000000 0x3fca82f4 0x00000002 0x00000069 0x3fca8164
3fca7fc0: 0x0000001e 0x3fcaa540 0x3fca8228 0x42047656 0x403828fa 0x3fca81b0 0x3fca9740 0x00000002
3fca7fe0: 0x00000000 0x3fca81b0 0x0000000b 0x00000000 0x3fca8130 0x00000050 0x00000254 0x3c141000
3fca8000: 0x3c141000 0x3fca7f90 0x3fca9310 0x42025ec4 0x3fca9358 0x3fca9560 0x3c143c54 0x00000000
3fca8020: 0x00000000 0x3fca8310 0x3c143c54 0x00000000 0x00000000 0x3fca8310 0x3c150ae0 0x000004d5
3fca8040: 0x3fcac260 0x3fcab660 0x000004d5 0x42017e6a 0x000005ef 0x3fcab660 0x00000000 0x3fcab660
3fca8060: 0x42015620 0x420155fa 0x3fca80e0 0x3fc97c00 0x3fc6e63c 0x4200c538 0x00000003 0x00000000
3fca8080: 0x00000004 0x00000003 0x00000001 0x3c141000 0x3c141000 0x00000256 0x3fcaa150 0x3fcaaf1f
3fca80a0: 0x3fffffff 0x3c143c90 0x3c1578dc 0x3fca80fc 0x0000000f 0x3fffffff 0x3fcaa090 0x42015204
3fca80c0: 0x3fffffff 0x3ffffffe 0x40000000 0x3fcaa150 0x00000000 0x0000000a 0x00000256 0x3c141000
3fca80e0: 0x3c141000 0x0000000b 0x0000002c 0x00000009 0x3fffffff 0x3ffffffe 0x40000000 0x3c141000
3fca8100: 0x3c141000 0x00000254 0x00000050 0x3fca8130 0x00000000 0x0000000b 0x3fca81b0 0x00000000
3fca8120: 0x00000002 0x3fca9740 0x3fca81b0 0x4200f29a 0x3fca9990 0x3fcaaf64 0x3fca8140 0x0000000b
3fca8140: 0x3fca9c80 0x3c141884 0x3fcaa370 0x00001ac2 0x000000c9 0x000019ba 0x00000001 0x0000119a
3fca8160: 0x3fcaa3a0 0x4c7f70b1 0x3c1420d8 0x3fcaa150 0x000000c0 0x3fcaa2f0 0x3fca81b0 0x4200f1ec
3fca8180: 0x00000001 0x00000010 0x3fcaa150 0x3fcac6cf 0x0000137b 0x3fcaa150 0x3fca9990 0x00000002
3fca81a0: 0x00000000 0x3fca81b0 0x3fca81f0 0x42046f00 0x3fcaa150 0x3c1420d8 0x3fca8388 0x3fca86c0
3fca81c0: 0x403828fa 0x3fca8350 0x3fca9740 0x00000005 0x0000137b 0x00000000 0x00000008 0xd9c0818a
3fca81e0: 0x3c1420d8 0x3fcaa360 0x3fc9ae5c 0x42017ab8 0x3c141000 0x3fca8180 0x0000000f 0x3c1420d8
3fca8200: 0x3c143f83 0x3fcaa020 0x3fc9ae5c 0x42018956 0x00000001 0x3fcaa020 0x3fcaa360 0x3c1420d8
3fca8220: 0x00000000 0x00000000 0x3fca83e8 0x00000000 0x4201894c 0x3fc9ae5c 0x3fcaa360 0x3c1420d8
3fca8240: 0xd9c0818a 0x00000008 0x00000000 0x0000137b 0x3fcac6cf 0x3fcaa150 0x00000254 0x3c141000
3fca8260: 0x3c141000 0x3fca8210 0x00000004 0x0000000c 0x3fcaa154 0x0000000c 0x3fcaa7c8 0x4200ac22
3fca8280: 0x3fffffff 0x0000dc15 0x00000001 0x3fcaa154 0x000012a2 0x00000001 0x3fcaa770 0x40382070
ELF file SHA256: 4e42dac477741998
Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x403807a8
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0xe8c
load:0x403cc710,len:0x6ec
load:0x403ce710,len:0x2b24
entry 0x403cc710
MicroPython v1.22.0 on 2023-12-27; LOLIN_C3_MINI with ESP32-C3FH4
Type "help()" for more information.
I see in the test.py code the gc.collect() is used, I also tried to gc.collect before the acquire.py code and disabled debug mode with osdebug(None) but did not help..
I can read the raw data and used the same esp for other projects. not sure what to do.
(found an wemos s2 mini and this device does not reset)
info on the Apple Remote NEC protocol: https://en.wikipedia.org/wiki/Apple_Remote
Hi,
Am I doing something wrong in my setup because I get inconsistent results when I playback data on the Pi Pico W.
Here are the results of a test where I played the data (via multiple sources) and recorded it:
original_data = [4502, 4526, 518, 606, 518, 602, 518, 1722, 542, 1702, 518, 602, 518, 1726, 542, 578, 518, 602, 518, 606, 518, 602, 518, 1722, 546, 1698, 518, 602, 518, 1722, 546, 578, 518, 602, 518, 1722, 546, 1698, 518, 1722, 542, 582, 514, 1726, 542, 578, 518, 602, 522, 602, 518, 602, 518, 606, 518, 602, 518, 1722, 546, 578, 518, 1722, 542, 1698, 518, 1726, 542, 1000]
playback_1 = [4340, 4563, 414, 708, 394, 689, 441, 1844, 426, 1838, 394, 711, 419, 1876, 417, 736, 2003, 3155, 1760, 1690, 1415, 3129, 4873, 4946, 2579, 4583, 2908, 5954, 1522, 2503, 8468, 268, 142, 701, 258, 638, 706, 1604, 287, 1872, 694, 390, 441, 1840, 421, 925, 524, 422, 424, 868, 348, 679, 653, 395, 468, 1747, 229, 898, 442, 634, 422, 1821, 472, 1789, 419, 1843, 442]
playback_2 = [4313, 4583, 393, 709, 420, 684, 420, 1821, 468, 1816, 396, 710, 420, 1848, 442, 686, 416, 687, 444, 719, 438, 691, 2392, 3166, 4702, 4215, 5419, 3657, 4792, 2285, 5763, 3605, 2155, 8555, 94, 352, 602, 497, 147, 751, 422, 711, 559, 1732, 678, 447, 1554, 582, 527, 607, 490, 665, 550, 554, 524, 2006, 546, 449, 681, 1530, 524, 1639, 544, 1924, 419]
playback_3 = [4326, 4568, 431, 673, 416, 706, 447, 1798, 440, 1791, 469, 663, 468, 1801, 464, 637, 443, 688, 599, 584, 732, 2189, 4840, 3238, 4259, 5167, 3519, 4974, 5444, 4556, 1650, 2328, 8368, 251, 182, 664, 285, 637, 335, 1931, 704, 2581, 704, 689, 182, 665, 679, 1604, 682, 396, 470, 1006, 206, 2820, 209, 2037, 437, 1792, 440, 1795, 496]
playback_via_arduino_1 = [4362, 4610, 482, 637, 446, 709, 473, 1813, 420, 1837, 421, 689, 441, 1838, 469, 662, 417, 721, 433, 680, 452, 685, 467, 1819, 443, 1827, 453, 664, 444, 1805, 504, 659, 444, 688, 440, 1817, 470, 1788, 445, 1817, 469, 662, 442, 1865, 419, 689, 455, 656, 462, 683, 463, 688, 419, 714, 443, 710, 418, 1845, 440, 686, 417, 1870, 415, 1841, 439, 1820, 451]
playback_via_arduino_2 = [4361, 4604, 445, 738, 410, 717, 437, 1821, 503, 1755, 418, 711, 418, 1850, 499, 620, 447, 686, 441, 711, 420, 735, 399, 1838, 468, 1789, 465, 690, 439, 1792, 471, 737, 435, 666, 421, 1841, 443, 1791, 463, 1823, 440, 688, 438, 1805, 488, 682, 417, 685, 466, 715, 439, 661, 470, 691, 416, 710, 418, 1842, 485, 672, 420, 1797, 483, 1815, 419, 1842, 443]
As you can see if you compare the original data to the playback it is inconsistent on the Pi Pico W, but consistent on the Arduino.
My testing suggests that the recording of the data is fine. The issue is with the playback.
The code I use is this:
from ir_tx import Player
from machine import Pin
volumeupbutton = [4502, 4526, 518, 606, 518, 602, 518, 1722, 542, 1702, 518, 602, 518, 1726, 542, 578, 518, 602, 518, 606, 518, 602, 518, 1722, 546, 1698, 518, 602, 518, 1722, 546, 578, 518, 602, 518, 1722, 546, 1698, 518, 1722, 542, 582, 514, 1726, 542, 578, 518, 602, 522, 602, 518, 602, 518, 606, 518, 602, 518, 1722, 546, 578, 518, 1722, 542, 1698, 518, 1726, 542, 1000]
ir = Player(Pin(17, Pin.OUT, value = 0))
ir.play(volumeupbutton)
Also here is the lengths of the data:
original_data = 68
playback_1 = 67
playback_2 = 65
playback_3 = 61
playback_via_arduino_1 = 67
playback_via_arduino_2 = 67
Any ideas would be appreciated greatly.
Many thanks,
Jonathan Adshead
Edit:
I have tried the alternate method of address & data for NEC Samsung/NEC 16 bit.
testing both test(1) and test(8) with the Arduino and original remote control shows a readable address and data, but if I use the below code (either with or without setting the NEC.samung bool) it results in a response of Error: bad block & Invalid start pulse.
from machine import Pin
from ir_tx.nec import NEC
powerbutton = 0x1e
functionbutton = 0x8a
volumeupbutton = 0x17
volumedownbutton = 0x16
volumemutebutton = 0x1f
nec = NEC(Pin(17, Pin.OUT, value = 0))
NEC.samsung=True
addr = 0x2c2c
nec.transmit(addr, powerbutton)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.