haseeb123
Newbie level 6
Hello
Please can someone help me to get the SRF02 ranger to register correctly by sending the correct distance
in CM. At the moment it is only replying back '0' and its LED flashs according to my program loop.
First I used the ranger via I2C interface and that worked well. Now I changed that to serial interface via
changing tie the SRF02 pin 4 to zero volts.
Im using the PIC18F2620 internal OSC @ 4MHz programming in CCS compiler. Below is my small test
program. Please can someone help me to get the SRF02 ranger to register correctly by sending the correct
distance to my serial port and print that out to hypertermial.
Thanks
Haseeb
Please can someone help me to get the SRF02 ranger to register correctly by sending the correct distance
in CM. At the moment it is only replying back '0' and its LED flashs according to my program loop.
First I used the ranger via I2C interface and that worked well. Now I changed that to serial interface via
changing tie the SRF02 pin 4 to zero volts.
Im using the PIC18F2620 internal OSC @ 4MHz programming in CCS compiler. Below is my small test
program. Please can someone help me to get the SRF02 ranger to register correctly by sending the correct
distance to my serial port and print that out to hypertermial.
Thanks
Haseeb
Code:
#include <18F2620.h>
#include <stdio.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN
// Set Speed to 4Mhz
#use delay(clock=4000000)
// Sonar
#use rs232(baud=9600, stop=2, parity=N, xmit=PIN_B2, rcv=PIN_C7, STREAM=Sonar)
// PC
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B3 ,STREAM=PC)
int range,
sonar_address = 0x00, //sonar address (factory default)
sonar_command = 0x54; //Enable Real Ranging Mode command '0x54' for...
//Result in centimeters & automatically Tx range back to...
//controller as soon as ranging is complete
void main(void)
{
delay_ms(100); //startup delay
while(true)
{
fputc(sonar_address, Sonar); //Sonar address '0'
fputc(sonar_command, Sonar); //data 0x54
while(!kbhit(Sonar)); //wait for char in USART buffer
range = fgetc(Sonar); //dump range in variable
fprintf(PC,"Range is %u cm\n\r",range);
delay_ms(250);
}
}