Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: ADS1115 lib with SCL1/SDA1 on teensy 3.1 issues

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    3

    ADS1115 lib with SCL1/SDA1 on teensy 3.1 issues

    Hi All,

    I am hoping for some guidance, I have been trying to get two ADS1115 modules working on the 2nd I2C bus of a Teensy 3.1 and am running out of talent and I can't find any tutorials!
    I have tried the Adafruit libary and got it working on a breadboard with one ADC on default wire.h with I2C0, but this I cannot get going on the 2nd I2c bus. I believe this is because the standard wire lib only works on SCL0/SDA0
    Moving on from that I have tried the i2cdevlib/Arduino/ADS1115 which seems a better lib and has features I would like to use but again does not seem to let me use the 2nd bus. Using the I2C_t3 lib I think is the answer
    but do not know how to get there. I am trying to use the wire1 as wire0 will be used for coms to another Teensy 3.1, basically offloading processing time onto a secondary MCU to allow the main MCU to do other things.

    I found this, https://github.com/jrowberg/i2cdevli...2Cdev/I2Cdev.h seems to say added support i2c_t3 for Teensy3.1, but the comment is, Don't do anything special for Teensy, just use regular Arduino Wire lib, I don't understand this! I tried looking in the ADS1115.h & I2Cdev.h file to see if i can force it to use i2c_t3 but could not work it out also I felt like I was in very deep water! so I ask you guys as I am rather stuck here

    Apologies for the code it is not cleaned up or working! I'm using Arduino IDE 1.6.9

    [ CODE]
    /*
    * trying to use i2cdevlib & i2c_t3

    https://github.com/nox771/i2c_t3/blob/master/README.md //Teensy I2C libary
    https://github.com/jrowberg/i2cdevli...master/Arduino

    0x00 = CPU 2 master (to coms with ADC's)
    0x48 = ADC 1
    0x4B = ADC 2
    0x66 = CPU 2 slave (to coms with CPU 1)
    */

    //#include <i2c_t3.h>
    #include <ADS1115.h>

    ADS1115 adc0(ADS1115_DEFAULT_ADDRESS); // construct an ads1115 instance (adc1, at address 0x49)
    ADS1115 adc1(ADS1115_ADDRESS_ADDR_SCL); // construct an ads1115 instance (adc2, at address 0x49)

    long 1Pressure=0;
    long 2Pressure=0;
    long 3Pressure=0;
    long 4Pressure=0;

    void setup() {
    Serial.begin(115200);
    delay(1000);
    Serial.println("ADC 1115");

    //Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
    //Wire.begin();
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);
    //Wire.begin(I2C_SLAVE, 0x66, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
    //Wire.setDefaultTimeout(200000); // 200ms

    adc0.initialize(); // initialize ADS1115 16 bit A/D chip
    adc1.initialize(); // initialize ADS1115 16 bit A/D chip

    Serial.println("Testing adc0..");
    Serial.println(adc0.testConnection() ? "adc0 connection successful" : "adc0 connection failed");
    Serial.println("Testing adc1..");
    Serial.println(adc1.testConnection() ? "adc1 connection successful" : "adc1 connection failed");

    //adc0.showConfigRegister(); //turn on the SERIAL_DEBUG in the ADS1115.h file
    //adc1.showConfigRegister(); //turn on the SERIAL_DEBUG in the ADS1115.h file

    adc0.setRate(ADS1115_RATE_860); //sample rate
    adc1.setRate(ADS1115_RATE_860); //sample rate

    adc0.setMode(ADS1115_MODE_CONTINUOUS); //do continuous sampling
    adc1.setMode(ADS1115_MODE_CONTINUOUS); //do continuous sampling

    adc0.setGain(ADS1115_PGA_0P256); //Set the gain (PGA) +/- 0.256v, 16x gain
    adc1.setGain(ADS1115_PGA_0P256); //Set the gain (PGA) +/- 0.256v, 16x gain
    }

    void loop() {

    1Pressure=adc0.getConversionP0N1(); //sets the mux and gets a reading.
    2Pressure=adc0.getConversionP2N3(); //sets the mux and gets a reading.
    3Pressure=adc1.getConversionP0N1(); //sets the mux and gets a reading.
    4Pressure=adc1.getConversionP2N3(); //sets the mux and gets a reading.

    Serial.print("1 = "); Serial.println(1Pressure);
    Serial.print("2 = "); Serial.println(2Pressure);
    Serial.print("3 = "); Serial.println(3Pressure);
    Serial.print("4 = "); Serial.println(4Pressure);
    Serial.println();

    delay(500);
    }
    [ /CODE]

    Error is:
    Teensy_ADC_pressure_sensor_test_V05:33: error: 'I2C_MASTER' was not declared in this scope
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);

    This tells me the i2c_t3 is not being used and wire.h does not like the commands

    Any help would be appreciated
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	P1130984.jpg 
Views:	125 
Size:	167.1 KB 
ID:	8437  

  2. #2
    Senior Member onehorse's Avatar
    Join Date
    Apr 2014
    Location
    Danville, California
    Posts
    921
    Need to use Wire1 for pins 29/30 with the i2c_t3.h library. And do not use the internal pullups, should have external 4K7 pullups. There is a nice description on how to use the i2c_t3.h library; maybe a moment to read it would help...

  3. #3
    Junior Member
    Join Date
    Oct 2016
    Posts
    3
    Quote Originally Posted by onehorse View Post
    Need to use Wire1 for pins 29/30 with the i2c_t3.h library. And do not use the internal pullups, should have external 4K7 pullups. There is a nice description on how to use the i2c_t3.h library; maybe a moment to read it would help...
    Hi onehorse,

    Thank you for your reply. Yes I have read all the pages I could find and searched the forums here and elsewhere including the guide you mentioned https://forum.pjrc.com/threads/21680...ry-for-Teensy3 (I read that one thoughly and all the github stuff) and have not been able to work it out for myself as there is no example code calling wire1 I have found only mention of it, I have not been able to work it out for myself after about 5+ hours only then have I resorted to reluctanlty asking on the forum as I am aware that sometimes people ask all too easily, plus if I don't work for it out for myself next problem I encounter I will not have had the experiance of getting though it (and the stupid thing is it's probably something simple).
    Please if you can see my mistake and can show me the correct code that would be great even better would be explain it too! As for int/ext pullups that is only there as I have been changing things to try to understand the errors I am getting from the compiler(they are under the teensy PCB) one of my main queries is ,will the ADS1115 lib use the i2c_t3 when compiling as far as I can see it will not.

    The closest mention on wire1 I found was

    Wire.begin(address); - initializes I2C as Slave mode using address, external pullups, 100kHz rate, and default pin setting
    return: none
    parameters:

    Wire1: I2C_PINS_29_30 (3.1/3.2)

    So that is what I used in
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);
    but this is not working, defining I2C_PINS_29_30 should enable wire1 no?

    Thanks.

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,252
    The trouble is most i2c libraries are not setup to use anything but the master i2c bus.

    Some i2c libraries have been modified to take an additional constructor that gives the appropriate i2c bus. I have an idea of how to solve this without modifying the libraries, but for the current time, what you need to do is copy the libraries you want to use to another name. Such as ADS1115_wire1, changing the name of the directory, and the *.h/*.cpp/example files inside to change #include <Wire.h> to #include <t3_i2c.h>, and within the library, change the occurrances of the Wire variable to Wire1.

  5. #5
    Senior Member onehorse's Avatar
    Join Date
    Apr 2014
    Location
    Danville, California
    Posts
    921
    Not:Wire.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);
    But:Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);

  6. #6
    Junior Member
    Join Date
    Oct 2016
    Posts
    3
    onehorse,
    Thank you for the clarification, I was sure it was something simple but if you dont know you dont know!
    MichaelMeissner
    You were right about the libs being written for the main i2c bus, this I did not have the skill or time to overcome.

    Just to wrap this up in the end I abandoned the external ADC approch and used a 3.3v referance and an op amp to the internal ADC with averaging and calibration to output the values to the second teensy via the i2c_t3 lib, I got very reasonable read rates and decent accuracy without too much noise.

  7. #7

    ADS1115 for Wire2 on T3.6

    This one is set up for 400000 on pins 3/4. MIT hack of the Adafruit lib.
    Maybe you could modify that as Wire2 is more searchable...also you'd need to change the begin() method...for the correct pin enum. ziplib.
    Attached Files Attached Files
    Last edited by 1bit; 02-24-2017 at 01:41 AM. Reason: can't spell

  8. #8
    Junior Member
    Join Date
    Sep 2016
    Location
    France
    Posts
    2
    Code:
     
    //#include <i2c_t3.h>
    #include <ADS1115.h>
    I'm using an ADS1115 since nearly years now with Jeff Rowberg updated I2Cdev library(supporting Teensy) and Teensy i2c_t3 library with an ADS1115 & Teensy 3.1

    In the code above you included only the ADS1115.h library.
    I use following include statement:
    Code:
     
    #include <I2Cdev.h>
    #include <i2c_t3.h>
    #include <ADS1115.h>
    I never checked if i2c_t3.h or I2Cdev.h are exclusive as it works that way.
    Then you have setup:
    Code:
     
      Wire.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, 400000);
    I suspect this initialize Jeff Rowberg Libray only and not i2c_t3 as I tested it with
    Code:
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, I2C_RATE_400);
    without success.
    I use only one ADS1115 but it initializes with:
    Code:
    Wire.begin();//use with I2Cdev & ADS1115 library
    and i2c speed is clearly the speed of i2c-t3 library.
    Just to find out how to initialize second i2c bus on Teensy

    The rest or your code should be ok. I need to mention that 860SPI is quite noisy. ADS1115 is a good product but not fast. Best results I got was 128SPI. Teensy running at 96Mhz and driving a ILI9371 display plus 2 analog buttons, 2 Touch buttons, a few leds, a voltage Ref, etc...
    Anyway my hardware is noisy but filtering out give me 15 bits with stable readings enough for my project. I take 12 samples using an array and cutting off extreme values/keeping mean values.

    Hope it helps
    Last edited by GSR_proj; 03-09-2017 at 12:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •