I have written and tested some code to use the Axon II with the Devantech's SRF02 and SRF08 ultrasonic rangers.
You can use same code for the SRF08 and I have added a line to use the light sensor that SRF08 has on it.
I have tested it and it works ok.
#include "sys/axon2.h"
#include "a2d.h" //use for ADC
#include "rprintf.h" //use for UART
#include "i2c_master.h" //use for I2C
//user includes
#include "hardware.h"
uint8_t address=0xE0; // I2C address for SRF02/08
uint8_t data[2]; // to put the high+low byte of the result
uint8_t result // our ranging result
uint8_t hb_reg=2; //Register 2 and 3 keep the result-we use the register 2 that holds the high byte
uint_8 light[1]; // put light sensor
uint_8 light_reg=1 // Register 1 for light sensor in SRF08
void appInitHardware(void)
{
//initialize UART ports (see hardware.h to change baud/names)
uartInit(USB_UART, USB_BAUD);
rprintfInit(USB_ACTIVATE);
}
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
rprintf("\nAxon Initiated.\n\n");
return 0;
}
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart)
{
if(i2cMasterWriteRegister(address,reg,81)) //start ranging in cm-replace with 80 if you want inches
{
delay_ms(70); //delay before next burst-no less than 65ms
rprintf("Ranging\n");
//i2cMasterReadRegisters(address,light_reg,1,light) // use this to read light sensor in SRF08
if(i2cMasterReadRegisters(address,hb_reg,2,data)) //read high byte and low byte
{
result=data[0]<<8; //put the high byte first and make room for the low byte
result=result+data[1]; // put the low byte
rprintf("\n%d",result); //print range
rprintf("\n");
}
else
{
rprintf("no communication\n");
}
}
return 0;
}
Theo