How can I program module ADS1115 with Arduino in Matlab?

11 views (last 30 days)
Hello! I am trying to program the module ADS1115 with Arduino in Matlab, I have reviewed these pages however I cannot understand how it works, has anyone managed to program? I have also tried this code and it does not give me an ADC value consistent with what the multimeter shows me.
My code is:
ar=arduino('COM4','Uno','Libraries','I2C');
dev = device(ar,'I2CAddress','0x48');
%dev = i2cdev(ar,'0x48'); % creates i2c device object
writeRegister(dev,1,51075,'uint16');
ADC=readRegister(dev,0,'uint16');
Volt=1.024*(ADC/65536);
disp(Volt)
pause(2)

Answers (2)

Tom Rockett
Tom Rockett on 5 Mar 2020
Hi Daniela
What is the voltage value that your code is giving you? If it is a factor of two out from the true value of 1.024V then the problem is due to using the wrong measurement mode of the ADS1115. You can try to set up your circuit to do a differential measurement, which will have the full 16-bits of resolution.
Best regards,
Tom
  3 Comments
Tom Rockett
Tom Rockett on 9 Mar 2020
Hi Daniela
If the value is random then that sounds like you are reading noise. I'm not sure what to suggest, other than checking all of the connections in your circuit.
Here is a photo of the circuit that I used, which is similar to what you are trying to achieve (apart from the voltage divider in my case). I hope this helps.
Tom
daniela tovar
daniela tovar on 10 Mar 2020
Hi Tom,
but what was your programming in matlab, I was connected the SCL and SDA to pins 4 and 5 of the arduino, so I see you connect it to the TX and RX. Truth?

Sign in to comment.


Tom Rockett
Tom Rockett on 10 Mar 2020
Hi Daniela
I don't know where you've got TX and RX from, I haven't used them. What model of arduino are you using? The SCL and SDA pins on the ADS1115 are connected to the SCL and SDA pins on the arduino, respectively.
You can try replacing your writeRegister line with:
writeRegister(dev,1,37762,'uint16');
As this should enable the differential measurement (using pins A0 and A3 on the ADS1115). I suggest you follow my original example and read the ADS1115 data sheet (the section on the config register) to understand what difference this will make.
Best of luck,
Tom
  3 Comments
Ahsan Sami
Ahsan Sami on 6 Jul 2022
Tom Rockett can u please help me in understanding how u design "37762" for both pins A0 and A3 and 51075 for only pin A0

Sign in to comment.

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!