How to connect srf08 to x2

I was hoping if anyone have any details on how to connect sonar SRF08 to orangutan X2. It would be great if anyone has a test program as well.


From a quick google search I found this page, which indicates that you communicate with the SRF08 using I2C, which is also known as TWI (two-wire interface). For more information on how to do this with the X2, you need to refer to section 19 (2-Wire Serial Interface) of the mega644 datasheet. Section 19.6, which starts on page 208, details the TWI algorithm, and you can find some sample code on page 210. I’ve never used TWI, but the datasheet should provide all the information you need.

Now, the trickiest part might be accessing the two TWI pins on the X2. TWI communication requires, not surprisingly, two pins: SDA (serial data, mega644 pin PC1) and SCL (serial clock, pin PC0). Both of these pins serve as LCD data lines on the X2, so you will need to tap into the LCD header if you want access to them. SCL/PC0 is pin 7 of the LCD header and SDA/PC1 is pin 8 of the LCD header (see the Orangutan X2 schematic). If you want to use the LCD, you should be able to use pins PC0 and PC1 for both the LCD and your SRF08. If you want nothing but the SRF08 on the TWI pins, you can always use the LCD in 4-bit interface mode.

If tapping into the hardware TWI lines via the LCD header isn’t appealing to you, you could probably find some libraries that bit-bang TWI communication on arbitrary I/O lines using software. I recommend you try searching for terms like “bitbang TWI” or “software I2C”. After a few seconds of searching I found this thread, which seems like it could potentially be of use.

All in all, using hardware TWI should be as simple as adapting the code on page 210 of the mega644 datasheet, and using software I2C would hopefully be as simple as adding a library to your project. Other than that, it’s just a matter of sending the right commands to the SRF08 (see your SRF08’s datasheet for info on that). Good luck with your project!

- Ben