Page 1 of 1
microbit IR REMOTE AND RECEIVER
Posted: Mon May 18, 2020 3:57 am
by asaf
i want to use ir on my microbit with python, like here -
https://www.circuitbasics.com/arduino-i ... -tutorial/
do u have example for this ?
Thanks a lot
Re: microbit IR REMOTE AND RECEIVER
Posted: Mon May 18, 2020 6:46 am
by OutoftheBOTS_
I have used this bit if hardware
https://www.ebay.com/itm/1Pc-Portable-I ... SwT2daRZgF just recently for something similar but it was for my 6yrs robot which is a Mbot (ardunio MCU programmed with scratch). It is cheap and works very well and comes with a really nice little reciver with LED that flashes when receiving a command from and IR remote. If you want to see it in action click here
https://www.youtube.com/watch?v=YMagc97np-M
I have in the past wrote python code to receive and decode all these IR remotes but didn't keep the code (pity so many people have asked for it
)
You may need to write your own code. I did write a short tutorial ages ago for doing this on RPi see
https://www.youtube.com/watch?v=zDErQPXtMyU&t=53s
I also did a little googling and here also good info for doing this in python
https://fishandwhistle.net/post/2016/ra ... e-control/
Re: microbit IR REMOTE AND RECEIVER
Posted: Mon May 18, 2020 11:02 am
by asaf
thanks.
but i need it to microbit.
do u have python code for this ir to microbit ?
Thanks
Re: microbit IR REMOTE AND RECEIVER
Posted: Mon May 18, 2020 8:13 pm
by OutoftheBOTS_
I am not sure if you will find code for microbit but from the links above you can understand how it works and write your own code
Re: microbit IR REMOTE AND RECEIVER
Posted: Sun Aug 02, 2020 1:06 pm
by asaf
i try this. but its not work.
from microbit import *
from time import time
def binary_aquire(pin, duration):
# aquires data as quickly as possible
t0 = time()
results = []
while (time() - t0) < duration:
results.append(pin8.read_digital())
return results
def on_ir_receive(pinNo, bouncetime=150):
# when edge detect is called (which requires less CPU than constant
# data acquisition), we acquire data as quickly as possible
data = binary_aquire(pinNo, bouncetime/1000.0)
if len(data) < bouncetime:
return
rate = len(data) / (bouncetime / 1000.0)
pulses = []
i_break = 0
# detect run lengths using the acquisition rate to turn the times in to microseconds
for i in range(1, len(data)):
if (data != data[i-1]) or (i == len(data)-1):
pulses.append((data[i-1], int((i-i_break)/rate*1e6)))
i_break = i
# decode ( < 1 ms "1" pulse is a 1, > 1 ms "1" pulse is a 1, longer than 2 ms pulse is something else)
# does not decode channel, which may be a piece of the information after the long 1 pulse in the middle
outbin = ""
for val, us in pulses:
if val != 1:
continue
if outbin and us > 2000:
break
elif us < 1000:
outbin += "0"
elif 1000 < us < 2000:
outbin += "1"
try:
return int(outbin, 2)
except ValueError:
# probably an empty code
return None
display.scroll("s")
while True:
display.scroll("w")
code = on_ir_receive(8)
if code:
display.scroll(str(hex(code)))
else:
display.scroll("I")