|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Wednesday, March 26, 2008 4:31 AM
Posts: 5,
Visits: 9
|
|
| Hi, Everybody I'm trying to Interface I2C Line Following Sensor with my PIC16F877 and im use CCS compiler.It seems like it should be fairly straightforward. So what im trying to do as a beginnig is to read white line on the black ground.i made the following connection from the the Sensor: Vcc: connected to the +5V. Gnd: connected to the same ground of the PIC. Sda: connected to the Pin_C3. Scl: connected to the Pin_C4. Im using built in pullup resistors for Scl and Sda. When i turned the power on, the bi-color red/green LEDs were turned on, so the sensor is functioning perfectly. I'm using the following statement in my Pic Headers:
#use I2C(MASTER, SLOW,sda=PIN_C3,scl=PIN_C4) Then I tried to read from the sensor by issuing the following code: int read_color() { int8 data;
i2c_start(); i2c_write(0x50); // Address of the sensore (default address) i2c_write(0x00); // I don't want to write any thing to the registers i2c_stop(); i2c_start(); i2c_write(0x51); // Address plus 1 LSB for Read Mode data = i2c_read(); return data; } I put the sensor on the black ground, and I run the program. I checked the value of the data and i got 255. i changed the position of the sensor and i put it on the white ground, the reading should be 0 but i got 255 instead of the 0 !! what its mean (255)? is it means there is no connection? Any ideas about what I need to do to connect the sensor with the Pic? and is there any wrong with the code ? Thanks
|
|
|
|
|
Forum Member
      
Group: Moderators
Last Login: Thursday, July 10, 2008 1:17 PM
Posts: 32,
Visits: 47
|
|
| Try this i2c_read() should be i2c_read(0). add the i2c_stop(); int read_color() { int8 data; i2c_start(); i2c_write(0x51); // Address plus 1 LSB for Read Mode data = i2c_read(0); i2c_stop(); return data; }
Ringo Davis
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: Yesterday @ 8:31 AM
Posts: 270,
Visits: 396
|
|
| Please note that I moved this under the Robot Sensor Support forum. Best Regards!
Jason Summerour President, Summerour Robotics Corporation Microsoft MVP www.roboticsconnection.com
|
|
|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Wednesday, March 26, 2008 4:31 AM
Posts: 5,
Visits: 9
|
|
Try this i2c_read() should be i2c_read(0). add the i2c_stop(); int read_color() { int8 data; i2c_start(); i2c_write(0x51); // Address plus 1 LSB for Read Mode data = i2c_read(0); i2c_stop(); return data; }
','165px');" style="DISPLAY: inline" onclick="InstantASP_OpenMenu('_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName','_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName_SimpleMenuDivLayer','','165px');">ringo thank you for your replay, i will try your code and i will tell you about the result | ','165px');" style="DISPLAY: inline" onclick="InstantASP_OpenMenu('_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName','_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName_SimpleMenuDivLayer','','165px');"> | ','165px');" style="DISPLAY: inline" onclick="InstantASP_OpenMenu('_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName','_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName_SimpleMenuDivLayer','','165px');"> nad i will like to apology for posting the topic in wrong place, after i posted the topic i realized that its in wrong place
| ','165px');" style="DISPLAY: inline" onclick="InstantASP_OpenMenu('_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName','_ctl2_ctlTopic_ctlPanelBar_ctlTopicsRepeater__ctl7_smAuthorName_SimpleMenuDivLayer','','165px');">so im sorry |