<< return to Pixycam.com

Simulink S-function for Reading Pixy Outputs in Arduino


I am trying to create an S-function in Simulink for reading the Pixy Outputs over SPI on the Arduino Uno.

The idea is to develop a control system on Simulink and run it on the Arduino. Pixy is my sensor and I need to develop a Simulink block to output the data in pixy.blocks[i].

I tried following this youtube video: https://www.youtube.com/watch?v=_OLctOFjjYQ and even though the code compiled and downloaded to the Arduino, there was no output when I ran the model in external mode.

Anyone has experience in this area?


Problem solved. If you are encountering similar issues:

  1. Copy all the files from the Pixy Arduino library to your Matlab working directory

  2. Copy SPI.h and SPI.cpp from your “Arduino install folder”\hardware\arduino\avr\libraries\SPI\src to your Matlab working directory

  3. Follow the procedure in the video I linked in my original post

  4. Stuff to include:
    #ifndef MATLAB_MEX_FILE
    #include <Arduino.h>
    #include “SPI.h”
    #include “SPI.cpp”
    #include “Pixy.h”
    Pixy pixy;

  5. Custom Start Code
    #ifndef MATLAB_MEX_FILE

  6. Output Function, edit as necessary to pull out whatever variables you need to the outputs of the S-function block
    #ifndef MATLAB_MEX_FILE
    uint16_t blocks;
    blocks = pixy.getBlocks();
    if (blocks){

else {