SwingeyP
Member
Not sure if this is in the right place but as everything developed so far has used OSHON here goes.
Well after a 2 year break (mainly due to illness) I am back on my robot project.
I never really found any answers to this so here goes again.
I have a URM 37 V3.2 ultrasonic sensor. I want to be able to read the temperature (and later distance - temp looks easier for the moment) from the sensor and act accordingly. I just can't get my head around how it works.
Here's the code
I have also attached the details of the URM37 as a PDF.
Am I send the 'commnd construct' and reading the 'data consruct' correctly?
It seems to work in simulation but no go in the real world.
Can anyone help please?
Regards - Paul
Well after a 2 year break (mainly due to illness) I am back on my robot project.
I never really found any answers to this so here goes again.
I have a URM 37 V3.2 ultrasonic sensor. I want to be able to read the temperature (and later distance - temp looks easier for the moment) from the sensor and act accordingly. I just can't get my head around how it works.
Here's the code
Code:
Define CONF_WORD = 0x3ffc 'Internal Oscillator'
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'URM37 Ultrasonic Test written by paul swingewood
'July 2011 - PIC 16F648A
'--------------------------------------------------------------------------
'Define SIMULATION_WAITMS_VALUE = 2
AllDigital
'Define the comms for the LCD display.
Define LCD_LINES = 2
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 'Use the high order bits'
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20
Define SEROUT_DELAYUS = 5000
Dim temperature As Byte
Dim distance As Byte
Dim datain(4) As Byte 'Array to store raw Data (Remember 0-3) word?
startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
WaitMs 20
Gosub welcome
WaitMs 20
Gosub setbaudrate
start:
Gosub sendcommandtemp
Gosub readtemp
Gosub calculatetemp
Gosub displaytemp
WaitMs 20
Gosub sendcommanddistance
Gosub readdistance
Gosub calculatedistance
Gosub displaydistance
Goto start
'--- sub routines ---
stop:
End
welcome:
Lcdcmdout LcdLine1Pos(1)
Lcdout "Waiting for DATA"
Return
setbaudrate:
Hseropen 9600 'Set the baud rate to 38400
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
WaitMs 10 '300
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Return
sendcommandtemp:
'send temp command to URM37'
Hserout 11h 'Send 11 00 00 11 to the URM37
Hserout 00h 'Tell the device we
Hserout 00h 'want to read the temperature
Hserout 11h
Return
readtemp:
'Read the data coming back from the URM37'Hserin datain(0) 'Bit1 -14
Hserin datain(0) 'Bit1 - 55
Hserin datain(1) 'Bit2 - 55
Hserin datain(2) 'Bit3 - 00
Hserin datain(3) 'Bit4 - 00
Return
calculatetemp:
temperature = datain(2)
Return
displaytemp:
Lcdcmdout LcdLine1Pos(1)
Lcdout "Temperature = ", #temperature
Return
sendcommanddistance:
'send distance command to URM37'
Hserout 22h 'Send 22 00 00 22 to the URM37
Hserout 00h 'Tell the device we
Hserout 00h 'want to read the distance
Hserout 22h
Return
readdistance:
'Read the data coming back from the URM37'Hserin datain(0) 'Bit1 -14
Hserin datain(0) 'Bit1 - 55
Hserin datain(1) 'Bit2 - 55
Hserin datain(2) 'Bit3 - 00
Hserin datain(3) 'Bit4 - 00
Return
calculatedistance:
distance = datain(2)
Return
displaydistance:
Lcdcmdout LcdLine2Pos(1)
Lcdout "Distance = ", #distance
Return
I have also attached the details of the URM37 as a PDF.
Am I send the 'commnd construct' and reading the 'data consruct' correctly?
It seems to work in simulation but no go in the real world.
Can anyone help please?
Regards - Paul