0

Raspberry Pi, CircuitPython & IR receiver
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Tue Aug 31, 2021 10:12 pm

I could use some help, please.

I'm tinkering around with the IR signal from a laser tag gun. I'm using a Raspberry Pi with an IR receiver. I found some code to capture the IR pulses from the gun.

{"1": [2944, 6039, 2944, 2040, 958, 2040, 958, 2040, 958, 2040, 958, 2040, 1945, 2040, 958, 2040, 958],
"2": [2944, 6039, 2944, 2040, 958, 2040, 958, 2040, 958, 2040, 1945, 2040, 958, 2040, 958, 2040, 958]}

1 is when the gun is set for team 1; 2 is from team 2.....

I like the CircuitPython code found in the tutorial https://learn.adafruit.com/ir-sensor/circuitpython. Unfortunately, it won't run on the Pi.....

Is there a way to use the pulseio from adafruit_irremote for a Pi?

Thanks in advance for any help!!

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Wed Sep 01, 2021 6:33 pm

I think I'm going to need a Raspberry Pi Pico to make this work....

--simple IR detection
--servo control

?? -- can I use multiple Picos together, say in I2C mode, with 3 or 4 Picos as slaves & 1 Pico as the master?

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by adafruit_support_mike on Thu Sep 09, 2021 2:54 pm

A microcontroller will give you much better control of the signal timing, yes.

To connect a group of microcontrollers, it’s often easiest to build a Serial token-ring network by daisy-chaining each board’s RX pin to the board on its left and its TX pin to the board on its right. Have each board copy anything it hears on RX over to TX to pass messages around the loop.

Then you can give each board an ID, and send messages that include the ID of the board that should listen.

adafruit_support_mike
 
Posts: 63729
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Sat Sep 18, 2021 7:50 pm

Ok. I am able to get some CircuitPython code working on a Raspberry Pi Pico.

I have an IR receiver, TSOP38238, connected to GP16 of the Pico. When I use the REPL of Thonny with the Pico connected I can see the pulses using

Code: Select all | TOGGLE FULL SIZE
>>>pulses = pulseio.PulseIn(board.GP16)
>>> import adafruit_irremote
>>> decoder = adafruit_irremote.GenericDecode()[
>>> team1 = decoder.read_pulses(pulses)
>>> team1
[2986, 2957, 2986, 2957, 2986, 2957, 2986, 2957, 2986, 2957, 2986, 2957, 2986, 2957, 2986, 2957]

It looks good but when I change the distance from the IR laser tag gun to the IR receiver, the pulses change & the number of pulses change.... Also, if I move farther away from the receiver, I get more pulses & the pulses change.

I have the IR receiver simply plugged into a breadboard with the Pico.

Suggestions? Comments?

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by adafruit_support_mike on Sun Sep 19, 2021 3:41 pm

If you move the IR receiver from position A to position B, then back to position A, do you get the same signals again?

adafruit_support_mike
 
Posts: 63729
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Mon Sep 20, 2021 11:50 am

I'm not sure what you mean by moving the IR receiver from position A to B & back....

Can you clarify that, please?

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by adafruit_support_mike on Thu Sep 23, 2021 5:41 pm

You said the number and timing of the pulses changes when you move the IR sensor from one position to another.

Call the original position 'position-A' and a position that gives different output 'position-B'. Put the IR sensor at position-A and record its output. Move the IR sensor to position-B and record the output. Then move the IR sensor back to position-A and record the output again. Are the two sets of output at position-A the same, or different?

adafruit_support_mike
 
Posts: 63729
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Tue Oct 05, 2021 11:12 pm

Ok. I understand now....

I think I have it working better now. I used some code from the Adafruit tutorial on IR. See the attached file.....

By adjusting the fuzzyness in the compare function, I'm able to get fairly good results. This seems to take care of the differences between the pulses from position A & B.

The next step is to make another IR receiver for the same set of pulses & see if the laser tag gun will only trigger 1 of the IR receivers.....

I modified the original code & tried simply creating another instance of PulseIn using a different GPIO pin on the Pico, but the script freezes up for some reason.

Code: Select all | TOGGLE FULL SIZE
# Create pulse input and IR decoder.
pulses1 = pulseio.PulseIn(Team1_IR_PIN1, maxlen=200, idle_state=True)  # IR_PIN1 is on GPIO16
pulses2 = pulseio.PulseIn(Team1_IR_PIN2, maxlen=200, idle_state=True)  # IR_PIN2 is on GPIO15

I looked thru the documentation for the pulseio.PulseIn class. I don't see anything that says there can't be more than 1 instance of the PulseIn....

Is this possible?
Attachments
Pico-Adafruit-IRremote.py
(1.33 KiB) Downloaded 2 times

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Fri Oct 08, 2021 5:41 pm

Sorry.... posted the wrong file.

Here is the revision where I added another IR receiver....
Attachments
Pico-Adafruit-IRremote_v1.py
(1.95 KiB) Downloaded 1 time

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

by ttu_don on Mon Oct 11, 2021 11:07 pm

Ugh! I can't get this working.....

Do I have to have a different Pi Pico for each IR receiver?? For 8 receivers, that's going to be expensive!

Looking at the CircuitPython docs again, I see that the pulseio is available on other boards, like the Feather boards & Arduino Metro boards. But will I run into the same problem where I can only use one IR receiver per board....?

ttu_don
 
Posts: 41
Joined: Mon Mar 17, 2014 12:36 am

Please be positive and constructive with your questions and comments.