How can I read multiple ADC inputs from ADS1115 with an I2C interface in MATLAB?
14 views (last 30 days)
Show older comments
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, https://www.youtube.com/watch?v=bGSiz4AiSvU&t=620s , but it generated lots of errors.
The Arduino on the other hand, has successfully printed each digital outputs when I used Serial.print command.
0 Comments
Answers (3)
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;
clc;
delete(instrfindall)
instrreset;
a = arduino('com7','mega2560');
adrr = '0x48';
ADC=0;
data=0;
i2c = i2cdev(a,adrr);
disp(['vib'])
figure
h = animatedline;
ax = gca;
ax.YGrid = 'on';
stop = false;
startTime = datetime('now');
while ~stop
writeRegister(i2c,1,hex2dec('C3E3'),'uint16'); % ch0 860sps
pause(1.2e-3);
while (data ~= 50147)
[data]=readRegister(i2c,1,'uint16');
end
[data1]=readRegister(i2c,0,'uint16');
%[data2]=readRegister(i2c,1,'uint16');
data1 = double(swapbytes(data1));
%data3= double(swapbytes(data2));
ADC=(data1*4.096)/32767.0;
% Get current time
t = datetime('now');
% Add points to animation
addpoints(h,datenum(t),ADC)
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
datetick('x','keeplimits')
drawnow
end
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 ^^
0 Comments
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.
0 Comments
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!