Servo compass picaxe 28X1 and Java

sub-bg

New Member
I've got a JAVA GUI which is receiving constantly data from my compass sensor and also is sending strings 1111 as a forward button, 1110 as right turn,1100 as left turn,1000 as reverse to move the servo motors. I've put an interrupt for call from my GUI but some reason in the simulation the program is not working properly. The first time it runs OK but then the interrupt cannot be initialised.
--------------------------------------------------------------------------
'+++++++++++++++++++++


SYMBOL TX_PIN = 2
SYMBOL RX_PIN = 3
SYMBOL NORTH = pin7
SYMBOL EAST = pin6
SYMBOL SOUTH = pin5
SYMBOL WEST = pin4




main:

init:
setint %00000100,%00000100

if North=0 and South=1 and East=1 and West=1 then label_11 ' North

if North=0 and South=1 and East=0 and West=1 then label_12 ' North East

if North=1 and South=1 and East=0 and West=1 then label_13 ' East


if North=1 and South=0 and East=0 and West=1 then label_14 ' South East

if North=1 and South=0 and East=1 and West=1 then label_15 ' South

if North=1 and South=0 and East=1 and West=0 then label_16 ' South West


if North=1 and South=1 and East=1 and West=0 then label_17 ' West


if North=0 and South=1 and East=1 and West=0 then label_18 ' North West

goto main ; *****

label_11: let pins = %10000000 ' LED1 on
serout TX_PIN,N2400,("2")
pause 500

goto main

label_12: let pins = %01000000 ' LED2 on
serout 2,N2400,("3")
pause 500


goto main

label_13: let pins = %00100000 ' LED3 on
serout 2,N2400,("4")
pause 500

goto main

label_14: let pins = %00010000 ' LED4 on
serout 2,N2400,("5")
pause 500


goto main

label_15: let pins = %00001000 ' LED5 on
serout 2,N2400,("6")
pause 500

goto main

label_16: let pins = %00000100 ' LED6 on
serout 2,N2400,("7")
pause 500

goto main

label_17: let pins = %00000010 ' LED7 on
serout 2,N2400,("8")
pause 500
goto main

label_18: let pins = %00000001 ' LED8 on
serout 2,N2400,("1")
pause 500
goto main

Interrupt:
SERIN 2,N2400,b1
moving:

servopos 0,150 ‘ move servo to one end
servopos 1,150 ‘ move servo to one end
pause 2000 ‘ wait 2 seconds

select case b1

case=87
servopos 0,180 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end

case 86
servopos 0,180 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end

case 76
servopos 0,120 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end

case 232
servopos 0,120 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end

end select

let b1=0
goto main

RETURN
------------------------------------------------------------------------------
Any help will be appreciated.
 

westaust55

Moderator
Firstly there is no need to start a new thread each time you have a question on the same topic eg your compass module.

your interrupt subroutine is not going to work correctly as it is posted.

1. You do not restart the setint at the end of the subroutine

2. you have just before the RETURN command a GOTO Main. This will cause return to original program location pointer data to be left on the stack. Had the interrupt subroutine worked more than one then you would get a Stack Overflow error.

Code:
Interrupt:
SERIN 2,N2400,b1
moving:

servopos 0,150 ‘ move servo to one end
servopos 1,150 ‘ move servo to one end
pause 2000 ‘ wait 2 seconds

select case b1

case=87
servopos 0,180 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end

case 86
servopos 0,180 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end

case 76
servopos 0,120 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end

case 232
servopos 0,120 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end

end select

let b1=0
[COLOR="Red"];  THIS must be removed ==>  goto main [/COLOR]

[COLOR="red"]; next lines to be added
DO      [COLOR="SeaGreen"]; wait until the interrup signal is removed before re-estabilishing interrupt control again[/COLOR]
LOOP UNTIL pin2 = 0 
setint %00000100,%00000100[/COLOR]

RETURN
 
Last edited:

westaust55

Moderator
picaxe 28x1 code

As a further comment, where you have the lines:

main:

init:
setint %00000100,%00000100​


change the order to:


init:
setint %00000100,%00000100

main:​

the initialisation part is normally only done once at the start.
 

hippy

Ex-Staff (retired)
Additionally, from -

Interrupt:
SERIN 2,N2400,b1

I would guess you are attempting to enter the interrupt whenever some data is sent from the PC. To do that takes an amount of additional effort because you cannot simply send a single byte of data, have that generate the interrupt then read the byte which was sent.

This is because the byte will already have started before SERIN is executed so it will likely ignore ( then wait for the next byte ) or mis-read what was sent.

The easiest workround ( at least to get you started ) is to prefix every byte you send from the PC with a dummy byte to trigger the interrupt, some 'qualifier bytes' ( "XYZZY" in the example below ), then the actual data -

So the PC / Java side is likely to be something along the lines of -

dataByte = 87;
System.Out.write( 0x00 );
System.Out.write( "XYZZY" );
System.Out.write( dataByte );

And on the PICAXE side -

Interrupt:
SerIn 2, N2400, ("XYZZY"), b1
 
Top