I am having trouble getting the BS2 to read and display ASCII code from a sensor. any Suggestions
Please post a data sheet, link to the data sheet, or part number of the sensor so we can help you. Almost all sensors I have come across with the exception of gps receivers send data in some form of binary.
sensors have an RS232 data format (with 0V to Vcc levels) The output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters,
followed by a carriage return (ASCII 13).
See the Stamp Manual for details, but the above will wait for the character "R", then take the next 4 bytes as a decimal integer and put the value in the variable called range. The carriage return will be ignored.
Nothing worked. I looked at the out from the sensor with a scope and it seemed to be sending data however the stamp didn't show anything in the debug. Called MaxBotix and they will try to come up with some code.
Nothing worked. I looked at the out from the sensor with a scope and it seemed to be sending data however the stamp didn't show anything in the debug. Called MaxBotix and they will try to come up with some code.
Did you try the code from their site?
[COLOR=#000000][FONT=Verdana]'Reads both the PW and serial outputs[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' {$STAMP BS2} [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' {$PBASIC 2.5} [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' www.danderrick.com/[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' permission for unlimited use granted to all [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' First test of the MaxSonar®-EZ1[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' micro µ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' ------- P PINs ----------------------------- [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [/FONT][/COLOR][B]pMaxRecv PIN 15
pMaxClock PIN 14
pMaxPWM PIN 0[/B][COLOR=#000000][FONT=Verdana] [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' --------------- X Variables ----------------- [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [/FONT][/COLOR][B]xDist VAR Word
xPulse VAR Word
xX VAR Byte [/B]
[COLOR=#000000][FONT=Verdana]' ============ Main loop ================ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [/FONT][/COLOR][B]DO GOSUB sPWM
GOSUB sSerial
DEBUG CR, CR
PAUSE 50
LOOP
END [/B][COLOR=#000000][FONT=Verdana] ' never reached [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]' ------------- Subs ------------------------ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [/FONT][/COLOR][B]sPWM:[/B][COLOR=#000000][FONT=Verdana] 'Max sends 147 µs per inch [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]'BS2 reads for 2 µs [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [/FONT][/COLOR][B]FOR xX = 1 TO 5
HIGH pMaxClock
PULSIN pMaxPWM, 1, xPulse
LOW pMaxClock
DEBUG DEC5 xPulse, " "
PAUSE 50
NEXT
DEBUG CR
RETURN
sSerial:
FOR xX = 1 TO 5
SERIN pMaxRecv\pMaxClock, 16468, [WAIT ("R"), DEC xDist]
DEBUG DEC5 xDist, " "
PAUSE 50
NEXT
DEBUG CR
RETURN[/B][COLOR=#000000][FONT=Verdana] [/FONT][/COLOR]
For some reason Maxbotix calls their inverted TTL "RS-232". It's really just inverted TTL.
Do any of the above suggestions show how to receive inverted data with the BS? Can the BS receive inverted serial? If the BS can't receive inverted serial then oldhippy will need to use an inverter of some sort.
You could also receive the data from the sensor by monitoring the pulse from one of the pins. I believe this behaves a lot like the Ping except you don't need to trigger the sensor.
I suppose you could also use RCTIME and read the analog signal the sensor uses.
Edit: I see Publison posted code to use both the serial data and the pulse data.
oldhippy - what model of Basic Stamp are you using (BS2, BS2e, BS2pe, etc.)? This matters as the baudmode value used in the sample code (16468, 8-bit, no parity, inverted, 9600) is for a particular set of Stamps.
...yup - I understand. Often times users will use "BS2" for any model, and I'm attempting to clarify that he's not using something other than a vanilla BS2.
Comments
It send s ASCII code?
How does the BS2 get the data? Via SERIN?
If it's SERIN, have you looked at SERIN and DEBUG in PBASIC Help?
Please post a data sheet, link to the data sheet, or part number of the sensor so we can help you. Almost all sensors I have come across with the exception of gps receivers send data in some form of binary.
followed by a carriage return (ASCII 13).
See the Stamp Manual for details, but the above will wait for the character "R", then take the next 4 bytes as a decimal integer and put the value in the variable called range. The carriage return will be ignored.
Exactly what didn't work?
Why won't you post what "code" you tried?
Did you try the code from their site?
You can try Baudmode 84 which is 8 BIT No-Parity Non-Inverted. You have the RS-232 and the TTL would probably be inverted data.
Do any of the above suggestions show how to receive inverted data with the BS? Can the BS receive inverted serial? If the BS can't receive inverted serial then oldhippy will need to use an inverter of some sort.
You could also receive the data from the sensor by monitoring the pulse from one of the pins. I believe this behaves a lot like the Ping except you don't need to trigger the sensor.
I suppose you could also use RCTIME and read the analog signal the sensor uses.
Edit: I see Publison posted code to use both the serial data and the pulse data.
That code Publison posted also uses a Pin for Flow-Control which I am guessing is the Ranging Start/Stop Pin.
Hippy, how do you have this thing wired and how are you powering it?
...yup - I understand. Often times users will use "BS2" for any model, and I'm attempting to clarify that he's not using something other than a vanilla BS2.