Range sensor code question

Pat13

Senior Member
Hello everyone, I am having troubles writing code for this application.
I need to monitor ranges in inches from 5 sources simultaneously and if range falls within a certain parameter, to trigger a piezo speaker.
I have a client who is legally blind (can see shapes within 3-8') and is now a quadraplegic.
We are going to put range sensors on her power wheelchair, one each left right and rear, and two on the front. Each sensor will be accompanied by a piezo speaker.
When she is with 18" to 24" of an object (say, a wall) I want the speaker on that side to emit a tone with a set duration, if she continues in that direction (12" to 17") i want the tone to increase in pitch and duration, if she continues (6" to 11"), again an increase in pitch and duration.
I ran debug on the senor and these are the readings I got:
at 3': 12/$0C/%00001100
at 2': 8/$08/%00001000
at 18": 6/$06/ %00000110
at12": 4/$04/%00000100
at 6": 2/$02?%00000010
Here is the code I have so far, View attachment Wheelchair Range Sensor.bas
I have run syntax and it is getting hung up on {if b1< 16}.
I think by using the "start" command, I can have this picaxe monitoring all 4 quadrants at once, but am stumped as how to write the byte variable. Any help greatly appreciated.
 
Last edited:

westaust55

Moderator
Firstly, in using the Start0, Start1, Start2 and Start3 labels for multi-tasking please confirm that you have an M2 series PICAXE chip.

With your lines such as:
if b1< 16 'if chair is within 18"-24" of object gosub alarm1
then gosub alarm1

the THEN keyword MUST be lon on the same line as the IF.

In fact, if you are only branching from the IF&#8230;THEN commands the destination label should also be on the same line so you will have:
IF b1< 16 THEN GOSUB alarm1 ; if chair is within 18"-24" of object gosub alarm1
 
Last edited:

westaust55

Moderator
Further to earlier response, for the data you have indicated there is a potentially better way to branch to the respective subroutines. Since the READADC value received increments by 2 for each 6 inches, then you could use some code such as:

value = b1 / 2 – 1 ; then give 0 for 6 inch, 1 for 12 inches, 2 for 18 inches etc
ON value GOSUB alarm1, alarm2, alarm3, alarm4, alarm5, alarm 6

Here alarm6 related to the 5th interval (0 to 5) = = > 6*(5+1) = 36 inches
For any greater distance, the ON. . .GOSUB will just all through to the next line of program code.
 

Pat13

Senior Member
Thanks for the help. Yes, am using the 18M2, on the CHI-030 project board. I will try the code when I am in the office tomorrow and will post the results. Once we have the unit running on the wheelchair, will post a video of it in action. Thanks again.
 

Pat13

Senior Member
Can you post the minimum code that demonstrates the problem?
here it is
Code:
	start0:
		readadc Range_RF,b1		'read range in inches into byte variable
		readadc Range_LF,b2
		
		if b1< 16 'if chair is within 18"-24" of object gosub alarm1 
	 	then gosub alarm1
 

westaust55

Moderator
As already mentioned, fixing the problem by moving the THEN GOSUB xxx to the same line as the IF... does solve the problem

Here is a snippet of the original code
Code:
'Wheelchair Range Sensor for client EK, clinically blind quadriplegic

symbol Range_RF=B.1
symbol Range_LF=B.2
symbol Range_R =B.3
symbol Range_L =B.4
symbol Range_RR=B.5

symbol Spkr_RF =C.0
symbol Spkr_LF =C.1
symbol Spkr_R = C.2
symbol Spkr_L = C.6
symbol Spkr_RR =C.7

main:
	start0:
		readadc Range_RF,b1		'read range in inches into byte variable
		readadc Range_LF,b2
		
		if b1< 16 then [B][COLOR="#006400"]gosub alarm1[/COLOR][/B] 'if chair is within 18"-24" of object gosub alarm1 
               [COLOR="#B22222"] ; gosub alarm1[/COLOR] ; remove here - it is now in the line above		
                GOTO Main ; added for for demo only
		
Alarm1:
	RETURN
 
Last edited:

Pat13

Senior Member
We seem to have run into another issue. The piezo that we are using are not loud enough when powered with 5V. They are rated 5-30V. We are using a CHI030 board and of course, I can use the darlington side of the board with 12V, however. I need to have at least 4, preferably 5 inputs to readadc for the range sensors, correct. And according to the 18M2 specs only C.0, C.1 and C.2 have readadc. Is there a way that i can power the piezos off 12V but still use a couple of the B pins to readadc the sensors? The sensors are rated for 5V.
 

eclectic

Moderator
A drastic but feasible method:

1. Saw off the top 6 legs of the ULN2803.

2. Connect jumper wires.

You then have inputs B.5, B.6 and B.7

e
 

Attachments

Pat13

Senior Member
The board we are using is actually a CHI030A and has a strip between the picaxe and the darlington designated B.0 thru B.7. I'm sure I could use these once i cut off the appropriate legs of the darlington
 

eclectic

Moderator
The board we are using is actually a CHI030A and has a strip between the picaxe and the darlington designated B.0 thru B.7. I'm sure I could use these once i cut off the appropriate legs of the darlington
In that case, there seems no need to amputate anything.

Just don't connect to the right-hand outputs of the ULN2803

e
 
Top