MATLAB Answers

How can I read multiple ADC inputs from ADS1115 with an I2C interface in MATLAB?

57 views (last 30 days)
Sam Lo
Sam Lo on 21 Sep 2017
Edited: Malhar Ashtaputre on 5 Nov 2019
I currently have two 16-bit ADS1115 ADC converters with different I2C addresses, which are '0X48' and '0x49', where one of them has 3 inputs and another has 2 inputs. They share the same SCL-SDA ports in Arduino Mega 2560. I wonder how can MATLAB read each digital outputs from the converters. I have tried to implement the method used in this Youtube link, , but it generated lots of errors.
The Arduino on the other hand, has successfully printed each digital outputs when I used Serial.print command.

Answers (3)

Adrian Ng
Adrian Ng on 2 Jul 2018
I only success to read one input from ADS1115 using arduino mega2560 interface in MATLAB....the data shown in form of real time plot. Here is my coding:
clear all;
a = arduino('com7','mega2560');
adrr = '0x48';
i2c = i2cdev(a,adrr);
h = animatedline;
ax = gca;
ax.YGrid = 'on';
stop = false;
startTime = datetime('now');
while ~stop
writeRegister(i2c,1,hex2dec('C3E3'),'uint16'); % ch0 860sps
while (data ~= 50147)
data1 = double(swapbytes(data1));
%data3= double(swapbytes(data2));
% Get current time
t = datetime('now');
% Add points to animation
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
fclose(b); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I try to use ADXL335 accelerometer to collect vibration signal with ADS1115 to convert the output data into 16bit....the result still not accurate yet, Please help to check my coding is that any mistake??? and thanks in advance ^^

Malhar Ashtaputre
Malhar Ashtaputre on 31 Oct 2019
Edited: Malhar Ashtaputre on 5 Nov 2019
If you follow exact steps from video you will get some error regarding Wire library. So to solve that issue, just copy paste following files to your project folder before building s-function.
(I have attached in zip file)
Add #include"Wire.cpp" & #include"twi.c" in library section in s-function before building.
I suggest to try with interfacing only one ADS module first. Then go for two ADS1115 modules.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!