Why program hangs - callback during timer works
8 Comments

Tojmak comment mistakenly posted as an answer moved here:
Yeah i wonder why there's two Pitch_Change events. I'm clicking only once ;d. I will try with serial port monitor. Also i think i will play around a little with debugging. Thanks for your time. Tommorow i will try to do something and give you some info if you still will be willing to help me :). Thanks a lot.
Tojmak comment mistakenly posted as an answer moved here:
Hi, so I download serial monitor. After I found a small thing that I did wrongly Pitch_Change is running now only once. But there's still an error and warning.
I find out that propably the problem is that after Pitch_change function execute all data are combine. Just like on picture :
Last line shows the problem. "p", value, and "?" are put together. So I think that's the problem. Arduino gets that data and don;t know what to do. I tried to add some new line character but it doesnt't work. I tried :
-> fprintf(app.serial_COM, '%s\n','p'); -> fprintf(app.serial_COM, '%s\n\r','p'); -> fprintf(app.serial_COM, '%s','p'); fprintf(app.serial_COM, '\n'); But none of them works. "\n" is being replace with a single dot. Picture above shows that (for example "p" and value have dot between them). Then i tried send new line command from Arduino with Serial.println(""). Now I have that :
if true
if(Serial.available()>0)
{
zmienna_com = Serial.read();
if(zmienna_com == '?')
{
Serial.println(String(Kalman_angle_y)+","+String(Kalman_angle_x)+","+String(magn_direct_tilt)+","+String(Distance));
}
else if(zmienna_com == 'p')
{
Serial.println("");
ZADANE_pitch = Serial.read();
lcd.setCursor(6,1);
lcd.print(ZADANE_pitch);
Serial.println("");
} } end
That was for Arduino, and now Matlab part :
if true function PITCH_Change(app, event)
fprintf(2,'Pitch_change: Enter\n');
value = app.PitchSlider.Value;
app.EditPitch.Value = value;fprintf(2,'Pitch_change: Sending \n');
fprintf(app.serial_COM, '%s','p');
%fprintf(app.serial_COM,'\n');
pause(2);
fscanf(app.serial_COM,'%s'); fprintf(2,'Pitch_change: Sending %f\n', value)
fprintf(app.serial_COM, '%.2f',value);
% fprintf(app.serial_COM,'\n\r'); pause(2);
fscanf(app.serial_COM,'%s'); fprintf(2,'Pitch_change: Updating UI \n');
% drawnow;
fprintf(2,'Pitch_change: Exit \n');
end
endBut something is still missing because I've got that :
So, firstly I think I found some kind of sollution but it isn;t work perfectly because value and "?" are still together. And secondly I know that sollution is stupid and I should seperate all that data using matlab instead Arduino. Any ideas?
Answers (0)
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!