File Exchange

image thumbnail

Rensselaer Arduino Support Package Library (RASPLib)

version 1.32 (11 MB) by Joshua Hurst
Simulink sensor and motor driver library for Arduino


Updated 13 Oct 2019

GitHub view license on GitHub

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

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
- Determining Angle with Complementary Filter
- Basic Balancing Lab
- Ultrasonic Distance Sensor

Labs are draft labs. Please contact with suggestions or help before leaving negative feedback.

Tested Matlab Versions 2015a-2019a. 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.

Cite As

Joshua Hurst (2020). Rensselaer Arduino Support Package Library (RASPLib) (, GitHub. Retrieved .

Comments and Ratings (69)

Joshua Hurst

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. 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?

Hung SoM

What if I want to use the RASPLib library for arduino Due? Could you please help me?

Hung SoM

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.

Joshua Hurst

Hello! Send me an email and I will help you with the error. Josh

Hi, ive downloaded the library and have the block in a red discontiune line with SYSTEM NOT FOUND message. :(

Joshua Hurst

It does, tit has been tested on 2019b and 2020a.

Does this work for Matlab 2019??

Joshua Hurst

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:

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

Dimas SIlva

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.

Joshua Hurst

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:

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

Bruno Lima

No solutions, my guy. Take fire on this shitttttt

Joshua Hurst

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?

Joshua Hurst


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.

Joshua Hurst

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

hi Joshua, i have this model error Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot". could you help me?

Quan Nguyen

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.

Joshua Hurst

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:

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?

Joshua Hurst

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 and I will help you

ayong zheng

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!

Joshua Hurst

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 .

Joshua Hurst

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?
Many thanks!

Joshua Hurst


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.

For example:

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!


Hi Joshua

'- 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?

Thanks. Regards.
Juan A.

Joshua Hurst

I2C sensors need 4 wires, power, ground, SCL, and SDA.

John Kempf

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!


Joshua Hurst

- 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..

Joshua Hurst

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)

Joshua Hurst

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: 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 ?
Thank you.

chawki mey

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?

Kri Ratta

Joshua Hurst

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 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.

Joshua Hurst

send me an email: 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.

Saeed Ahmed


Joshua Hurst

BMP180 is supported. The image file was old. The image file has been updated.

Saeed Ahmed

why BMP180 block is not shown in the library?

Joshua Hurst

send me an email: and I will help you

vladimir so

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.

Joshua Hurst

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!

Ramon Angel

Qiao Chen

N Kando



Updated M2V5 and MinSegNano Demo Files


PWM frequency bug fix. Added support for MinSegMegaV3 and MinSegShield M2V5. Changed file naming convention for clarity. VL53L0X time-of-flight sensor support block added. Other minor fixes. Verified support with 2019a.

Bug fix for 2015a serial plot

formatting update

updated description to recommend 2015a

Data sync improvements for serial plotting of with multiple channels

- 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.

- Added a synchronization string to the SerialPlot block. This allows versions after 2017a to sync data sent to the serial line for plotting/saving data.

- 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)
- fixed system objects to be compatible with 2018a

updated image file

- PWM frequency selection blocks (for Magnetic Levitation kits)
- BMP180 barometer driver
- support MinSegNano, MinSegPro, and MinSegShield M1V5
- HCSR04 ultrasonic driver workaround for 2015b or later

minor bugs and fixes

minor edits

minor edits

minor updates

added library image

minor edit

minor edit

minor formatting updates

MATLAB Release Compatibility
Created with R2015a
Compatible with R2015a to R2019a
Platform Compatibility
Windows macOS Linux

Inspired by: Device Drivers