| Posted: 07:08pm 13 Nov 2022 |
|
|
|
It lives....
Turns out that the robot is quite sensitive to the timing of the pulses. It needs 40kHz (not 38kHz) and the data is in most significant bit format.
@Volhout - modified your code sample:
bitbang_IR.bas test for bitbang bitstream
option default none option explicit
const carrier% = int(1e6/40e3) '40kHz period time in us const phase% = int(carrier%/2) 'half the carrier period time const bits% = 6 'number of bits to send
'generate an array that contains the 40 time delays '40 transitions in data pulse
dim i%,keycode% dim a$ dim puls%(39):for i%=0 to 39:puls%(i%)=phase%:next i%
'setup ---------------------------------------------------------------------------------------
'Init GP0 as the transmit pin, and force low (IR LED off) setpin gp0,dout : pin(gp0)=0
'Init GP1 for interrupt low (IR receiver modules are default high, low when IR detected) setpin gp1,intl,IR_in
'main ----------------------------------------------------------------------------------------
keycode% = 38 'hardcoded the value for "forward" send_IR
'Interrupt ------------------------------------------------------------------------------------ sub IR_in 'do nothing yet end sub
'subroutines ----------------------------------------------------------------------------------
'send keycode% using carrier bursts coded in puls%() sub send_IR
local i% for i%=bits%-1 to 0 step -1 'cycle through the 6 bits in reverse order bitbang bitstream gp0,40,puls%() 'leading pulse pause 1.2 '2ms - 0.5ms carrier - 0.3ms MMBasic loop delay if (keycode% and 2^i%) then pause 2 'when 1 bit then wait 2ms more until next next i% bitbang bitstream gp0,40,puls%() 'terminating pulse pause 50 'interword gap (pause until next keycode sent) end sub
Delighted to report that the robot now responds to commands from the PicoMite + IR diodes.
Final step to program up a remote of some sorts.
Huge thanks to the pointers and help provided - great to see 1980's kit with a new life.
N |