Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Arduino to Circuitpython code conversion
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Arduino to Circuitpython code conversion

by mikeysklar on Tue Oct 26, 2021 3:33 pm

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.

mikeysklar
 
Posts: 6184
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Tue Oct 26, 2021 3:52 pm

The results are nearly the same

Code: Select all | TOGGLE FULL SIZE
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?

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

by mikeysklar on Wed Oct 27, 2021 4:49 pm

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.

mikeysklar
 
Posts: 6184
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Fri Oct 29, 2021 4:27 am

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)

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

by mikeysklar on Fri Oct 29, 2021 11:38 am

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.

mikeysklar
 
Posts: 6184
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Sat Oct 30, 2021 2:46 am

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.

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

by mikeysklar on Mon Nov 01, 2021 1:35 pm

@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

mikeysklar
 
Posts: 6184
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Mon Nov 01, 2021 4:55 pm

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

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Mon Nov 01, 2021 9:54 pm

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

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Re: Arduino to Circuitpython code conversion

by mikeysklar on Tue Nov 02, 2021 3:05 pm

@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

mikeysklar
 
Posts: 6184
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino to Circuitpython code conversion

by Daft_vagabond on Tue Nov 02, 2021 10:07 pm

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.

Daft_vagabond
 
Posts: 43
Joined: Thu May 28, 2020 2:53 pm

Please be positive and constructive with your questions and comments.