Skip to main content
4 votes
Accepted

Serial.availableForWrite versus Serial.flush

The line while (Serial.availableForWrite() <= 0) {} waits until the serial output buffer is not full. Whereas Serial.flush(); waits until the serial output buffer is empty.
Edgar Bonet's user avatar
  • 43.1k
3 votes

The analog read is not giving the correct waveform as that of an oscilloscope

Your sampling rate is far too low for the signals you are looking at; you're not getting enough data points for drawing something that looks like the original signal. The Arduino library's analogRead()...
ocrdu's user avatar
  • 1,795
3 votes

Linking Arduino and Matlab

This block of code can give you some idea... % create an arduino object a = arduino('com3', 'uno'); % start the loop to blink led for 10 seconds for i = 1:10 writeDigitalPin(a, 'D11', 1);...
karanrp's user avatar
  • 396
3 votes
Accepted

Employing C++ code for Arduino

You've got quite an interesting project. Programming an Arduino (C++) Arduino is C++ (or atleast a subset). The Arduino IDE uses the GNU AVR-GCC compiler. And it takes care of all "make" files and ...
aaa's user avatar
  • 2,695
2 votes

Employing C++ code for Arduino

Here's a sample program you could use as reference, just replace the values in the array and adjust VALUES_NUMBER accordingly. Disclaimer: I didn't try to compile/run it, but it should give you an ...
Igor Stoppa's user avatar
  • 2,125
2 votes

Questions on how to connect Arduino to Matlab through the serial port

I might try to reboot with out the Arduino plugged into the USB port, bring up the device manager and open the COM section and watch which COM becomes available when you do plug in the Arduino's USB ...
st2000's user avatar
  • 7,325
2 votes

Serial.availableForWrite versus Serial.flush

https://www.arduino.cc/reference/en/language/functions/communication/serial/availableforwrite/ availableForWrite Get the number of bytes (characters) available for writing in the serial buffer ...
Juraj's user avatar
  • 18.1k
2 votes

Connecting arduino with MATLAB

Using clear command on Octave before executing a=arduino('COM8') will remove this problem. Use it like this: clear a=arduino('COM8')
user12345's user avatar
2 votes

Interfacing MPU6050 with Arduino through Simulink S-function

To add to the answer above, you are limited by the serial speed of the USB, i.e. USB 2.0 is around 12 Mbps, as well as what your hardware can manage. Also, Simulink uses about 25% of each time step ...
Shaun Rance's user avatar
2 votes

about receiving float on matlab from ATmega32 Avr

i found the solution for this problem, i set a header before sending the data from ATmega32,and on Matlab i check the frame ,if it received correctly,i receive the data //ATmega32 code float x =...
mohamed's user avatar
  • 75
2 votes

Problem on Sending float number and multiple float numbers

Sending numerical values between systems is fraught with difficulty. Not only do you have to ensure that both ends agree on the size of the data (16 bit vs 32 bit ints, float vs double, etc) but that ...
Majenko's user avatar
  • 105k
2 votes

MATLAB - Read from 2 SPI inputs synchronously

Yes and No. Synchronously in development slang means step-by-step execution. Asyncronously mean by some event. Arduino has only one core. Even if you use interrupt, Arduino can only execute one ...
Serg Kryvonos's user avatar
1 vote

Updating the firmware of Arduino Mega2560

https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html This link has the instructions for connecting the Arduino board. Look right at the first where it ...
Delta_G's user avatar
  • 3,270
1 vote

How to program an Arduino Uno to collect data using a timer interrupt and analyze that data in matlab?

I've configured the timer differently making use of its UserData property. The timer will update the data every fixed period for a specified number of samples. close all; clear all; % Some useful ...
tim's user avatar
  • 699
1 vote
Accepted

Taking data from main 120V 50/60Hz power

The Serial output on an Arduino is quite slow. By printing your output, you will slow down the readings so much that it will appear to be nonsense. You should collect a series of readings into a C ...
Duncan C's user avatar
  • 5,682
1 vote
Accepted

Variable sets to 32767 - MATLAB Arduino

Some findings: Your for loop iterates over 71 results, but your array has only the length 70. You may overwrite variables in the memory behind the array. You can use else instead of else if (i >=...
Peter Paul Kiefer's user avatar
1 vote
Accepted

Interfacing MPU6050 with Arduino through Simulink S-function

Measurement sometime lost due to serial communications between Arduino and Simulink. So raw data have some glitches in output values. In order to solve the issue, we have to use state estimation to ...
Danish_Anwar's user avatar
1 vote

GUI interface with microcontroller to control a device through SPI

I grappled with the same question for a while. Here is how I solved the issue. 1- Find a suitable exchange format and protocol Here you need to decide what is the most important thing on the ...
Luiz Menezes's user avatar
1 vote

Arduino and MatLab with OWI Robotic Arm Edge -- Issue with I2C

The documentation in MATLAB for scanI2CBus() notes that the return is a cell array of character vectors They even give the example: a = arduino('COM9'); scanI2CBus(a,1) with result: ans = ...
jose can u c's user avatar
  • 6,974
1 vote

Sidestep one second log rate with NeoGPS when another sensor on the board need to log faster

Ok, I won't recreate your whole code, but here is a logic snippet that you can use. Let's suppose that you have 2 sensors, sensor1 and sensor2. sensor1 is read every 10 milliseconds and sensor2 is ...
Dat Ha's user avatar
  • 2,913
1 vote

Arduino Mega 2650 + Matlab/Simulink - Serial decimation

I don't think there will be a problem in this. I do not understand exactly why you can only send signals every 0.010 s. The board runs at 16 MHz, that's 16 million cycles per second, however, every '...
Michel Keijzers's user avatar
1 vote

MATLAB+Arduino+LCD

while answer fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); % ask user to enter value for ...
dda's user avatar
  • 1,588
1 vote

MATLAB+Arduino+LCD

You can use Matlab's Arduino support package, it allows you to control the Arduino directly without having to write code in the Arduino IDE. I never used it with an LCD though. Here is a link that ...
Isra's user avatar
  • 95
1 vote
Accepted

clear Arduino as a global variable in Matlab

In the MatLab Help Center they had nice description of how to clear a variable from memory. Check it here: https://www.mathworks.com/help/matlab/ref/clearvars.html In your case should be: clearvars -...
Niki Dimitrov's user avatar
1 vote

MatLab connection to Arduino using Bluetooth

As discussed in the comments, the "problem" seemed to be Matlab adding a "New Line" which is a decimal 10 in ASCII. asciitable.com Decimal 10 is the ASCII code for a "New Line" so it appears your ...
aaa's user avatar
  • 2,695
1 vote

Employing C++ code for Arduino

As the arduino "language" is C and C++ therefore it is possible to program an Arduino in C++/c. I need a maker file and a compiler. However my question is that isn't there a more non-programmer ...
Nick Gammon's user avatar
  • 38.2k
1 vote

MATLAB - Read from 2 SPI inputs synchronously

Truly parallel sampling is rarely needed. Especially if you can separate the triggering (latching) of a reading in the peripheral from the act of subsequently transferring the latched value over SPI, ...
Chris Stratton's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible