Simulink Arduino Analog Input does not work

31 vues (au cours des 30 derniers jours)
José Antonio González Prieto
Commenté : Omar le 16 Nov 2024 à 9:32
Hi
I',m trying to read Arduino analog input from Maltab/Simulink but nothing seem to work. I have a power source contected to A0 analog input sending a step signal with 0.5 Hz and 1 V, and a basic simulink with a Arduino Analog input read and a scope to visualize results. The problem is that the analog input readed in Simulin is always zero.
Documentation about this is very dificult to find (one of the big problems of Matlab is this type of lacks in their documentation and with very few support in the forums). Any idea about how to solve thiss?
Thanks in advance

Réponses (1)

Gandham Heamanth
Gandham Heamanth le 6 Juil 2023
If you're experiencing issues with reading Arduino analog input from MATLAB/Simulink, there are a few things you can check and try to resolve the problem:
1. Make sure you have properly connected the Arduino board to your computer and selected the correct board and port in MATLAB/Simulink. You can use the `arduino` function in MATLAB to create an Arduino object and verify the connection status. For example:
a = arduino();
This should create an Arduino object `a` and display the board information if the connection is successful.
2. Check the pin configuration in your Simulink model. Make sure you have selected the correct pin number for the analog input read block. The pin number should correspond to the analog input pin on your Arduino board where the signal is connected (e.g., A0).
3. Verify that the Arduino board is properly receiving the input signal. You can use the Arduino IDE or write a simple Arduino sketch to read the analog input and print the values to the serial monitor. This will help ensure that the Arduino board is functioning correctly and receiving the input signal.
4. Check the sample time settings in your Simulink model. Make sure the sample time is set appropriately to capture the analog input signal. You can adjust the sample time in the block parameters of the analog input read block.
5. Ensure that you have the necessary support packages installed in MATLAB/Simulink. You can check the "Add-Ons" menu in MATLAB to verify if the Arduino support package is installed. If not, you can install it from the Add-Ons menu or using the MATLAB Support Package Installer.
6. If you're still facing issues, try restarting MATLAB and reconnecting the Arduino board to your computer. Sometimes, restarting the software and reconnecting the hardware can resolve communication problems.
If none of these steps resolve the issue, it might be helpful to provide more details about your setup, including the version of MATLAB, the Arduino board model, and the specific Simulink model you're using. This additional information can assist in troubleshooting the problem further.
  2 commentaires
José Antonio González Prieto
Modifié(e) : José Antonio González Prieto le 11 Juil 2023
Hi
As part of my test, I used a Matlab 2021b script to control the charge of a capacitor using a PWM pulse. The results of the test (including a step input as well as a sinusoidal input) are correct.
By testing the same system from Simulink, observing the results in a Scope, I am able to verify that the input reproduces the input signal well, however at the output I always read the maximum value (1023). In order to make the code run correctly on the Arduino system, I have made sure that it runs in real (paced?) time.
Omar
Omar le 16 Nov 2024 à 9:32
I'm having the same problem..did you ever figure out a solution?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by