HC-SR04 Add-On Library for Arduino not working

4 次查看(过去 30 天)
I am using MATLAB 2018a. I have followed all the instructions mentioned in https://in.mathworks.com/matlabcentral/fileexchange/57898-hc-sr04-add-on-library-for-arduino
I have even downloaded the zip file, renamed it to 'Ultrasonic' and put it in "My Documents\Arduino\libraries\"
However, when I run the command "arduino('COM8', 'Uno', 'Libraries', 'JRodrigoTech/HCSR04')", I get the error "Cannot program board Uno (COM8). Please make sure the board is supported and the port and board type are correct. For more information, see Arduino Hardware Troubleshooting."
But when I just run the arduino() command in the command window, I get the required object
Port: 'COM8'
Board: 'Uno'
AvailablePins: {'D2-D13', 'A0-A5'}
Libraries: {'I2C', 'Servo', 'SPI'}
Can someone please help me with this?

回答(2 个)

Madhu Govindarajan
Madhu Govindarajan 2018-4-17
For these addons to work there are two requirements -
1) You place the 3P libraries in the accurate folder - C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\arduinoide.instrset\arduino-1.8.1\libraries
If you did not install your support package in the default - C:\ProgramData\MATLAB\SupportPackages\R2018a\ then you can find out where it is located by typing the following command in MATLAB.
>> matlabshared.supportpkg.getSupportPackageRoot
Here, confirm that you are placing the 3P libraries in one direct folder. Example - sometimes it gets located inside /libraries/UltraSonic/UltraSonic and this can cause issues as the HCSR04.m file is looking at /libraries/UltraSonic folder.
2) Make sure that the downloaded zip file is on MATLAB path and that you have not renamed the +arduinoioaddons,+JRodrigoTech folders.
Once you have both of these, if you type the following in MATLAB Command Window
>> listArduinoLibraries
This should show your library. If it does not please post the output for others to help.
Madhu
PS - If this works, please accept the answer. I say this because this is a commonly asked question for 3P addons, and I want to see if this solution works universally for all addons.
  2 个评论
Vinesh Appu
Vinesh Appu 2020-8-29
Hi, i did what ever you told but i am getting error
"Cannot program board Uno (COM9). Please make sure the board is supported and the port and board type are
correct. For more information, see Arduino Hardware Troubleshooting."
please help me

请先登录,再进行评论。


Kohl Fritschen
Kohl Fritschen 2019-5-3
Adding the JRodrigoTech/HCSR04 addon file to the C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset path allowed my arduino Uno to recognize the library and create the object
a = arduino('COM3', 'Uno', 'Libraries', 'JRodrigoTech/HCSR04')

Community Treasure Hunt

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

Start Hunting!

Translated by