Go Down

Topic: New and growing well-documented, feature-complete I2C device library (Read 21 times) previous topic - next topic

Graynomad

I suppose you library doesn't think of itself as a slave device, but can you implement that for inter-Arduino talks.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

terryking228

Jeff, Very nice professional work!  Thanks for the effort.

I'll be following...

Regards, Terry King
...In The Woods In Vermont
terry@yourduino.com
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Jeff Rowberg

#7
Aug 03, 2011, 07:27 am Last Edit: Aug 03, 2011, 07:38 am by Jeff Rowberg Reason: 1

Thanks Jeff, that would be great. I've had the device for over a week now but just not the time to try and cobble something together. I'm a hardware type and software comes slow and gradual to me. The built in A/D pins on a arduino are useful but sadly fall far short of instrumentation quality. I thoough this would be a nice improvement to have avalible.


Lefty, I just pushed a new ADS1115 class up on GitHub for you to try. It compiles okay, and it's as close to the datasheet as I could make it. There should hopefully be enough comments that you can tell how to use it, but check the datasheet or ask me if you aren't sure. I might not have an answer, but I can give it a shot. Let me know how it works.

The ADS1115 is interesting because it uses 16-bit registers, which I haven't run into before. I had to update the main I2Cdev library to support word-size operations conveniently instead of just byte-size ones, though I'm sure that will come in handy for other devices as well, so in no way was it wasted effort or a one-time-use thing.


one suggestion is to add a timeout property to the library so calls want hang if the I2C device does not respond. ... You would want to inform the caller of a timeout, for example return 0 if the code times out.


Good idea! I've added this as well. The timeout is set to a default of 250ms (defined in I2Cdev.h). Read operations that time out return -1, while 0 indicates instant failure and 1 or more indicates success. A timeout length of zero disables timeout detection. Thanks for the suggestion!


I suppose you library doesn't think of itself as a slave device, but can you implement that for inter-Arduino talks.


This could be useful, though I'd have to think about how best to build it into the library's basic structure. The I2Cdev main class and all device classes are specifically designed to interface with slave devices, and doing an Arduino-to-Arduino link is unpredictable and arbitrary in terms of protocols. The Arduino MasterReader example uses a very simple Wire implementation to do just that, including the necessary "onRequest" event hook on the "slave" Arduino. I don't know if it would be valuable to write one of these class libraries for generic communication, but if you had a specific functional protocol in mind for the slave device (like these manufactured I2C slave chips), then maybe it would be.

If you just use the basic "I2C::readBytes()" and other core functions of the main library, you might be able to accomplish simple communication without any specific device classes. I haven't tried, but it would be interesting.


Jeff, Very nice professional work! Thanks for the effort. I'll be following...


Thanks, Terry! I'm glad you and others believe it will be helpful. That's my goal!

   Jeff

mem


The timeout is set to a default of 250ms (defined in I2Cdev.h). Read operations that time out return -1, while 0 indicates instant failure and 1 or more indicates success. A timeout length of zero disables timeout detection.


I think that 250ms is too short for some precision I2C devices that have long sample times.
I suggest at least doubling the default  value to avoid false errors with those devices.

retrolefty

Jeff;

Thank you very much for your quick work on this ADS1115 device. I will try and check it out with the module this weekend. One possible question I have on a quick read through, are you sure about the I2C device addresses this device would use? You show:

Code: [Select]
#define ADS1115_ADDRESS_ADDR_GND    0x90 // address pin low (GND)
#define ADS1115_ADDRESS_ADDR_VDD    0x91 // address pin high (VCC)
#define ADS1115_ADDRESS_ADDR_SDA    0x92 // address pin tied to SDA pin
#define ADS1115_ADDRESS_ADDR_SCL    0x93 // address pin tied to SCL pin
#define ADS1115_DEFAULT_ADDRESS     ADS1115_ADDRESS_ADDR_GND


I would think the 7 bit I2C possible addresses that the Wire library would require would be:

Code: [Select]


#define ADS1115_ADDRESS_ADDR_GND    0x48 // address pin low (GND)
#define ADS1115_ADDRESS_ADDR_VDD    0x49 // address pin high (VCC)
#define ADS1115_ADDRESS_ADDR_SDA    0x4A // address pin tied to SDA pin
#define ADS1115_ADDRESS_ADDR_SCL    0x4B // address pin tied to SCL pin
#define ADS1115_DEFAULT_ADDRESS     ADS1115_ADDRESS_ADDR_GND


From the datasheet (QuickStart Guide, page 11) the 7 bit address is show as:

Quote
Hardware for this design includes: one ADS1113/4/5 configured with an I2C address of 1001000;


My understanding with using the Wire library calls, that one uses the 7 bit address for the calls and the Wire library adds the internal R/W bit to form the full 8 bit I2C address?

Thanks again;
Lefty

Go Up