File Exchange

image thumbnail

Rensselaer Arduino Support Package Library (RASPLib)

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


Updated 30 May 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 (2019). Rensselaer Arduino Support Package Library (RASPLib) (, GitHub. Retrieved .

Comments and Ratings (41)

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



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


Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor