Best method to run MATLAB code on a Teensy

Status
Not open for further replies.

kdharbert

Well-known member
I have a Teensy piping sensor data to MATLAB. The Teensy has enough processing power to handle the sensor processing, so I want to use MATLAB to generate the processing code and then port the code to Teensy. MATLAB has built-in features for this, but they take over the programming entirely and won't work for a Teensy. Is there a good way to run C code exported from MATLAB on a Teensy?
 
You might want to read this response on the matlab forum: https://www.mathworks.com/matlabcentral/answers/517717-support-teensy-hardware

If you wish to create your own custom target, you can refer to the tutorial below. Note that it would require Embedded Coder.
https://www.mathworks.com/videos/se...-cortex-a-based-hardware-platform-121440.html

You could try just copying the c code to the IDE and try compiling it but you may run into porting issues. Not 100% sure as I never tried it.
 
You could write your Matlab code and use the code generation tool provided by Matlab to generate c or c++ code automatically. Maybe some particular settings are necessary before generating the code.
I already made something similar before. I had to implemented a Kalman filter for control purposes. I created a Matlab class with the necessary matrix multiplications etc., and thus converted the class with code generation to give a c++ class, which can be simply used in the teensy code. Result and performance were pretty good.
If intersted, I can give you much more details.
 
For my Teensy-based flight control system, we use Simulink to generate C++ code using Embedded Coder. Our build system pulls that in with a modified version of the Teensy core and low level drivers to build and upload the executable. The software can be found here, feel free to ask if you have any questions:
https://github.com/bolderflight/spaaro
 
Status
Not open for further replies.
Back
Top