i want to see the HMC5883L output by matlab serial port and plot the real time output. how can i do it?
Is this a Matlab question or an Arduino question?
@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
if you do a web search for arduino matlab serial you get plenty of links on the topic
Can you post your Arduino code you have so far? Without the code it is difficult to help you.
thank you. i attache the arduino code. this is for a magnetometer(hmc5883l)
i use this matlab codes:
s.BaudRate = 9600;
s.InputBufferSize = 1000 ;
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.
HMC5883L_calibrate.ino (2.39 KB)
if you print out (Matlab) what is displayed? you arduino code has
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
@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 ''
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/
yes, i can see the results from tera tem.
in my arduino i have
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 .
azita: but i get 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.