Raspberry Pi, CircuitPython & IR receiver

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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!!

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

Post by adafruit_support_mike »

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.

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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

>>>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?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

Post by adafruit_support_mike »

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

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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

Can you clarify that, please?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi, CircuitPython & IR receiver

Post by adafruit_support_mike »

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?

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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

# 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 3 times

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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 2 times

User avatar
ttu_don
 
Posts: 53
Joined: Mon Mar 17, 2014 12:36 am

Re: Raspberry Pi, CircuitPython & IR receiver

Post by ttu_don »

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....?

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

Return to “Adafruit CircuitPython”