ByAman Mangal IIT Bombay
June 6, 2012
Aman Mangal, IIT Bombay
Serial Communication between Arduino and MATLAB
1/36
Prerequisite
Serial data transfer in Arduino. Follow the link to learn more1 2
http://arduino.cc/en/Reference/serial http://www.ladyada.net/learn/arduino/lesson4.html http://users.ece.gatech.edu/bonnie/book/TUTORIAL/ tut_1.html http://www.mathworks.in/help/techdoc/matlab_ product_page.html
MATLAB programming. To learn more, go to1
2
You should be familiar with MATLAB structures, MATLAB objects etc. Basic programming concepts.
Aman Mangal, IIT Bombay
Serial Communication between Arduino and MATLAB
2/36
Serial Communication
Serial means ”One after another”. Serial communication is when we transfer data one bit at a time, one right after the other. Information is passed back & forth between the computer and Arduino by, essentially, setting a pin high or low. Just like we turn an LED on and off, we can also send data. One side sets the pin and the other reads it. MATLAB can read/send the data from/to the serial port of the computer and process it.
Aman Mangal, IIT Bombay
Serial Communication between Arduino and MATLAB
3/36
Buffer
It is most important to understand the nature of buffer to avoid errors later while writing codes. There exists a buffer between the two events of sending and reading the data. Say a sensor is streaming back data to your program, more frequently than your program reads it. Then the data is stored to a list which we call a buffer. One writes data into it and other reads it, may be with different speeds. Buffer are of finite length.
Aman Mangal, IIT Bombay
Serial Communication between Arduino and MATLAB
4/36
Buffer...in detail
Initially the buffer is empty. As new data values come in they get added to the bottom of the list (most recent data). If your program reads a value from the buffer, it starts at the top of the list (oldest data). Once you read a byte of data,