Interfacing MATLAB and Arduino

Hi friends!I have just found and tested a Blockset that interfaces MATLAB/SIMULINK and Arduino. You may find this at:http://www.mathworks.com/matlabcentral/fileexchange/24675-arduino-targetI highly suggest this program since it offers rapid prototyping capabilities to the famous and cheap arduino. The guys have build a block that interfaces with the Real Time Workshop of MATLAB and have also implemented C functions for all arduino operations (analog in, out, serial read/write etc.). Despite the fact that the code is obviously bigger one can gain advantage from the quick and abstract way of programming that simulink offers. It is a good work!Happy coding!
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Update for Future Viewers of this thread: The current release of Simulink has the Arduino Support Package built into it which means you don't need to grab the files from the File Exchange for basic functionality. All you need to do is MATLAB and Simulink, and then type >> targetinstaller at the MATLAB Command Window and it guides you through the setup process.

    If you're a student, you can purchase the Student Version. If you're not a student and are using it for personal use (non-commercial, non-academic), you can purchase MATLAB Home at a low price.

    @Christopher: Example Quadrature Encoder blocks are provided in the Device Driver guide in the File Exchange. The "Continuous Servo Write" block can be used with a motor controller which takes in servo protocol (i.e. ESC) to control DC motors. I have tried this and it works well. The trick is to make sure that the ground pin from the Arduino, the negative terminal on the Battery and the ESC ground input line are all connected together.

  • Has anyone been able to get the servo output block to work? How do you add it to the Arduino library? I can get the serial write and digital output (blink LED) working no problem. I am also looking for a PID model to use with my Arduino in Simulink. The goal is to read in wheel encoders (quadrature encoding) and output PWM to control DC motors to implement a cruise controller.
  • I think Arduino Target is very good start. Author Doug Eastman must be congratulated.

    Those who have formal/deeper understanding in flight control theory may use this tool in Matlab/Simulink to create better controller algorithms.

    According to the following figure

    arduinoShot.JPG

    the current version of Arduino Target only support analog and digital input/analog, serial read/write and serial config blocks. However, the ZIP file of the Arduino Target further contains a servo output block.

    It seems to be that Arduino Target does not support interrupts. May be someone with real experience on Arduino Target can correct me.

    I am looking forward to see people sharing their Matlab/Simulink based control applications.
  • It would be great if the same existed for Scilab ( http://www.scilab.org/ )
  • guys it is just straight forward, you install, you design on simulink and - if everything has gone well - you compile, build and download on arduino.
  • probably just simple 'include' would allow portions or all of the existing ardupilot code to be used, with autocoded parts hooked in. not sure till try it though, just suspect that's a way.
  • can get matlab for linux. but it's big $$$ regardless of os. can get a student version for cheap or free. the arduino tool is only tested / used so far in windows per the listing in mathworks exchange, but pretty sure no huge reason it shouldn't work in linux, the arduino ide does work in linux fine. go for it. if I get around to trying that, i would be using matlab on windows, so may as well flash straight from there.

    matlab real time workshop (RTW) is for autocoding, creating c or other code from graphical simulink and stateflow control models. make and test a control scheme or part of the code, or some fancy calculations, and mathworks creates the code for the target controller. good way to fill up an arduino, but the advantage is how easy it should be, once rtw is set up and working, very quick & easy to make things without typing out lots of code manually. If you're familiar with matlab simulink stateflow, it could be very handy. Otherwise, might do just as well writing code normal way, getting matlab and figuring it out would be a good investment, but could be a lot of time by itself.

    There's not anything to wire up differently, use the ftdi cable. Think must be able to use parts of program in c / arduino language, and other parts autocoded. Everytime you flash new program to arduino, you erase it, except leave the bootloader basic program still there.

    it looks like it piggybacks on the existing arduino ide. here's more description on it.
    GettingStarted.html

    Anyway, I think I may try this sometime. Thanks for finding this!
    there.it
    description
  • How do you wire up the Arduino and the MATLAB ? Is it with the FTDI cable ? Is there any Servo Output / PWM ? Do you need to erease the code in the Arduino to be able to use the MATLAB tool?
  • Doesn't work on OS X/Linux :(
This reply was deleted.