MATLAB Answers

0

Error when using HCSR04 example

Asked by Joseph Stout Fay on 8 Nov 2016
Latest activity Answered by ibra
on 1 Apr 2019
Using the HCSR04Example.m file only edited for the pins I am using on my Arduino Uno and COM3 instead of COM38 with Arduino hardware support and HC-SR04 Add-On Library for Arduino. I keep getting the error:
>> HCSR04Example
Updating server code on board Uno (COM3). Please wait.
Error using HCSR04Example (line 25)
The Arduino source 'Ultrasonic/Ultrasonic.h' for libraries 'JRodrigoTech/HCSR04' cannot be found. Install the 3P library source first and try again.
Have I not installed an add-on or not taken something else into account?

  0 Comments

Sign in to comment.

4 Answers

Answer by ameya umrani on 23 Feb 2018

Even after installing the necessary libraries the error "The Arduino source 'Ultrasonic/Ultrasonic.h' for libraries 'JRodrigoTech/HCSR04' cannot be found. Install the 3P library source first and try again "still exists

  0 Comments

Sign in to comment.


Answer by Hari Desanur on 14 Nov 2016

Note that the HCSR04Example.m from the 'HC-SR04 Add-On Library for Arduino' requires MATLAB R2016a or higher and MATLAB Support Package for Arduino Hardware.
Make sure that the Arduino Support Package is installed correctly by running this command -
>> matlabshared.supportpkg.getInstalled
Ensure that you have followed the installation steps mentioned in this link such as renaming the unzipped folder to ‘Ultrasonic’.
Check if MATLAB is able to detect the add-on library by executing the "listArduinoLibraries" command. You may have to restart MATLAB after installing this library.

  3 Comments

How can we use sonar sensors in earlier version of matlab. am using matlab 2015a. am using HC-sr04 and a UNo board
The sensor library doesnt work with 2015 version. It strongly recommends to use 2016 or higher version.

Sign in to comment.


Answer by Arpita Agrawal on 23 Feb 2018

Hi Ameya,
Please ensure that you have installed the 3P library of the Ultrasonic sensor from https://github.com/JRodrigoTech/Ultrasonic-HC-SR04/archive/master.zip
Refer to instruction on the doc page https://in.mathworks.com/matlabcentral/fileexchange/57898-hc-sr04-add-on-library-for-arduino to install this library.
Thanks Arpita

  2 Comments

Actually did all the steps mentioned. Still the problem remains. I can also see the HCSRO4 in the list of avaiable libraries but, when given the command a = arduino('COM4', 'Uno', 'Libraries', 'JRodrigoTech/HCSR04'); it says it is missing a Ultrasonic.h file which i can see in the library. i also checked for the path but all seems fine to me
Hi Ameya,
Please contact MathWorks Technical Support, they will work with you to resolve this issue.
Thanks Arpita

Sign in to comment.


Answer by ibra
on 1 Apr 2019

First download the file from this link
there is another file in the describtion, download it and put it in the arduino file in matlab
C:\ProgramData\MATLAB\SupportPackages\R2016b\3P.instrset\arduinoide.instrset\arduino-1.6.13/libraries
or type arduinoio.IDERoot in command window to see the directory of the file
if you get this error:
Cannot program board Uno (COMX). Please make sure the board is supported and the port and
board type are correct.
then rename the Arduino folder in Documents into anything else. and open the arduino.exe
from this folder (C:\ProgramData\MATLAB\SupportPackages\R2016b\3P.instrset\arduinoide.instrset\arduino-1.6.13/libraries)
you'll get this message "The sketchbook folder no longer exists. Arduino will switch to the default sketchbook location , and create a new sketchbook folder if necessary. Arduino will then stop talking about himself in the third person."
also it will help if you run matlab as an administrator

  0 Comments

Sign in to comment.