Author Topic: Axon II and SRF02/08 code  (Read 1428 times)

0 Members and 1 Guest are viewing this topic.

Offline teoxanTopic starter

  • Full Member
  • ***
  • Posts: 49
  • Helpful? 2
Axon II and SRF02/08 code
« on: September 06, 2010, 12:18:10 PM »

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.

Code: [Select]
#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)


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

   //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("no communication\n");

return 0;


Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,166
  • Helpful? 111
Re: Axon II and SRF02/08 code
« Reply #1 on: September 06, 2010, 05:29:13 PM »
Thanks for the code Theo

I know that I've already told you via email that the SRF02 and SRF08 are already supported directly in WebbotLib - so this is just to let others know.

Webbot Home:
WebbotLib online docs:
If your in the neighbourhood:


Get Your Ad Here