Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Reading Arduino Serial Port into Matlab and 50% of the time getting characters instead of digits.

Reading Arduino Serial Port into Matlab and 50% of the time getting characters instead of digits.

/ 2025-01-07
Reading Arduino Serial Port into Matlab and 50% of the time getting characters instead of digits.
Matlab

Exactly as the title says.
Trying to read serial values from an Arduino serial port into a matlab array. The sensor we’re reading from is a heartrate sensor from https://pulsesensor.com/. This is for a science fair project where a full collection is about 30 seconds long and then it is broken into chunks of 500 datapoints. So 6 trials from one collection. 60% of the time we’ll get a sensor reading that is in a doubles format but that other 40% the code seems to read extra characters and defaults back into characters. These characters aren’t random letters either but have plenty of accents and such. (example below the code)

We dont have trouble connecting to the board and when the data is being printed into the matlab command window it shoes numberical values ranging from 0 – 750 depending on the signal voltage. Its only after the loop that the file converts into a char array (usually 3005×1).

Any suggestions on how to ensure that the file stays in double and doesnt convert into a character array? I think it might have to do with the sampling frequency and aligning the arduino with the matlab code reading it but I’m not very familar with the process. Any suggestions would be greatly appreciated.
% Define the port where Arduino is connected
arduinoPort = ‘COM3’; % Replace ‘COM3’ with your actual port
baudRate = 9600; % Set the baud rate to match the Arduino’s baud rate
s = serial(arduinoPort, ‘BaudRate’, baudRate); % Create a serial object for the Arduino

% Initialize an empty array to store PPG data
ppgData = [];
numSamples = 3000; % Set the number of samples to collect (can be adjusted)

disp(‘Collecting PPG data…’); % Display message indicating data collection has started
j=1
fopen(s); % Open the serial port for communication
while j < numSamples+1
% Check if there is data available in the serial buffer
if s.BytesAvailable > 0
i = 1:numSamples; % Loop to collect the specified number of samples
% Read data from the serial port as a string and convert to an integer
data = fscanf(s, ‘%d’);
disp(data); % Display the received data to verify if values are being read
ppgData = [ppgData, data]; % Append the new data to the PPG data array
j=j+1;
%pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
else
disp(‘No data available in buffer.’); % Warn if no data is available
end
pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
end

ppgData = ppgData’;

data = reshape(ppgData, [500, 6]);
‘¼’
‘Ç’
‘Ì’
‘Ê’
‘à’
‘à’
‘ç’
‘ó’
‘ñ’
‘Ā’
‘ý’
‘û’
‘Ă’
‘ó’
‘ò’
‘ì’
‘×’
‘ß’
‘Î’
‘Ç’
‘¿’
‘«’
‘«Exactly as the title says.
Trying to read serial values from an Arduino serial port into a matlab array. The sensor we’re reading from is a heartrate sensor from https://pulsesensor.com/. This is for a science fair project where a full collection is about 30 seconds long and then it is broken into chunks of 500 datapoints. So 6 trials from one collection. 60% of the time we’ll get a sensor reading that is in a doubles format but that other 40% the code seems to read extra characters and defaults back into characters. These characters aren’t random letters either but have plenty of accents and such. (example below the code)

We dont have trouble connecting to the board and when the data is being printed into the matlab command window it shoes numberical values ranging from 0 – 750 depending on the signal voltage. Its only after the loop that the file converts into a char array (usually 3005×1).

Any suggestions on how to ensure that the file stays in double and doesnt convert into a character array? I think it might have to do with the sampling frequency and aligning the arduino with the matlab code reading it but I’m not very familar with the process. Any suggestions would be greatly appreciated.
% Define the port where Arduino is connected
arduinoPort = ‘COM3’; % Replace ‘COM3’ with your actual port
baudRate = 9600; % Set the baud rate to match the Arduino’s baud rate
s = serial(arduinoPort, ‘BaudRate’, baudRate); % Create a serial object for the Arduino

% Initialize an empty array to store PPG data
ppgData = [];
numSamples = 3000; % Set the number of samples to collect (can be adjusted)

disp(‘Collecting PPG data…’); % Display message indicating data collection has started
j=1
fopen(s); % Open the serial port for communication
while j < numSamples+1
% Check if there is data available in the serial buffer
if s.BytesAvailable > 0
i = 1:numSamples; % Loop to collect the specified number of samples
% Read data from the serial port as a string and convert to an integer
data = fscanf(s, ‘%d’);
disp(data); % Display the received data to verify if values are being read
ppgData = [ppgData, data]; % Append the new data to the PPG data array
j=j+1;
%pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
else
disp(‘No data available in buffer.’); % Warn if no data is available
end
pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
end

ppgData = ppgData’;

data = reshape(ppgData, [500, 6]);
‘¼’
‘Ç’
‘Ì’
‘Ê’
‘à’
‘à’
‘ç’
‘ó’
‘ñ’
‘Ā’
‘ý’
‘û’
‘Ă’
‘ó’
‘ò’
‘ì’
‘×’
‘ß’
‘Î’
‘Ç’
‘¿’
‘«’
‘« Exactly as the title says.
Trying to read serial values from an Arduino serial port into a matlab array. The sensor we’re reading from is a heartrate sensor from https://pulsesensor.com/. This is for a science fair project where a full collection is about 30 seconds long and then it is broken into chunks of 500 datapoints. So 6 trials from one collection. 60% of the time we’ll get a sensor reading that is in a doubles format but that other 40% the code seems to read extra characters and defaults back into characters. These characters aren’t random letters either but have plenty of accents and such. (example below the code)

We dont have trouble connecting to the board and when the data is being printed into the matlab command window it shoes numberical values ranging from 0 – 750 depending on the signal voltage. Its only after the loop that the file converts into a char array (usually 3005×1).

Any suggestions on how to ensure that the file stays in double and doesnt convert into a character array? I think it might have to do with the sampling frequency and aligning the arduino with the matlab code reading it but I’m not very familar with the process. Any suggestions would be greatly appreciated.
% Define the port where Arduino is connected
arduinoPort = ‘COM3’; % Replace ‘COM3’ with your actual port
baudRate = 9600; % Set the baud rate to match the Arduino’s baud rate
s = serial(arduinoPort, ‘BaudRate’, baudRate); % Create a serial object for the Arduino

% Initialize an empty array to store PPG data
ppgData = [];
numSamples = 3000; % Set the number of samples to collect (can be adjusted)

disp(‘Collecting PPG data…’); % Display message indicating data collection has started
j=1
fopen(s); % Open the serial port for communication
while j < numSamples+1
% Check if there is data available in the serial buffer
if s.BytesAvailable > 0
i = 1:numSamples; % Loop to collect the specified number of samples
% Read data from the serial port as a string and convert to an integer
data = fscanf(s, ‘%d’);
disp(data); % Display the received data to verify if values are being read
ppgData = [ppgData, data]; % Append the new data to the PPG data array
j=j+1;
%pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
else
disp(‘No data available in buffer.’); % Warn if no data is available
end
pause(0.01); % Pause for 10 milliseconds to allow time for new data to arrive
end

ppgData = ppgData’;

data = reshape(ppgData, [500, 6]);
‘¼’
‘Ç’
‘Ì’
‘Ê’
‘à’
‘à’
‘ç’
‘ó’
‘ñ’
‘Ā’
‘ý’
‘û’
‘Ă’
‘ó’
‘ò’
‘ì’
‘×’
‘ß’
‘Î’
‘Ç’
‘¿’
‘«’
‘« arduino, fscanf, char, arduino serial MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Warning: Error updating FunctionLine in using fplot
2025-05-12

Warning: Error updating FunctionLine in using fplot

Solid creation Simulink, simscape multibody: stuck in loading
2025-05-12

Solid creation Simulink, simscape multibody: stuck in loading

Does Matlab 2023b support Classification learner like what I got trainned in ML Module?
2025-05-12

Does Matlab 2023b support Classification learner like what I got trainned in ML Module?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss