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.
Joshua Hurst (2019). Rensselaer Arduino Support Package Library (RASPLib) (https://www.github.com/hurstj01/RASPLib), GitHub. Retrieved .
1.32 | Updated M2V5 and MinSegNano Demo Files |
|
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
|
|
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)
|
|
1.1.0.0 | updated image file |
|
1.1.0.0 | added:
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 |
Inspired by: Device Drivers
Create scripts with code, output, and formatted text in a single executable document.
Bruno Lima (view profile)
No solutions, my guy. Take fire on this shitttttt
Joshua Hurst (view profile)
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
José Ignacio González Angarita (view profile)
Hi Joshua, Is this library compatible with the 2019b version?
Joshua Hurst (view profile)
Hello,
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.
Enrique Hidalgo (view profile)
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 (view profile)
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 joshua.hurst.rpi@gmail.com
Angela Rendon (view profile)
hi Joshua, i have this model error Undefined variable "realtime" or class "realtime.internal.getArduinoIDERoot". could you help me?
Daniel Renjewski (view profile)
Quan Nguyen (view profile)
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 (view profile)
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
Gabriel Giannini (view profile)
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 (view profile)
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 (view profile)
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 (view profile)
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!
hichem belhadj chikh (view profile)
i work with arduino due and i need to read postion from encoder ,which bloc of encoder i choose .
Daniel Doscher (view profile)
Joshua Hurst (view profile)
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 (view profile)
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 (view profile)
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 (view profile)
Juan Andrés Martin (view profile)
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 (view profile)
I2C sensors need 4 wires, power, ground, SCL, and SDA.
John Kempf (view profile)
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 (view profile)
Joshua Hurst (view profile)
- 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
Mohd Azri Abd Mutalib (view profile)
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 (view profile)
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 (view profile)
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.
Elric Thomas (view profile)
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 (view profile)
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 (view profile)
Zakarya Motea (view profile)
Joshua Hurst (view profile)
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.
John Stricker (view profile)
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
Zakarya Motea (view profile)
Thanks. email has been sent.
Joshua Hurst (view profile)
send me an email: joshua.hurst.rpi@gmail.com and I will help you
Zakarya Motea (view profile)
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 (view profile)
mike (view profile)
Joshua Hurst (view profile)
BMP180 is supported. The image file was old. The image file has been updated.
Saeed Ahmed (view profile)
why BMP180 block is not shown in the library?
Joshua Hurst (view profile)
send me an email: joshua.hurst.rpi@gmail.com and I will help you
vladimir so (view profile)
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.
Jacob Blaustein (view profile)
Joshua Hurst (view profile)
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 (view profile)
Ivan Dominguez (view profile)
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!
Ivan Dominguez (view profile)
Sorry for telling now but my Matlab is 2017 b. Maybe it is for that
Guolong Jiang (view profile)
Very good! Thanks!
Ramon Angel (view profile)
Qiao Chen (view profile)
N Kando (view profile)
Davide Marzatico (view profile)
jeerawat pokanit (view profile)