Welcome, Guest. Please Login.
Surveyor Corporation Surveyor SRV-1
Home Help Search Login

Surveyor Robotics Forum

Welcome to the user support forum for Surveyor SRV-1 robots, SRV-1 robot controllers and SVS stereo vision systems. To register for this forum, please send an email to support@surveyor.com which includes your desired forum user name, your registration email address, and a brief explanation of why you wish to join, and we will create a forum account for you.

Please note that there is a Search button in the forum toolbar for forum topics. Another effective search method for the entire surveyor.com site is to use Google, e.g. "xyz site://www.surveyor.com" where "xyz" is the search topic.



Pages: 1
Send Topic Print
I2C (Read 1819 times)
YL90
YaBB Newbies
*




Posts: 3
I2C
12/09/11 at 5:43am
 
I'm a student, currently working on a project, which requires SRV-1 to read from I2C devices.
I'm a newbie in robotics. I've downloaded the latest firmware, and know that many robot functions are declared.
 
But I have a few questions for the statement "readi2c (int device, int register)".
1. Are both of them written in hex form or decimal form?
2. Is the device corresponds to the device address?  
For example, the connected device is preprogrammed to the address 0x50, and I want to read from it.  
Should I just type readi2c (0x50, 0x00)?
3. How much delay I have to program between each reading?
 
Thank you.
Back to top
 
 
  IP Logged
tjump
Global Moderator
*****




Posts: 408
Re: I2C
Reply #1 - 12/12/11 at 5:52am
 
There is some missing information that makes it difficult to answer your questions. First and foremost, are you planning on using SRV direct commands, picoC, or some other means to poll the device?
 
T. Jump
Back to top
 
 
  IP Logged
YL90
YaBB Newbies
*




Posts: 3
Re: I2C
Reply #2 - 12/22/11 at 8:42pm
 
I'm planning to use a direct command, which found in C interpreter.
 
int readi2c(int device, int register): read byte from I2C port
Back to top
 
 
  IP Logged
tjump
Global Moderator
*****




Posts: 408
Re: I2C
Reply #3 - 12/23/11 at 12:04am
 
I think you are mixing your user terms for the SRV. Direct commnads are not related to the C interpreter (picoC). Direct commands for reading I2C devices are in the form irab, iRab, iMabc.
 
The C interpreter is picoC. Reading I2C with picoC commands differ depending on what you want to read. There is the generic process to read I2C devices in the form 'readi2c(x, y);' where 'x' is the I2C device address (int device) and 'y' is the port on the device (int register). However, if you are using one of the ADC devices already pre-configured for the SRV, to read these analog devices the code is in the form 'analog(x);' where 'x' is the port of the analog device (int channel).
 
Now, to your specific device at address 0x50 your are correct with the first part of your 'read' request:
 
readi2c(0x50, y);
 
but what you put in for 'y' depends on the device. It will most likely be in hex form (0x..) but probably not 0x00. For instance, there is a digital I/O used on the RCM with eight ports. A picoC read request for this device looks like:
 
readi2c(0x27, 0x12);  to read bank A ports (ports 1 - 8)
 
readi2c(0x27, 0x13);  to read bank B ports (ports 1 - 8)
 
Now, once you've read the device you must specify what to do with the data? If you simply want to see what the value is you need to call a print function 'print(f)' so the value of your read is displayed.
 
Example:  
 
int x;
x = readi2c(0x27, 0x13);
 
printf("%d\n", (x & 0x02));
 
exit();
 
In this example, the digital I/O is read (all eight ports have a value), but only the value of port 2 is displayed per the print(f) statement.
 
 
So, you need to understand what your device offers as options to read to know what value to put into the 'y' section of the read statement; then you need to understand what you want to do with the data.
 
 
T. Jump
Back to top
 
« Last Edit: 12/23/11 at 12:33am by tjump »  
  IP Logged
YL90
YaBB Newbies
*




Posts: 3
Re: I2C
Reply #4 - 12/23/11 at 5:46am
 
Ok, thx for explaining the difference between direct commands and the picoC.
 
Yes, I'm going to use the picoC. The device I'm using is the line tracker device, but its documentation didn't specify which is the port to read. It's just stated that the device is preprogramed at address 0x50. It will return a decimal number 0-127 when receives I2C read signal.
 
The documentation is as follow, in case you want to see it.
http://www.roboticsconnection.com/p-67-line-following-sensor.aspx
 
Thanks.
Back to top
 
 
  IP Logged
tjump
Global Moderator
*****




Posts: 408
Re: I2C
Reply #5 - 12/23/11 at 12:06pm
 
This device may allow for a simple "readi2c(0x50);" and not need a second integer. PicoC, however may need the second int to meet it's formating requirement. You may be able to use "readi2c(0x50, 0);" or something like this. As the bit value is 127 you may need "readi2c(0x50, 0x80);" as this requests a read of all bits. It will take a little bit of research and/or playing around to find a functioning code line.
 
Hopefully you can poll individual sensors on the board; for example, to read the second sensor:
 
int x;
x = readi2c(0x50, 0x80);
 
printf("%d\n", (x & 0x02));
 
exit();
 
 
Another thing to look for, depending on which version of firmware you have the exit(); function in picoC requires an actual int value in the newer versions. If you get an error throwing at the exit(); function then change it to exit(0);
 
Finally, the amount of delay is more likely dependent on your device than the SRV. It will probably require testing to see what it takes. I would guess delay(2); would be sufficient, but again it will take some testing.
 
 
T. Jump
Back to top
 
« Last Edit: 12/23/11 at 1:29pm by tjump »  
  IP Logged
Pages: 1
Send Topic Print