Infraout Joystick

billhayley

New Member
I have adapted a computer joystick to send infrared signals to a model Puma Armoured car.It works fine with the normal remote supplied by rev-ed but with the joystick the movement is jerky. My first effort didnt work over long ranges but having read the article on Infr red on the forum I built the enhanced circuit with twin leds. The range is much better but the movement is not smooth.I think it is something to do with the code below paarticularly tm .Pictures of Joystick and Model attached. Any ideas I have tried the simulations but to no avail.
Code:
; *******************************
; ***** Infra Joystick  *****
; *******************************
;    Filename: infra joystick	small	twin leds
;    Date: 	30/01/2011		
;    File Version: 1	
;    Written by: billhayley		
;    Function:infra joystick control		
;    Last Revision:
;    Target PICAXE:20m
; ******************************* 
init:
	
	if pin4=1 then main
	if pin5=1 then revs
	if pin6=1 then fire
	if pin7=1 then rotate
	goto init
main: 
	           
	if pin3 = 1 then ir3; fwdlft
	if pin2 = 1 then ir2; fwd 
	if pin1 = 1 then ir1; fwdrht
	if pin0 = 1 then ir0; rev 
	
	goto main    
			
revs:
	if pin3 = 1 then ir4; revlft
	if pin2 = 1 then ir2; fwd 
	if pin1 = 1 then ir5; revrht
	if pin0 = 1 then ir0; rev
	 goto revs

fire:
	if pin3 = 1 then ir8; firelft
	if pin2 = 1 then ir9; fire
	if pin1 = 1 then ir7; firerht
	if pin0 = 1 then ir6; fire
	 goto fire

rotate:
	if pin3 = 1 then ir12; rotlft
	if pin2 = 1 then ir10; raise
	if pin1 = 1 then ir13; rotrht
	if pin0 = 1 then ir11; lower
	goto rotate
	
ir0:	b2=12;rev
	b3=pin0
	goto tm
	
ir1:	b2=18;fwd rht
	b3=pin1
	goto tm

ir2:	b2=9;fwd
	b3=pin2
	goto tm

ir3:	b2=16;fwd lft
	b3=pin3
	goto tm;
	
ir4:	b2=17;revlft
	b3=pin3
	goto tm
	
ir5:	b2 = 19;revrht 
	b3=pin1
	goto tm
	
ir6:	b2 = 2;fire
	b3=pin0
	goto tm
 
ir7:  b2 = 3;firerht
	b3=pin1
	goto tm

ir8:	b2=4 ;firelft
	b3=pin3
	goto tm

ir9:	b2=2;fire
	b3=pin2
	goto tm

ir10:	b2=6;raise
	b3=pin2
	goto tm
	
ir11:	b2=7;lower
	b3=pin0
	goto tm
	
ir12:	b2 = 0 ;rotate
	b3=pin3
	goto tm
	
ir13:	b2 = 1;back
	b3=pin1
	goto tm
 
tm:
	high 2;indicator led to show transmission.
	w0 = 0
	Do
	infraout 1,b2
	pause 45
	w0 = w0 + 1
	w0 =  b3 * w0
	Loop Until w0 > 30;keep sending the signal until input pin goes low
	low 2
	goto init
 

Attachments

Last edited:

hippy

Technical Support
Staff member
I'm not clear about the use of 'b3' in the 'tm' routine -- isn't this meant to keep repeating IR output until the button is released ?

If so you're reading the button once ( b3=pinX ) before entering the 'tm' routine, never reading the pin while in the routine. Thus it always stays in the 'tm' routine for 30 x 45ms, or forever if 'b3' happens to be zero !
 

billhayley

New Member
b3 is meant to be the value of the input pin. I have adapted this routine from the one for reading pin0 when using infrain.The problem here is that the input pin varies according to the various switches on the joystick. I thought therefore that it was continuously reading the value of the input pin obviously not. I not sure how I would use the routine to read the input pin value at the same time as outputting the infrout?
 

billhayley

New Member
I have amended the code as follows and it seems to work better, although the number of actions I can control is limited at the moment. Any suggestions for further improvement ?
Code:
; *******************************
; ***** Infra Joystick  *****
; *******************************
;    Filename: infra joystick	small	twin leds 20m ver2
;    Date: 	30/01/2011		
;    File Version: 1	
;    Written by: Billhayley	
;    Function:infra joystick control		
;    Last Revision:02/02/2011
;    Target PICAXE:20m
; ******************************* 

main: if pin7 = 1 then fire1
	if pin6 = 1 then fire 
	if pin5 = 1 then rotrht
	if pin4 = 1 then rotlft
	           
	if pin3 = 1 then fwdlft; fwdlft
	if pin2 = 1 then fwd; fwd 
	if pin1 = 1 then fwdrht; fwdrht
	if pin0 = 1 then revs; rev 
	
	goto main    
			

	
revs:	
	high 2
	do
	infraout 1,12;rev
	pause 45
	Loop Until pin0 =0
	low 2
	goto main
	
	
fwdrht:	
	high 2
	do
	infraout 1,18;fwd rht
	pause 45
	Loop Until pin1 =0
	low 2
	goto main
	

fwd:	
	high 2
	do
	infraout 1,9;fwd
	pause 45
	Loop Until pin2 =0
	low 2
	goto main

	
fwdlft:	
	high 2
	do
	infraout 1,16;fwdlft
	pause 45
	Loop Until pin3 =0
	low 2
	goto main
	
	
rotlft:	
	high 2
	do
	infraout 1,0;rotlft
	pause 45
	Loop Until pin4 =0
	low 2
	goto main
	
rotrht:	
	high 2
	do
	infraout 1,1;rotrht
	pause 45
	Loop Until pin5 =0
	low 2
	goto main

fire:	
	high 2
	do
	infraout 1,2;fire
	pause 45
	Loop Until pin6 =0
	low 2
	goto main

fire1:	
	high 2
	do
	infraout 1,2;fire
	pause 45
	Loop Until pin7 =0
	low 2
	goto main
 
Last edited:

eclectic

Moderator
@Bill
A couple of questions:

1. How are the input pins connected to the joystick connections?

2. What receiver is on board the tank?
And how many?

and to save space, use the
[ code]
listing
[/ code]

simply remove the spaces.

e

Code:
; *******************************
; ***** Infra Joystick *****
; *******************************
; Filename: infra joystick small twin leds 20m ver2
; Date: 30/01/2011 
; File Version: 1 
; Written by: Billhayley 
; Function:infra joystick control 
; Last Revision:02/02/2011
; Target PICAXE:20m
; ******************************* 

main: if pin7 = 1 then fire1
if pin6 = 1 then fire 
if pin5 = 1 then rotrht
if pin4 = 1 then rotlft

if pin3 = 1 then fwdlft; fwdlft
if pin2 = 1 then fwd; fwd 
if pin1 = 1 then fwdrht; fwdrht
if pin0 = 1 then revs; rev 

goto main 



revs: 
high 2
do
infraout 1,12;rev
pause 45
Loop Until pin0 =0
low 2
goto main


fwdrht: 
high 2
do
infraout 1,18;fwd rht
pause 45
Loop Until pin1 =0
low 2
goto main


fwd: 
high 2
do
infraout 1,9;fwd
pause 45
Loop Until pin2 =0
low 2
goto main


fwdlft: 
high 2
do
infraout 1,16;fwdlft
pause 45
Loop Until pin3 =0
low 2
goto main


rotlft: 
high 2
do
infraout 1,0;rotlft
pause 45
Loop Until pin4 =0
low 2
goto main

rotrht: 
high 2
do
infraout 1,1;rotrht
pause 45
Loop Until pin5 =0
low 2
goto main

fire: 
high 2
do
infraout 1,2;fire
pause 45
Loop Until pin6 =0
low 2
goto main

fire1: 
high 2
do
infraout 1,2;fire
pause 45
Loop Until pin7 =0
low 2
goto main
 

billhayley

New Member
hi e
the input pins are connected directly to the joystick switches via the 103g on the VE118 board which I believe is a strip of 10k resistors.

The receiver is a built up board using one 20x2 chip, which controls two servos and three motors via l293d chips plus light and sound via infra input.

Code attached. Not sure what you meant by code /code but i know how to add it as an attachment, i need further training.
b
 

Attachments

eclectic

Moderator
hi e
the input pins are connected directly to the joystick switches via the 103g on the VE118 board which I believe is a strip of 10k resistors.

The receiver is a built up board using one 20x2 chip, which controls two servos and three motors via l293d chips plus light and sound via infra input.

Code attached. Not sure what you meant by code /code but i know how to add it as an attachment, i need further training.
b
Code is shown in
http://www.picaxeforum.co.uk/showthread.php?t=7679

20X2? Your code shows 20M

What's a VE118 ?

And by receiver, I meant, for example
TSSOP138 or similar.

e
 
Last edited:

billhayley

New Member
hi e
Ive mastered it!
bill


code:

Code:
        ; ***** SdKfz 234 Puma *****
; *******************************
;    Filename: SdKfz 234 Puma		
;    Date: 06/11/2010		
;    File Version: 1	
;    Written by:Billhayley 		
;    Function:SdKfz 234 Puma control by infra	
;    Last Revision:29/11/2010 on board sound chip
;    Target PICAXE:20x2
; ******************************* 


init:
	symbol infra = b14 ' define an infra variable
	irin c.0, infra ' read input 0 into infra
	
	
	if infra = 16 then left; 1
	if infra = 9 then centre ;2,
	if infra = 18 then right; 3
	if infra = 17 then leftrevs; P+
	if infra = 12 then centrerevs
	if infra = 19then rightrevs; P-
	if infra = 2 then fire;actual 3
	if infra = 0 then rotate
	if infra = 1 then back
	if infra = 6 then raise
	if infra = 7 then lower
	;if infra = 8 then mid
	if infra = 3 then firerht
	if infra = 4 then firelft
	goto init
fire:
	
	w0=0
	b1 = 0
	do
	high b.7
	servo b.3,125
	pause 300
	;high 7
	servo b.3,80
	pause 300
	servo b.3,125
	pause 300
	low b.3
	for B1=1 to 3
	sound 5,(253,5)
	pause 50
	next B1
	low 5
	;pause 100
	
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	;low 6
	;back arm
	low b.7
	goto init

leftrevs:
	low b.0
	high b.1
	b1=180
	gosub rm
	low b.1
	goto init

centrerevs:
	low b.0
	high b.1
	b1=125
	gosub rm
	low b.1
	goto init
	
rightrevs:
	low b.0
	high b.1
	servo b.6,80
	b1=80
	gosub rm
	low 1
	goto init


centre:
	low  b.1
 	high b.0
	b1=125
	gosub rm
  	low b.0
	goto init

left:
	low  b.1
 	high b.0
	b1=180
	gosub rm
  	low b.0
	goto init

right:	
	low  b.1
 	high b.0
	b1=80
  	gosub rm
  	low b.0
	goto init
	
raise:
	high b.4
	low c.3
	w0 = 0
	Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low b.4
	goto init
	
lower:
	high c.3
	low b.4
	w0 = 0
	Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low c.3
	goto init	





	

back:
	high c.2
	low c.1
	w0 = 0
	Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low c.2
	goto init
	
rotate:	
	high c.1
	low c.2
	w0 = 0
	Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low c.1
	goto init
	
firerht:
	w0=0
	do						
	b1=0
	high b.7
	high c.2
	low c.1
	for B1=1 to 10
	sound 5,(253,5)
	pause 25
	next B1
	low 5
	
	servo b.3,125
	pause 300
	;high 7
	servo b.3,80
	pause 300
	servo b.3,125
	pause 300
	low b.3;back arm
	;w0 = 0
	;Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low b.7
	low c.2
	;low b.0
	goto init


firelft:
	w0=0
	do						
	b1=0
	high b.7
	high c.1
	low c.2
	for B1=1 to 10
	sound 5,(253,5)
	pause 25
	next B1
	low 5
	
	servo b.3,125
	pause 300
	;high 7
	servo b.3,80
	pause 300
	servo b.3,125
	pause 300
	low b.3
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	low b.7
	low c.1
	goto init
	
	 
rm:	servo b.6,b1
	pause 300
	low b.6 
	w0 = 0
	Do
	w0 = w0 + 1
	w0= pinc.0* w0
	Loop Until w0 > 30
	return
 

billhayley

New Member
hi e
thanks for the link but i worked it out.
The transmitter joystick uses a 20m chip and the receiver uses a 20x2 chip. Sorry the Ve 118 is a VXE 118 board by rev ed typo error. Yes the receiver is a Led020. The receiver seems OK as it works perfectly when using the rev-ed remote control and even better with the "one for all 4" remote control when set to sony protocol.It seemed simpler idea to operate a joy stick rather than to press buttons!

And now that I am using the transistor circuit and twin leds the joystick range is ok. It works better with the simplyfied code I am now using.What I intend to do next is use a 20x2 for the transmitter enabling me to use more code.So far transfer of the code to new chip has been problomatic.
bill
 

billhayley

New Member
hi hippy
From further research it appears that when using a picaxe chip 20m in this case as a transmitter and the receiver is a 20x2 the line in the code:Loop Until w0 > 30 works if it is changed to: Loop Until w0 > 100. I dont know why.It was only the 20x2 chip as receiver that I had a problem with. The sony remote can cope with the original code as can the 28x1 14m and 20m chips.
 
Top