I've been working on a library for the SRF02 ultrasonic ranging module for a few weeks now. I've tested it as far as I can so I am posting it here for anyone else to use and hoping that someone else will be able to test it. I have been using a 16F914 with version 0.93 of the software I2C library for testing.
There are some notes at the top of the header file which give a list of the functions that are included which covers everything except resetting the automatic calibration.
I have also posted a demo program which shows off the main features.
I have been unable to change the bus address of the device. I have tried a few things and nothing seems to have worked so if anyone can give me some pointers with that I'd be grateful, as it would allow me to test the 'Fake range' and the 'Ping' functions properly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Displays the module software version, takes some measurements then reports the calibration data.
Results are displayed on a 2x16 LCD module.
;ChipSettings#chip 16F914,8#config CP=OFF, MCLRE=ON, PWRTE=ON, WDT=OFF, OSC=INTRC_OSC_NOCLKOUT;Includefiles(Libraries)#include <SRF02.h>;Defines(Constants)#define LCD_IO 8#define LCD_RW PORTD.6#define LCD_RS PORTD.7#define LCD_Enable PORTD.5#define LCD_DATA_PORT PORTB#define I2C_MODE Master#define I2C_DISABLE_INTERRUPTS ON#define I2C_DATA PORTC.7#define I2C_CLOCK PORTC.6;VariablesDimiAsbyteDimjAsbyteDimunitAsstringSRF02_Demo_1Wait1sSRF02_Demo_2Wait1sSRF02_Demo_3Wait1sCLSPrint"Finished!"SubSRF02_Demo_1'Read the software version and save in the SRF_ver variableSRF_SWVer0xE0'Display on the LCDCLSPrint"Software version"Locate1,0PrintSRF_verEndSubSubSRF02_Demo_2Fori=0to2'0 = inches, 1 = cm, 2 = us'determine the unit for displayingSelectCaseiCase0unit="in."Case1unit="cm"Case2unit="us"EndSelectForj=1to100'Repeat 100 times'Take a measurement and save in the deviceSRF_Measurei,0xE0'Read the result from the device and saves in the SRF_Result variableSRF_GetResult0xE0'Output to the LCDCLSPrint"SRF_Measure "Printiprint" "Locate1,0PrintSRF_ResultPrint" "PrintunitWait100msNextNextEndSubSubSRF02_Demo_3'Set the unit to cm by making a measurementSRF_Measure1,0xE0'Wait for this to complete (takes around 66 ms)Wait70ms'Read the result and save in the SRF_Calib variableSRF_GetCalib0xE0'Output to the LCDCLSPrint"Calibration value"Locate1,0PrintSRF_CalibPrint" cm"EndSub
I have updated my SRF02.h library to version 0.2. Changes are:
- SRF_ChangeAddr now works and allows the I2C bus address to be changed which allows multiple sensors to be used
- SRF_Ping and SRF_FakeMeasure have been tested as best as I can and you seem to be able to detect a ping from one sensor on another.
The new file is attached. There's hardly any change from version 0.1.
Hello,
I've been working on a library for the SRF02 ultrasonic ranging module for a few weeks now. I've tested it as far as I can so I am posting it here for anyone else to use and hoping that someone else will be able to test it. I have been using a 16F914 with version 0.93 of the software I2C library for testing.
Technical details of the module are here: http://www.robot-electronics.co.uk/htm/srf02tech.htm
There are some notes at the top of the header file which give a list of the functions that are included which covers everything except resetting the automatic calibration.
I have also posted a demo program which shows off the main features.
I have been unable to change the bus address of the device. I have tried a few things and nothing seems to have worked so if anyone can give me some pointers with that I'd be grateful, as it would allow me to test the 'Fake range' and the 'Ping' functions properly.
Code Listing:
Last edit: Peter 2014-11-07
Example program:
Displays the module software version, takes some measurements then reports the calibration data.
Results are displayed on a 2x16 LCD module.
Last edit: Peter 2014-11-07
@Peter. Very nice.
May I include this good work in the next release of GCB?
This is a good addition to the portfolio!
Yes, no problem including it.
Hopefully a few more people will play around with it and test it. Being unable to change the module address is a bit of a limitation.
I have updated my SRF02.h library to version 0.2. Changes are:
- SRF_ChangeAddr now works and allows the I2C bus address to be changed which allows multiple sensors to be used
- SRF_Ping and SRF_FakeMeasure have been tested as best as I can and you seem to be able to detect a ping from one sensor on another.
The new file is attached. There's hardly any change from version 0.1.
@Peter. Thank you again. Can we publish as part of the next GCB release? I will add headers etc. for you.
Go for it.
If I find any more bugs in it beforehand I will let you know.