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

202 Downloads

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) (https://www.github.com/hurstj01/RASPLib), GitHub. Retrieved .

Comments and Ratings (46)

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: joshua.hurst.rpi@gmail.com

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

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 joshua.hurst.rpi@gmail.com 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.

hasan223

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

Sure:

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:
C:\ProgramData\MATLAB\SupportPackages\R2017b\3P.instrset\arduinoide.instrset\arduino-1.8.1\hardware\arduino\avr\cores\arduino\Tone.cpp

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!

dgmcik

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!

TNagy

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: joshua.hurst.rpi@gmail.com and I will help you.

Hello,
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

Hello,
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 joshua.hurst.rpi@gmail.com and I will help you.

Hi,
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

Thanks. email has been sent.

Joshua Hurst

send me an email: joshua.hurst.rpi@gmail.com 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

mike

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: joshua.hurst.rpi@gmail.com 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.

dgmcik

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
\code\sensor_ert_rtw>An_error_occurred_during_the_call_to_make
"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?

Thanks!

Sorry for telling now but my Matlab is 2017 b. Maybe it is for that

Very good! Thanks!

Ramon Angel

Qiao Chen

N Kando

Updates

1.3

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.

1.2.4.3

Bug fix for 2015a serial plot

1.2.4.2

formatting update

1.2.4.1

updated description to recommend 2015a

1.2.4.0

Data sync improvements for serial plotting of with multiple channels

1.2.3.0

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

1.2.1.0

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

1.2.0.0

- 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

1.1.0.0

updated image file

1.1.0.0

added:
- 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

1.0.0.0

minor edits

1.0.0.0

minor edits

1.0.0.0

minor updates

1.0.0.0

added library image

1.0.0.0

minor edit

1.0.0.0

minor edit

1.0.0.0

minor formatting updates

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

Inspired by: Device Drivers

Communities