Go Down

Topic: see real time graphic from arduino by matlab serial port (Read 1 time) previous topic - next topic

azita

i want to see the HMC5883L output by matlab serial port and plot the real time output. how can i do it?

groundFungus

Is this a Matlab question or an Arduino question?

azita

@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

horace

if you do a web search for arduino matlab serial you get plenty of links on the topic

robtillaart

Can you post your Arduino code you have so far?
Without the code it is difficult to help you.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

azita

@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.




horace

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


azita

@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                 ''

horace

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/

azita

@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 .

sterretje

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up