Write and read I2C on arduino
77 views (last 30 days)
I want to get the data out of the Sensirion SDP810-125Pa via my arduino. With a llibrary that I downloaded from github, the sensor works fine and gives me data via I2C and the serial moitor respectively with the Arduino IDE.
Now I wanna combine it with Matlab.
myarduino = arduino('COM3','Uno','Libraries','I2C');
pressureSensor = device(myarduino,'I2CAddress',0x25,'bitrate',100000);
write(pressureSensor, 0x361E, 'uint16');
data = read(pressureSensor, 2,'uint16');
I configured the I2CAddress but now it gives me the followin error.
Error using Untitled (line 6)
Error occurred while reading data from the I2C device. Check the connections between the hardware and device, clear the device object and create a
Thanks for your help!
Aakriti Suman on 27 Mar 2020
I understand that you want to use I2C devices on Arduino hardware.
The address that you are using for I2C communication seems incorrect. The bus address used for I2C comunication on Arduino hardware is 0x48. You can also scan the I2C bus to get the I2C address. You can try the below code snippet.
% connect all the I2C devices with the arduino and then perform the following snippet
myarduino = arduino('COM4','Uno','Libraries','I2C') % assuming that the arduino hardware is connected in COM4 serial port.
add = scanI2CBus(myarduino);
Here is an example documentation of the usage of I2C devices on arduino hardaware. This will help you in understanding the I2C communication with arduino hardware in detail. https://in.mathworks.com/help/supportpkg/arduinoio/ug/measure-temperature-from-i2c-device-on-arduino-hardware.html
I am also attaching a document which will help you with the functions that can be used in reading and writing to I2C devices connected to arduino hardware. https://in.mathworks.com/help/supportpkg/arduinoio/i2c-sensors.html?s_tid=CRUX_lftnav
Harsha Priya Daggubati on 23 Mar 2020
You need to have either a Total Phase Aardvark host adapter or a NI USB-845x adapter board installed to use the i2c interface.
Refer to the following link for installation help:
You can also follow the steps listed here after the installation is successful:
These threads might be of help too: