Arduino Forum

Using Arduino => Interfacing w/ Software on the Computer => Topic started by: azita on Jan 15, 2018, 12:17 pm

Title: see real time graphic from arduino by matlab serial port
Post by: azita on Jan 15, 2018, 12:17 pm
i want to see the HMC5883L output by matlab serial port and plot the real time output. how can i do it?
Title: Re: see real time graphic from arduino by matlab serial port
Post by: groundFungus on Jan 15, 2018, 12:19 pm
Is this a Matlab question or an Arduino question?
Title: Re: see real time graphic from arduino by matlab serial port
Post by: azita on Jan 15, 2018, 05:00 pm
@groundFungus
it it a quastion about arduino i think, because i want to see the output of a sensor( a sensor which is operate by arduino), by matlab.
should i ask this question in another forume?
thank you
Title: Re: see real time graphic from arduino by matlab serial port
Post by: horace on Jan 15, 2018, 06:00 pm
if you do a web search for arduino matlab serial you get plenty of links on the topic
Title: Re: see real time graphic from arduino by matlab serial port
Post by: robtillaart on Jan 15, 2018, 06:40 pm
Can you post your Arduino code you have so far?
Without the code it is difficult to help you.
Title: Re: see real time graphic from arduino by matlab serial port
Post by: azita on Jan 15, 2018, 08:26 pm
@robtillaart
thank you. i attache the arduino code. this is for a magnetometer(hmc5883l)
i use this matlab codes:

s=serial('com3')
s.BaudRate = 9600;
 s.InputBufferSize = 1000 ;
 fopen(s)
out = fread(s,s.BytesAvailable,'uint8')


my sensor has, 6 register(8 bit), each pair of them show the magnetic field at a axis. its output is 2,s complementary.

the above code don't work well. do you help me to write the better code?


i start arduino and uploade the attached code to it. after that i start matlab and write the codes. but it cant read the correct output.



Title: Re: see real time graphic from arduino by matlab serial port
Post by: horace on Jan 15, 2018, 09:19 pm
if you print out (Matlab) what is displayed?
you arduino code has
Code: [Select]
Serial.begin(2000000);
but the Matlab code sets a baudrate of 9600?

should they be the same?

also in Arduino  loop() you appear to be writing data to the PC continuously - you could be overrunning the PCs serial buffers

Title: Re: see real time graphic from arduino by matlab serial port
Post by: azita on Jan 18, 2018, 10:03 am
@horace
i change the BAUDRATE to same as my arduino board. but it doesnt work again. sorry would you explan me about your comment ''             also in Arduino  loop() you appear to be writing data to the PC continuously - you could be overrunning the PCs serial buffers                 ''
Title: Re: see real time graphic from arduino by matlab serial port
Post by: horace on Jan 18, 2018, 10:17 am
loop() appears to run continuously with a short delay of 13milliseconds in the loop - if the PC cannot process the serial data you will get overrun and loose information.
Are you sure COM3 is correct?
If you run a terminal emulator such as TeraTermPro or RealTerm is the information displayed OK?

also have a look at
https://www.arduino.cc/reference/en/language/functions/communication/serial/
Title: Re: see real time graphic from arduino by matlab serial port
Post by: azita on Jan 18, 2018, 03:07 pm
@horace
yes, i can see the results from tera tem.
in my arduino i have
Serial.begin(9600);,

i set the tera tem to the parameter attached in this post. and at the matlab software, i set the values of baudrate to the 9600, too. and the others , like tera tem, too.
but i get errors .
Title: Re: see real time graphic from arduino by matlab serial port
Post by: sterretje on Jan 27, 2018, 05:09 am
but i get errors .
Which errors?

Be aware that only one PC program can use the serial port at a time; so trying teraterm and matlab at the same time will not work.