Receive and transmit IR remote codes
Re: Receive and transmit IR remote codes
Hello Peter!
I tried to use your library but ran into this error:
https://imgur.com/a/mJCmZi9
Do you have any idea how to solve it?
Thank you in advance
Karol
I tried to use your library but ran into this error:
https://imgur.com/a/mJCmZi9
Do you have any idea how to solve it?
Thank you in advance
Karol
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Receive and transmit IR remote codes
I don't use Thonny so it's hard to be sure but I think it's a directory problem. When you issue
the assumption is that your current directory is above the ir_rx directory - i.e. your current directory contains ir_rx.
Code: Select all
from ir_rx.test import test
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Receive and transmit IR remote codes
I moved to Pycharm and now ran into such a problem:
https://imgur.com/a/sUeLBWb
Do you have any idea why this might not work?
https://imgur.com/a/sUeLBWb
Do you have any idea why this might not work?
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Receive and transmit IR remote codes
Do you have the micropython plugin installed and active?
I don't have access to my pycharm at the moment but if I remember correctly, the utime module doesn't work correctly for me either.
But this message can be safely ignored anyways.
I don't have access to my pycharm at the moment but if I remember correctly, the utime module doesn't work correctly for me either.
But this message can be safely ignored anyways.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Receive and transmit IR remote codes
Hi Peter,
I downloaded your code a few days ago. I have successfully used your code with a Pico to receive from a Sony remote using ir_rx.test , and to transmit using ir_tx.test to my Sony TV. I found that any of the Sony modes will work. However, I can only get the tx to work with the ir_tx.test code. I am using Thonny to run the code. When I use my own code, nothing happens :
from ir_tx.sony import SONY_12
from machine import Pin
# Basic usage on Pico: ( pasted from TRANSMITTER.md )
# from machine import Pin
# from ir_tx.nec import NEC
# nec = NEC(Pin(17, Pin.OUT, value = 0))
# nec.transmit(1, 2) # address == 1, data == 2
sony = SONY_12( Pin(17, Pin.OUT, value = 0) )
addr = 0x1 # TV address
data = 0x15 # power code, toggles TV power
sony.transmit(addr, data)
I expect my TV to turn off, but nothing happens. If I use the ir_tx.test in test(1) ( or 2 or 3 ) mode , it works as expected. I also tried a few other remote button codes and they worked fine.
Another strange thing I noticed is that, if I turn on the "timeit" feature in your tx_it.test code ( irb.timeit=True ), it reports the timing but there does not seem to be any IR transmission, or it is invalid, as nothing happens.
Thank you very much for any help.
I downloaded your code a few days ago. I have successfully used your code with a Pico to receive from a Sony remote using ir_rx.test , and to transmit using ir_tx.test to my Sony TV. I found that any of the Sony modes will work. However, I can only get the tx to work with the ir_tx.test code. I am using Thonny to run the code. When I use my own code, nothing happens :
from ir_tx.sony import SONY_12
from machine import Pin
# Basic usage on Pico: ( pasted from TRANSMITTER.md )
# from machine import Pin
# from ir_tx.nec import NEC
# nec = NEC(Pin(17, Pin.OUT, value = 0))
# nec.transmit(1, 2) # address == 1, data == 2
sony = SONY_12( Pin(17, Pin.OUT, value = 0) )
addr = 0x1 # TV address
data = 0x15 # power code, toggles TV power
sony.transmit(addr, data)
I expect my TV to turn off, but nothing happens. If I use the ir_tx.test in test(1) ( or 2 or 3 ) mode , it works as expected. I also tried a few other remote button codes and they worked fine.
Another strange thing I noticed is that, if I turn on the "timeit" feature in your tx_it.test code ( irb.timeit=True ), it reports the timing but there does not seem to be any IR transmission, or it is invalid, as nothing happens.
Thank you very much for any help.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Receive and transmit IR remote codes
Your code works fine here: with an oscilloscope on pin 17 I can see a sequence of carrier bursts each time I transmit.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Receive and transmit IR remote codes
Thanks much for the fast reply. I don't have a 'scope, but I used my volt meter to look at the GPIO and I see no change when executing this loop :
from ir_tx.sony import SONY_12
from machine import Pin
sony = SONY_12( Pin(17, Pin.OUT, value = 0) )
while True
sony.transmit(0x1, 0x15)
I would expect the average voltage to be a little less than 0.5 * 3.3 V = 1.65V, assuming carrier ( 50 % duty factor ) bursts, but I get zero, so it seems like mine is not working. I am using Thonny to execute this, but I do the same when using your test.py code. I also tried putting this in main.py and resetting the Pico to eliminate Thonny, but I get the same behavior.
I am not well versed in writing classes, so the inheritance is a bit difficult for me to follow, but I can't see any reason why the transmission would depend on the button press code. I hacked the "main" in test.py to eliminate almost everything but the button press call, and it still works fine, as expected. I just use a wire to tie pin 18 to ground, and my TV turns off instantly.
async def main():
pin = Pin(17, Pin.OUT, value = 0)
irb = SONY_12(pin)
px3 =Pin(18, Pin.IN, Pin.PULL_UP)
b = []
b.append(Rbutton(irb, px3, 0x1, 0x15, 1))
while True:
await asyncio.sleep_ms(500)
I wonder why I would need the button press call , but you don't ? Any ideas of other things to try?
from ir_tx.sony import SONY_12
from machine import Pin
sony = SONY_12( Pin(17, Pin.OUT, value = 0) )
while True
sony.transmit(0x1, 0x15)
I would expect the average voltage to be a little less than 0.5 * 3.3 V = 1.65V, assuming carrier ( 50 % duty factor ) bursts, but I get zero, so it seems like mine is not working. I am using Thonny to execute this, but I do the same when using your test.py code. I also tried putting this in main.py and resetting the Pico to eliminate Thonny, but I get the same behavior.
I am not well versed in writing classes, so the inheritance is a bit difficult for me to follow, but I can't see any reason why the transmission would depend on the button press code. I hacked the "main" in test.py to eliminate almost everything but the button press call, and it still works fine, as expected. I just use a wire to tie pin 18 to ground, and my TV turns off instantly.
async def main():
pin = Pin(17, Pin.OUT, value = 0)
irb = SONY_12(pin)
px3 =Pin(18, Pin.IN, Pin.PULL_UP)
b = []
b.append(Rbutton(irb, px3, 0x1, 0x15, 1))
while True:
await asyncio.sleep_ms(500)
I wonder why I would need the button press call , but you don't ? Any ideas of other things to try?
Re: Receive and transmit IR remote codes
I tried the voltmeter while running the hacked test.py, so while I have PIO 18 tied to ground I get my TV turning off and on. I see an average of about 0.25V on PIO 17, whereas I get 0.0V with my looping transmit code. Apparently the repeating codes in the button loop have a ~ 8% overall duty factor.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Receive and transmit IR remote codes
You need a delay in this loop: bear in mind you're emulating a physical remote with a user periodically pushing a button. The transmit method returns immediately with actual transmission occurring as a background process, so you need to be sure it's finished before starting a new transmission.
If you're writing synchronous code, use time.sleep():
In asynchronous code you'd use await asyncio.sleep(1) in a coroutine defined with async def.
If you're writing synchronous code, use time.sleep():
Code: Select all
while True:
sony.transmit(0x1, 0x15)
time.sleep(1)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Receive and transmit IR remote codes
With more careful measurements I can indeed see that a burst is being sent with my code, but apparently the data is wrong. Sorry, but I am still having trouble understanding how the addr and data are being passed to the transmit method .
In test.py, I noticed that the closed button function "cfunc" calls the transmit() method, but also has this line:
self.tim.trigger(108)
Could that be the problem? I tried some ideas to add that to my code, but it seemed to have no effect.
I was also wondering, you said you see a data burst using my code with a 'scope, but are you sure the data is correct? Can you control something with the IR as expected? It acts as if some modification needs to be made to the addr/data before passing it to transmit() . But, I don't see any code that would modify those.
In test.py, I noticed that the closed button function "cfunc" calls the transmit() method, but also has this line:
self.tim.trigger(108)
Could that be the problem? I tried some ideas to add that to my code, but it seemed to have no effect.
I was also wondering, you said you see a data burst using my code with a 'scope, but are you sure the data is correct? Can you control something with the IR as expected? It acts as if some modification needs to be made to the addr/data before passing it to transmit() . But, I don't see any code that would modify those.