peterhinch / micropython_ir

Nonblocking device drivers to receive from IR remotes and for IR "blaster" apps.
MIT License
240 stars 51 forks source link

Error: bad block while running ir_rx.test on Pico #21

Open BambooStrategic opened 1 year ago

BambooStrategic commented 1 year ago

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

peterhinch commented 1 year ago

The addition of Samsung is quite recent (last update 28th Sept) so firstly make sure you have the latest code. However I only have one example of a Samsung remote. It works, as does that of @cyrilchristin who submitted the latest fix. There do seem to be different versions of the Samsung protocol, and it is possible that your remote uses a variant that I haven't yet encountered.

The 38KHz chip should be correct according to my measurement.

BambooStrategic commented 1 year ago

I was successful at getting the values using the Arduino, now using your latest Transmitter code. I am trying to send a pulse every 5 seconds. the onboard LED is indicating that the loop is working, but the syntax with regards to the transmission for a Samsung is what I am unsure of.

Does this look correct?

from machine import Pin
from ir_tx.nec import NEC
import time

led_onboard = Pin(25, Pin.OUT)
nec = NEC(Pin(17, Pin.OUT, value = 0))
NEC.samsung=True
addr = 0x707
dat = 0x7
rpt = 0xF8070707

while True:
    nec.transmit(addr,dat)
    time.sleep(0.5)
    nec.transmit(addr,rpt)
    time.sleep(0.5)
    led_onboard.value(1)
    time.sleep(5)
    led_onboard.value(0) 

I set up a separate 5v source for the simple IR LED / Resistor/ NPN transistor circuit that you shared. the ground is common with the Pico ground. I have +5 at the LED Anode, just unsure if the pin 17 out is doing what it should based upon my code.

peterhinch commented 1 year ago

To display Python code, please prefix it with three ` characters, with the same at the end. Then indenting is preserved (click the preview tab to see the effect). I have edited your post to do this.

Your code looks OK except for

rpt = 0xF8070707

The data value passed to nec.transmit must be an 8-bit value, as in the rest of your code. I'm not sure where you got this number from.

As a matter of interest where did address 0x707 come from? The reason I ask is that my remote happens to use that address and it worked fine with the receiver.

BambooStrategic commented 1 year ago

Thanks for the feedback. I am really at introductory level, so I'm learning daily on this project that I have a personal need for. Hopefully I'll solve this challenge!

In order to get these codes, I built a different circuit using an Arduino to read the transmitter. Here is the Arduino project link:

https://mschoeffler.com/2021/05/01/arduino-tutorial-ir-transmitter-and-ir-receiver-hx-m121-hx-53-ky-005-ky-022-keyes-iduino-open-smart/#:~:text=A%20typical%20example%20for%20IR,undetectable%20to%20the%20human%20eye.

Here are the results that I received using on/off , Volume up Volume down .

ON/OFF Received something... Protocol=Samsung Address=0x707 Command=0xE6 Raw-Data=0x19E60707 32 bits LSB first Received something... Protocol=Samsung Address=0x707 Command=0x2 Repeat gap=46400us Raw-Data=0xFD020707 32 bits LSB first

Volume UP Received something... Protocol=Samsung Address=0x707 Command=0x7 Raw-Data=0xF8070707 32 bits LSB first

Volume Down Received something... Protocol=Samsung Address=0x707 Command=0xB Raw-Data=0xF40B0707 32 bits LSB first

peterhinch commented 1 year ago

Here is the outcome of testing my Samsung remote. I have annotated it to explain which buttons I'm pressing. In each case I held the button down long enough for multiple messages to be sent.

>>> from ir_rx.test import test
Test for IR receiver. Run:
from ir_rx.test import test
test() for NEC 8 bit protocol,
test(1) for NEC 16 bit,
test(2) for Sony SIRC 12 bit,
test(3) for Sony SIRC 15 bit,
test(4) for Sony SIRC 20 bit,
test(5) for Philips RC-5 protocol,
test(6) for RC6 mode 0.
test(7) for Microsoft Vista MCE.
test(8) for Samsung.

Hit ctrl-c to stop, then ctrl-d to soft reset.
>>> test(8)
running
running
Data 0x02 Addr 0x0707 Ctrl 0x00  # ON/OFF
running
Data 0x02 Addr 0x0707 Ctrl 0x00
Data 0x02 Addr 0x0707 Ctrl 0x00
Data 0x02 Addr 0x0707 Ctrl 0x00
Data 0x02 Addr 0x0707 Ctrl 0x00
Data 0x02 Addr 0x0707 Ctrl 0x00
running
Data 0x07 Addr 0x0707 Ctrl 0x00  # VOLUME UP
Data 0x07 Addr 0x0707 Ctrl 0x00
Data 0x07 Addr 0x0707 Ctrl 0x00
Data 0x07 Addr 0x0707 Ctrl 0x00
running
Data 0x0b Addr 0x0707 Ctrl 0x00  # VOLUME DOWN
Data 0x0b Addr 0x0707 Ctrl 0x00
Data 0x0b Addr 0x0707 Ctrl 0x00
Data 0x0b Addr 0x0707 Ctrl 0x00
Data 0x0b Addr 0x0707 Ctrl 0x00
Data 0x0b Addr 0x0707 Ctrl 0x00
running
running
>>> 

It seems identical to yours except for the initial message you got on pressing ON/OFF (the second message matched mine). So I'm baffled as to why yours didn't work with this test script. Could there be an electrical issue?

BambooStrategic commented 1 year ago

Thank you Peter.

I am traveling now, but will try to build your receiver again this weekend and try again with that.

I have some new components arriving as well to make the Tx circuit as well, so I am hopeful I can create pair of Tx and Rx circuits and get the expected results.

So the 0x00 is what I should use as the third value?

On Wed, Nov 2, 2022, 9:40 AM Peter Hinch @.***> wrote:

Here is the outcome of testing my Samsung remote. I have annotated it to explain which buttons I'm pressing. In each case I held the button down long enough for multiple messages to be sent.

from ir_rx.test import testTest for IR receiver. Run:from ir_rx.test import testtest() for NEC 8 bit protocol,test(1) for NEC 16 bit,test(2) for Sony SIRC 12 bit,test(3) for Sony SIRC 15 bit,test(4) for Sony SIRC 20 bit,test(5) for Philips RC-5 protocol,test(6) for RC6 mode 0.test(7) for Microsoft Vista MCE.test(8) for Samsung. Hit ctrl-c to stop, then ctrl-d to soft reset.>>> test(8)runningrunningData 0x02 Addr 0x0707 Ctrl 0x00 # ON/OFFrunningData 0x02 Addr 0x0707 Ctrl 0x00Data 0x02 Addr 0x0707 Ctrl 0x00Data 0x02 Addr 0x0707 Ctrl 0x00Data 0x02 Addr 0x0707 Ctrl 0x00Data 0x02 Addr 0x0707 Ctrl 0x00runningData 0x07 Addr 0x0707 Ctrl 0x00 # VOLUME UPData 0x07 Addr 0x0707 Ctrl 0x00Data 0x07 Addr 0x0707 Ctrl 0x00Data 0x07 Addr 0x0707 Ctrl 0x00runningData 0x0b Addr 0x0707 Ctrl 0x00 # VOLUME DOWNData 0x0b Addr 0x0707 Ctrl 0x00Data 0x0b Addr 0x0707 Ctrl 0x00Data 0x0b Addr 0x0707 Ctrl 0x00Data 0x0b Addr 0x0707 Ctrl 0x00Data 0x0b Addr 0x0707 Ctrl 0x00runningrunning>>>

It seems identical to yours except for the initial message you got on pressing ON/OFF (the second message matched mine). So I'm baffled as to why yours didn't work with this test script. Could there be an electrical issue?

— Reply to this email directly, view it on GitHub https://github.com/peterhinch/micropython_ir/issues/21#issuecomment-1300421694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFLR756KHCXNXXPGLR6XRMDWGJVK7ANCNFSM6AAAAAARSDLRGI . You are receiving this because you authored the thread.Message ID: @.***>

peterhinch commented 1 year ago

So the 0x00 is what I should use as the third value?

If you mean the toggle arg to transmit, it defaults to 0. It is unused by Samsung. Further, the Samsung protocol doesn't seem to use repeat codes. So if you want to steadily increase volume, this should work:

from machine import Pin
from ir_tx.nec import NEC
import time

led_onboard = Pin(25, Pin.OUT)
nec = NEC(Pin(17, Pin.OUT, value = 0))
NEC.samsung=True
addr = 0x707
dat = 0x7

while True:
    nec.transmit(addr, dat)
    time.sleep(0.5)
    led_onboard.value(1)
    time.sleep(5)
    led_onboard.value(0)

With these time values, volume change will be very gradual - you might want to reduce the 5s delay.