Arduino to Circuitpython code conversion

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

Post by mikeysklar »

Thanks for quickly trying the provided code.

The second pulse looks closer to the expected value.

If you only print out pulses[1] ignoring the pulses[0] does that start to provide pulseIn data that is matching to your Arduino.

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

The results are nearly the same

Code: Select all

27
27
27
27
27
27
27
27
28
27
28
9
19
11
17
17
7
27
27
27
27
28
28
28
27
8
8
27
28
11
27
27
27
27
27
7
7
27
27
27
28
13
27
28
22
7
27
28
27
27
28
28
28
7
9
28
8
28
7
10
27
27
7
28
6
27
28
27
6
27
27
28
27
27
28
27
27
28
6
27
28
27
9
17
8
28
8
7
27
28
28
27
28
27
27
27
28
7
7
8
28
27
28
28
27
27
7
17
27
10
27
17
27
27
Which doesn't surprise me, as I think as the array fills up, they just start to cycle through, right?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

Post by mikeysklar »

Looking through the docs for pulseio.PulseIn() one thing that stands out is pulse.resume(80) using a trigger pulse.
Using trigger pulse with a device that drives both high and low signals risks a short. Make sure your device is open drain (only drives low) when using a trigger pulse. You most likely added a “pull-up” resistor to your circuit to do this.
https://circuitpython.readthedocs.io/en ... s/pulseio/

It would probably be best not to pass pulse.resume(80). btw in you last code example code paste it looks like you might have dropped pulse.resume()? I did not see the last line after the comment.

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

Would you mind Eli 5ing that for me? (Other than the part about the pull up/pull down resistor, I understand that that is just a resistor that is only strong enough to influence the logic in one direction or the other while the signal is idle)

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

Post by mikeysklar »

I'd like you to try to use pulse.resume() with no arguments. Get the 80 out of there. That '80' value is for an optional trigger pulse and I don't think that is helpful in your case.

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

Oh, yeah, I hadn't been using the (80) parts. I thought that by introducing more pulses, it'd only further throw off my readings.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

Post by mikeysklar »

@Daft_vagabond,

Looking at the github repo for PulseIO (PulseIn) for CircuitPython an issue stands out as you are attempting to measure < 10us pulses.

"PulseIn drops very short pulses #4946"
https://github.com/adafruit/circuitpython/issues/4946

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

I'm guessing Arduino/C++ doesn't have this issue?

Since I'm not measuring IR, would it be simple enough to lower the minimum?

In that thread, DavePutz mentions it as a possibility.

https://github.com/adafruit/circuitpyth ... -872975351

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

Or even, could we add a parameter that can control the minimum lengths or even turn them off.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

Post by mikeysklar »

@Daft_vagabond,

That seems reasonable to me. There is a maxlen parameter why not have a minlen so these short pulses can be caught.

Would you like to suggest that on the open issue?

https://github.com/adafruit/circuitpython/issues/4946

In terms of a shorter term work around I don't see an obvious setting in the CircuitPython PulseIn to adjust for minimums. You might be able to get something going based rp2pio / adafruit_pioasm examples here:

https://github.com/adafruit/circuitpython/issues/4983

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

Post by Daft_vagabond »

I posted a comment on the open issues you linked to. Lets hope this is something that can be implemented. It would open up an array of uses outside of IR-related projects.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”