View previous topic :: View next topic |
Author |
Message |
csshah
Joined: 28 Feb 2005 Posts: 24
|
I2C interface for photocell sensor |
Posted: Sun Jul 17, 2005 3:48 pm |
|
|
I would like to interface a photocell sensor with pic18F8720 using i2c interface. I never used i2c, if somebody has code to read data using i2c for similar sensor application then it would be very useful to me.
thanks in advance |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sun Jul 17, 2005 5:16 pm |
|
|
In short. Hook up the analog output of your photocell to a suitable I2C A/D converter. If you post the part number for your photocell, I'll be able to give you a more detailed explanation.
Cheers,
Kender |
|
|
csshah
Joined: 28 Feb 2005 Posts: 24
|
thanks |
Posted: Mon Jul 18, 2005 7:54 am |
|
|
hey
thanks for reply. it s actually a range finder by acroname. I wanted to measure relative distance using it. I am pasting the link to the page
[http://www.acroname.com/robotics/parts/R145-SRF08.html]
take care
cs[/url] |
|
|
Ttelmah Guest
|
|
Posted: Mon Jul 18, 2005 8:27 am |
|
|
Guess what. :-)
99% of it is already done for you!.
The key comes when you look at the data:
[http://www.robot-electronics.co.uk/htm/srf08tech.shtml]
Note the comment, that the unit behaves like the 24xx EEPROMs, except that the actual device address is different, and that the actual registers are 36 registers starting at address 0.
Complete drivers for the 24xx EEPROMs, are included with the CCS compiler, in the 'drivers' directory. Use the smallest and simplest (2401.c).
In this code, there are three locations where the value '0xA0' is used, and one where '0xA1' is used. Change these to the address of the device (0xE0, and E1 - the low 'bit' here signifies read/write control).
If you then try 'read_ext_eeprom(0)', you should get back the firmware revision of the unit.
If you try:
Code: |
//Obviously you will have to include this in some suitable 'main' code.
union {
int16 range;
int8 b[2];
} reading;
write_ext_eeprom(0,81);
//set to range in centimetres
delay_ms(65);
reading.b[0]=read_ext_eeprom(3);
reading.b[1]=read_ext_eeprom(2);
|
Then reading.range, should be the distance to the first echo in cm.
Best Wishes |
|
|
csshah
Joined: 28 Feb 2005 Posts: 24
|
thnaks a lot |
Posted: Wed Jul 20, 2005 8:23 am |
|
|
Hey Ttelmah
thanks a lot for ur help u made my life easier. I will try to do the way u suggested.
cheers
cs |
|
|
|