Hi! We have this project for our senior's research regarding the optimization of multiple sensors which incorporates DS Theory. I would like to know if any of you knows how to import data from a microcontroller into MATlab program?:-D
Hi! We have this project for our senior's research regarding the optimization of multiple sensors which incorporates DS Theory. I would like to know if any of you knows how to import data from a microcontroller into MATlab program?:-D
The simplest way is to use a serial interface - buy a USB to serial dongle for the PC, then use the built in support for serial ports in MATLAB to talk to the micro via one of its built in UARTS. If you buy an FTDI USB<->serial lead with logic level UART interface you can connect this directly to the UART ports on the micro.
If you need more bandwidth then use a micro with built in Ethernet and the built in support for network comms in the very latest release of MATLAB - this is more work (since you'll almost certainly need a lot more code and extra chips at the micro end) but can go faster and has other advantages.
MK
MATLAB has a direct interface for the most commonly used boards (Uno, Mega, Due, Leonardo) at Arduino Support from MATLAB - Hardware Support
This is much easier than trying to do your own bit-banging. The interface is just an ordinary USB cable from the PC to port on the Arduino.
There is a MATLAB package that you use to abstract the serial connection to both transmit instructions to, and receive data from the Arduino. The link I included in my post gives you "how-to" videos, code examples, and a documentation package. Only caveat is you need to have MATLAB R2014a or higher. There is more than one way to do it, but; for instance say I wanted to connect to an Arduino Uno on the USB port COM4, and use a TMP102 I2C temp sensor.
1. Start the connection: a = arduino ( 'com4', 'uno', 'Libraries', 'I2C')
2. Scan the I2C bus: addrs = scanI2CBus(a)
3. We'll say the only I2C address this returns is 0x298
4. You create the I2C object: tmp102 = i2cdev(a, '0x298')
5. And write the code to retrieve the Celsius temp using I2C:
write(tmp102, 0, 'uint8');
data = read(tmp102, 2, 'uint8');
temperature = (double(bitshift(int16(data(1)), 4)) + double(bitshift(int16(data(2)), -4))) * 0.0625
This is a screenshot of a demo on the MathWorks website using MATLAB R2015a. They've tried to make the API's close to Arduino syntax.