A Simulink Arduino toolbox with blocks for: quadrature encoder, compass/magnetometer, barometer, temperature, accelerometer, gyroscope, ultrasonic, driver amplifier (DC motor driver), and simple serial communication and plotting tools.
Supported I2C Sensors: MPU6050, MPU9250, HMC5883, BMP180, BMP280, MS5611, BMI160 (commonly found on GY-521, GY-271, GY-91, GY-87), HC-SR04, VL53L0X, QMC5883.
Examples are provided for basic hardware IO, step response and closed loop control of an Lego NXT motor.
Download includes basic curriculum labs describing the following:
- Simulink Arduino Intro Blinking LED
- RASPlib Installation Instructions
- Analog and Encoder input, and PWM output
- Gyroscope Reading and Calibrating
- Magnetometer - Making a Compass
- Serial Communication Basics
- Bluetooth Communication
- DC Motor Step Response
- Realistic DC Motor Simulation
- Basic DC Motor Control
- Realistic PI Controller Simulation
- DC Motor Parameter ID
- DC Motor Control with Full State Feedback and LQR
- Determining Angle with Complementary Filter
- Basic Balancing Lab
- Ultrasonic Distance Sensor
- Solving ODEs with MATLAB and Simulink
Labs are draft labs. Please contact with suggestions or help before leaving negative feedback.
Tested Matlab Versions 2015a-2020a. Support for Mega, Nano and Uno. Not tested or expected to work with Due without modification.
We highly recommend 2015a 32 bit for the best user experience. It is the fastest for compile and connection times and it the most tested version. 2020a also highly recommended.
Joshua Hurst (2021). Rensselaer Arduino Support Package Library (RASPLib) (https://github.com/hurstj01/RASPLib), GitHub. Retrieved .
2020a is supported. Send me an email if you need help with other issues. firstname.lastname@example.org Josh
Can this lib work with newer versions of Matlab(2020a) ?
Have you completed all the steps in Labs 1 and 1a included in the download? Please send me an email if you have and are still having trouble. email@example.com Josh
Hi Joshua, I have this model error Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot". could you help me?
Hey, I need the library for MATLAB 2014a version, could you help me please?
What if I want to use the RASPLib library for arduino Due? Could you please help me?
Can you help me with this error? I have completed biul, but cannot run. Although my MPU6050 is connected
Error occurred while executing External Mode MEX-file 'ext_comm':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Hello! Send me an email and I will help you with the error. firstname.lastname@example.org Josh
Hi, ive downloaded the library and have the block in a red discontiune line with SYSTEM NOT FOUND message. :(
It does, tit has been tested on 2019b and 2020a.
Does this work for Matlab 2019??
I think there is a version of MATLAB where this is an issue: Send me an email with your version and I can try to figure this out: email@example.com
I have the same trouble:
### Build procedure for model: 'Demo_MinSegMega_V3' aborted due to an error.
Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot"
· This only happens when working with HCSR04
hi Joshua, i have this model error Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot". could you help me? I have followed the installation instructions in README.txt and labs 1 and 1a.
Hello. This usually means you are using normal mode, or just deploying to hardware in stead of using external mode (look through lab 1). Send me an email with additional information and I can help out: firstname.lastname@example.org
hi mman, i need to use this sensor VL53L0X (a need the value of the mesure to make a control system in simulink) , i just instal this library, an use the block on simulink but the mesure that gives me is always 0. what can i do? can you help me
No solutions, my guy. Take fire on this shitttttt
Hello! Tentatively - Yes. I download and ran a couple demos and it went fine. I have not tested all the files yet, but I think it should be OK. Once I have tested more extensively I will update the file information, but for now it should be OK to try. Let me know if you have any issues! Josh
Hi Joshua, Is this library compatible with the 2019b version?
There are different Magnetic levitation kits that have been used. For our base controller design was with a coil with R=3.4 ohm, L=15mH. Most kits have coils with much larger resistance, but we were able to use the same controller design. You can easily measure the coil resistance, and this inductance value should get your controller close.
Hello Joshua, I am a student who's doing a project on how to design and implement control algorithms in the MagLev device. Do you know the values of the coil inductance and resistance so I can analyze the system? Thank you.
Be sure to follow the installation instructions in README.txt and labs 1 and 1a . If you still need help send me an email at email@example.com
hi Joshua, i have this model error Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot". could you help me?
Hi Joshua, I am struggling with VCNL4010 proximity sensor and PCA9548A multiplexer. Could you help me to build S-Function block to work on Simulink? Thank you so much.
Hello and thanks! I have used this with many 9250's with the magnetometer working. Send me an email with additional information and some pictures of your setup and I can help out: firstname.lastname@example.org
First I would like to thank you for the amazing work.
I have been following all the labs and learning a lot from that.
Only one question, I have noticed that the Magnetometer for the MPU9250 is not working. It looks like the files MPU9250.h and MPU9250.cpp are not configurated for the magnetometer. Are you planning to do any update about that?
Have you looked at the labs in this download? There is a lab for parameter ID, some modeling, and a balance lab.
For the other error can you send me an email to email@example.com and I will help you
Hello~ I am doing the Minseg project where the M1V4 is used and the board is Mpu6050. And I want to ask that do you know the nonlinear model of the inverted pendulum robot Minseg on the Minseg website is correct or not? And also do you know the parameters like resistence of the robot and other things? Another serious problem is when I use the simulink block which is in the Demo M1V4, there will be an error which is the lost of connection every time I use the pin 5. Can you help me with these problems? Thank you very much!
This library is only tested with Mega, Nano and Uno. For Due you would have to modify the code for the Due libraries and pins. I have updated the description with this information. Thanks!
i work with arduino due and i need to read postion from encoder ,which bloc of encoder i choose .
The home MATLAB directory is where MATLAB starts by default. In a windows machine it will be something like: C:\Users\hurstj\Documents\MATLAB MATLAB includes this directory in its search path and if startup.m is in there will add the necessary directories for the library to its search path. README.txt and labs 1 and 1a go over the installation of the components you need before you install RASPLib. You may be missing the Arduino support package for Simulink. I'm not familiar with the installation on a MAC, so if these steps do not work you may want to reach out to Mathworks technical support.
I am trying to install this package on a mac. After I unzip the folder and copy the RASPLib and startup.m file, where do I paste it? I have tried multiple directories but I can't access the simulink blocks associated with this support package. How do I find the home directory on a mac?
Use this command at the MATLAB command line to find out where arduino files are installed:
[~, hardwaredir] = codertarget.arduinobase.internal.getArduinoIDERoot('hardware')
then navigate to 'arduino\avr\cores\arduino' and you should find Tone.cpp in there.
Edit Tone.cpp: search for the line "#ifdef USE_TIMER2" which for my file is located on linen 537 and modify this line to "#ifdef USE_TIMER2_disable" (just append _disable to the end of the line)
Which will prevent it from running the code defining timer 2 interrupt since 'USE_TIMER2_disable' is never defined.
Note: this will affect any code that uses timer 2! so modify at your own risk!
'- Added functionality to 3 ultrasonic sensors. Code works by modifying Tone.cpp to not use Timer 2 ISR so ultrasonic library can be used'
Can you elaborate on how exactly to do this? where is this tone.cpp file located? how to modify it?
I2C sensors need 4 wires, power, ground, SCL, and SDA.
Joshua Hurst, I'm going to be using your support package to run the accelerometer and gyroscopic sensor on an MPU-6050. I can't seem to find any instruction on wiring it to my mega 2560. I know of course the voltage source and ground, and I'm guessing the SCL and SDA pins go to the SCL and SDA communication pins on the arduino, but are there any other connections needed to get the sensors working? Thanks!
- Added support for ultrasonic sensor up to 2018a
- Added functionality to 3 ultrasonic sensors. Code works by modifying Tone.cpp to not use Timer 2 ISR so ultrasonic library can be used
Joshua Hurst, i`m using your support package to run Ultrasonic Distance Sensor. what if i`m using 2 unit of it? if i`m not mistaken, that support package only support for one unit. please help..
2018a now supported, in addition:
- added support for BMI160 Gyroscope Accelerometer (BMI160 seems to be more robust to noise than MPU6050)
- added serial plot for multiple channels (useful for boards without external mode like nano)
I have fixed this for 2018a, but had not had the time to test it extensively yet. If you would like to test this release before it posted send me an email: firstname.lastname@example.org and I will help you.
This toolbox work fine with Matlab 2015a and my Arduino device, it's very useful. Since march 2018, my coworker team want to install and use Matlab 2018 a for other purposes (Simscape).
When I try to install your package with Matlab 2018, there is no problem but when I want to use it, the accelerometer, barometer and MPU 9250 blocks appears with "system not found" in red. When I try to use this block, I have this error in the diagnostic viewer :"Incorrect definition of setupImpl in soMPU9250. setupImpl can have at most 0 input(s) because stepImpl defines 0 input(s) (in addition to System object)."
Can you help me ?
I have a matlab 2017a and I work with arduino. When I try to run the simulink in external mode, I receive the error message "### Unable to generate all binary outputs
can help me?
This error is usually a result of: 1.) not installing the Arduino Support package 2.) not installing a compiler properly 3.) not installing the RASPLib folder and the startup.m file in the correct location. All the steps are outlined in labs 1 Simulink Arduino installation PDF and 1a RASPLib installation PDF. If you have followed the steps in labs 1 and 1a PDFs and still have this error please send me an email email@example.com and I will help you.
When try to run this in external mode I get the error message "### Failed to generate all binary outputs." The error message says it's looking for something called "stream.h". Any idea why that would be?
Thanks. email has been sent.
send me an email: firstname.lastname@example.org and I will help you
Hi Joshua Hurst
why when I use Gyro block in the same Simulink model with Accelero block or Barometer block the plot of Gyro become undesirable. but when i use it alone it is ok as explained in the tutorial.
BMP180 is supported. The image file was old. The image file has been updated.
why BMP180 block is not shown in the library?
send me an email: email@example.com and I will help you
At the end of running everything in simulink external mode I get this error:
### Failed to generate all binary outputs.
What could be happening, thanks for your answers.
The ultrasonic sensor is not supported by default after 2015b since the compilation libraries for Arduino changed. There is a workaround you can try. If you open the file "soHCSR04Sonar.m" you will see some instructions that will exclude Tone.cpp from the build path allowing compilation of the current block.
Hi! I have tried ultrasonic distance sensor in Simulink and it is doesn't work. My version is 2017 b and Simulink show me this:
MATLAB\Add-Ons\Toolboxes\HC-SR04 Add-On Library for Arduino\code\sensor_ert_rtw>echo The make command returned an error of 2
"An_error_occurred_during_the_call_to_make" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
### Build procedure for model: 'sensor' aborted due to an error.
Error:Error(s) encountered while building "sensor":
### Failed to generate all binary outputs.
Someone know why happen this?
Sorry for telling now but my Matlab is 2017 b. Maybe it is for that
Very good! Thanks!
Inspired by: Device Drivers
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!