Controlling DS1803 digital potentiometer via arduino I2C protocol in Matlab

3 ビュー (過去 30 日間)
Greetings!
I feel like I am one step away from being able to control this digital potentiometer using matlab but I seem to be missing some key component.
Here is a link to the datasheet for the device I am trying to use: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf
I was able to run a package in arduino successfully that I found here: https://github.com/federico-galli/Arduino-dual-i2c-potentiometer-DS1803
I grounded all of the address inputs (A0,A1,A2) which gives me the correct (i think) address, 46.
Below is the code I am using in matlab.
clear all
a = arduino('COM3', 'Uno', 'Libraries', 'I2C');
addrs = scanI2CBus(a);
%this gives an address of 0x28
DS1803 = i2cdev(a, addrs{1});
write(DS1803, uint8(bin2dec('101010101')));
write(DS1803,250,'uint8')
Here how I have wired up the DS1803:
Again, I was able to get the LED to turn on with the arduino program. The matlab program seems to be much simpler and I am feeling like I am missing something.
When I execute the last line, the LED does not turn on. I see the indicator LEDs on the arduino flicker when sending the command though.
Any input would be really appreciated. I'll keep messing around with it in the meantime.
Thank you!

採用された回答

Konstantin Bakhurin
Konstantin Bakhurin 2018 年 12 月 6 日
For anyone with this problem, the following code worked for me
clear all;
a=arduino('com3','Uno');
pause(5);
addr=scanI2CBus(a);
dev=i2cdev(a,addr{1});
value=254;reverse=0;
for i=1:100
if value>=254
reverse=1;
end
if value<=242
reverse=0;
end
if reverse==0
value=value+1;
else
value=value-1;
end
writeRegister(dev,169,value);
pause(0.05)
end
clear dev;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by