ADS1115 lib with SCL1/SDA1 on teensy 3.1 issues

Status
Not open for further replies.

Errorkey

New member
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/i2cdevlib/blob/master/Arduino/I2Cdev/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:confused::confused:

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/i2cdevlib/tree/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
 

Attachments

  • P1130984.jpg
    P1130984.jpg
    167.1 KB · Views: 256
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...
 
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-New-I2C-library-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.
 
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.
 
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);
 
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.
 
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.
 

Attachments

  • ABS_ADS1X15.zip
    9.4 KB · Views: 170
Last edited:
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:
Status
Not open for further replies.
Back
Top