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;
t = datetime('now');
addpoints(h,datenum(t),ADC)
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
Sign in to comment.