Code covered by the BSD License  

Highlights from
RC Receive Driver Block for Arduino

4.33333
4.3 | 4 ratings Rate this file 70 Downloads (last 30 days) File Size: 40.1 KB File ID: #45541 Version: 1.4
image thumbnail

RC Receive Driver Block for Arduino

by

 

13 Feb 2014 (Updated )

Control an Arduino robot using an RC Transmitter and Receiver with Simulink

| Watch this File

File Information
Description

With this block, a user can use Simulink to generate code for an Arduino which receives signals from an an RC Transmitter.
When the output of an RC Receiver is connected to an Arduino, this custom driver block outputs the length of the RC signal's pulse in microseconds, which corresponds directly to the signal's value.
 
This material is meant to support the MakerZone article "How to use an RC Controller with Arduino and Simulink".
 
http://makerzone.mathworks.com/resources/how-to-use-an-rc-controller-with-arduino-and-simulink/
 
This driver block was tested with the Cirrus-DPR-4FM Transmitter and Receiver. All Receivers output servo protocol so the block will work with all RC Transmitter/Receivers.
 
The block works with the Arduino Uno, Mega 2560, and Due.

Acknowledgements

Device Drivers inspired this file.

Required Products Simulink
MATLAB
MATLAB release MATLAB 8.3 (R2014a)
Other requirements Compiler must be installed for your OS and version of MATLAB; http://www.mathworks.com/support/compilers/R2013b/ The Arduino Support Package must be installed which can be found by typing >> targetinstaller at the MATLAB Command Window.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
12 Mar 2015 Sergio Biagioni

Hi Sean,
Great to hear. Since you are using the Arduino Uno, you should specify only two pins in the block, 2 and 3.

Best,
Sergio

Comment only
12 Mar 2015 sean cleary

Hey Sergio,

Thanks for your help previously, all working fine now.

Just wondering, I'm going to use an arduino uno with this block which only has 2 pins available compared to the 4 for the arduino mega. If I use just 2 pins, do I need to modify the code at all? should i just input 2 pins or input 4 pins(where the last 2 are random)

Thanks,
Sean

07 Mar 2015 sean cleary

Thanks very much for that Sergio

Comment only
06 Mar 2015 Sergio Biagioni

Hi Sean,
Windows SDK 7.1 should work for Windows XP Service Pack 3. If you can't get it to work, any other MathWorks Supported Compiler will work.

You can find the list of supported compilers for R2014b here:
http://www.mathworks.com/support/compilers/R2014b/index.html

The list of supported compilers depends on the version of MATLAB you are using, your OS (32 or 64-bit windows), and whether you are using it for MATLAB or Simulink. In this case, you are using it for Simulink.

Let me know if you can't find a suitable compiler for your configuration and we will find a solution.

Best,
Sergio

Comment only
06 Mar 2015 sean cleary

Hi Sergio,

Thanks very much for this.

Though I am stuck on windows XP at the moment and am having trouble getting Window SDK for it for use with the rc reciever block. Any advice*?

Cheers
Sean

29 Oct 2014 Sergio Biagioni

Hi Andrea,
You could just copy everything I did with channels 0-4 and expand necessary arrays. I would do it for you but I don't have a 6 channel tx/rx on hand at the moment to test. The specific steps are as follows;

1. Open RC Receive Driver Block
2. Change Data Properties->Output ports "Rows" to 6
3. In Libraries, change definition for rcc to:
volatile rcChannel rcc[6] = {{0,1,0,0}, {0,2,0,0}, {0,3,0,0}, {0,4,0,0}, {0,5,0,0}, {0,6,0,0}};
4. In Libraries, add void calc4 and calc5 interrupt service routines, just as calc0-4 were defined
5. In Outputs, change duration vector to the following:
static uint16_t duration[6] = {0,0,0,0,0,0};
6. In Outputs, add updateflag "if statements" for channels 4 and 5
7. In Outputs, add out[4] = duration[4] and out[5] = duration[5]
8. In Discrete Update, add attach interrupts for calc4 and calc5
9. Build the S-Function builder block
10. Run modify('sfcn_rcreceive')

Comment only
29 Oct 2014 Andrea

Andrea (view profile)

Great work Sergio! At now I'm working with four channels, how can I upgrade your block to six channels?

Sincerely,

Andrea

27 May 2014 Sergio Biagioni

The test model was built in R2013b. If you're using a previous version of MATLAB (i.e. R2013a), you could receive an error if you try to run the model in external mode.

Error Message Example:
Error occurred while executing External Mode MEX-file 'ext_comm':
Expected 1xN string array for host name

To resolve this, create a new model and copy the RC Receive block into it.

Enjoy!
Sergio

Comment only
19 May 2014 Akeel

Akeel (view profile)

 
Updates
05 Mar 2014 1.1

Removed mex files, updated required products.

07 Mar 2014 1.2

adjusted copyright

13 Mar 2014 1.3

Updated required toolboxes, only MATLAB and Simulink necessary.

13 Aug 2014 1.4

Added support for Arduino Due

Contact us