<< 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;
    #endif

  5. Custom Start Code
    #ifndef MATLAB_MEX_FILE
    pixy.init();
    #endif

  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){
    sig[0]=pixy.blocks[0].signature;
    }

else {
sig[0]=0;
}
#endif

1 Like

Hello,
I tried to follow your steps but it didn’t work. Can you please send my the model or can I send you my model so you can check it ?
Thank

Hey James,

sorry you’re having trouble! Can you say more about what you’re trying to do, and what issue you’re having? (what version of Pixy are you using?)

Thanks,
Jesse