File Exchange

image thumbnail

Raspberry Pi DC Motor H-Bridge Driver Block SFunction

version (19.2 KB) by Joshua Hurst
DC Motor Driver Block using Soft PWM of WiringPi Library


Updated 22 Aug 2014

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Motor Driver Block using Soft PWM of WiringPi Library.
This block controls both the magnitude and direction of a DC motor with an H-bridge such as the DRV8833 or the SN754410 using Soft PWM of the WiringPi library.

The reference zero speed is set with high voltage at both motor terminals (both PWM signals at full duty cycle). For the DRV8833 driver this creates a highly linear response and eliminates the typical dead band around zero speed. This increases motor response but may have a larger power draw (this has not been measured).

More information can be found at our website, along with other device drivers:

A complete Arduino library and curriculum is available here:

Other driver blocks on the way:
- Quadrature encoder
- MPU6050

Stay tuned!

This development is part of the Mechatronics curriculum at Rensselaer Polytechnic University

Cite As

Joshua Hurst (2021). Raspberry Pi DC Motor H-Bridge Driver Block SFunction (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Nimra Zeeshan

Guimin Long

Arnaud Villeneuve

Murat Belge

@Marco: The H-bridge driver is looking for an installation of wiringPi library under /home/pi/wiringPi directory. The wiringPi installation has been moved to /opt/wiringPi directory in the latest Linux image for Raspberry Pi. Create a symbolic link to /opt/wiringPi library by executing the following on your Raspberry Pi:

# ln -s /opt/wiringPi /home/pi/wiringPi

This should resolve the build issue.


Hi Joshua,

when I try to download the model to raspberry I receive this error:

The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
Error executing SSH command: make: Entering directory `/home/pi/DC_Motor_Driver_Block_RPi_rtt'
"gcc" -I"


fatal error: /home/pi/wiringPi/wiringPi/gertboard.h: No such file or directory

What am I missing?




James - did you press build in the s-function windows?


I receive the following error when I try to run the Simulink model:

Error in S-function 'DC_Motor_Driver_Block_RPi/Volts To RPi PWM 754410 or DRV8833 PWM High is zero speed/Include WiringPi Libraries': S-Function 'Include_WiringPi' does not exist

I am using R2013b and applied the bug fix that is described in the Device Drivers article by Giampero Campa. Thanks in advance for your help.

Paul Kassebaum

Michael Lundgren

Just what I have been searching for. Good job.

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Device Drivers


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!