<< return to Pixycam.com

Connecting to Pixy2 cam SPI_SS C++

Hey guys!

I am currently working on a project where I need to connect a pixy cam to an NXP board. The board is not running any kernel, it is a simple micro-kernel running C++.

When trying to initiate the Pixy2 object using the .init() method, I get the following error:
“error : no response”

I followed the steps on a trouble shooting guide to connect to Arduino “including training the pixy an object in CCC”.

I found this wiki page: https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
It explains how to port the Tpixy.h to C++. Any help to connect would be greatly appreciated!

PS: Here is my port:

// Arduino SPI with slave select link class

#ifndef _PIXY2SPI_SS_H
#define _PIXY2SPI_SS_H

#include “TPixy2.h”

extern “C”{
#include “Interfaces/iSpi.h”
#include “Interfaces/iDio.h”
#include “Modules/mSpi.h”
#include “Pixy2Line.h”
#include “Pixy2CCC.h”
}
#define PIXY_SPI_CLOCKRATE 2000000

class Link2SPI_SS
{
public:
int8_t open(uint32_t arg)
{
/* if (arg==PIXY_DEFAULT_ARGVAL)
ssPin = SS; // default slave select pin
else
ssPin = arg;
pinMode(ssPin, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(PIXY_SPI_CLOCKRATE, MSBFIRST, SPI_MODE1));
*/
mSpi_Open();
return 0;
}

void close()
{
mSpi_Close();
}

int16_t recv(uint8_t *buf, uint8_t len, uint16_t *cs=NULL)
{
uint8_t i;
if (cs){
*cs = 0;
}
// CS camera OFF
iDio_SetPort(kPortD,kMaskIo4,kIoOff);

for (i=0; i<len; i++)
{
  buf[i] = (uint8_t)mSpi_SP1ReadWrite(0x00);
  if (cs)
    *cs += buf[i];
}
// CS camera ON
iDio_SetPort(kPortD,kMaskIo4,kIoOn);

return len;

}

int16_t send(uint8_t *buf, uint8_t len)
{
uint8_t i;

// CS camera OFF
iDio_SetPort(kPortD,kMaskIo4,kIoOff);
for (i=0; i<len; i++)
{
	mSpi_SP1ReadWrite(buf[i]);
}
// CS camera ON
iDio_SetPort(kPortD,kMaskIo4,kIoOn);
return len;

}

void setArg(uint16_t arg)
{
}

private:
uint16_t ssPin;
};

typedef TPixy2<Link2SPI_SS> Pixy2SPI_SS;

#endif

Hello,
It sounds like you should take a couple steps back and get basic communications working between your micro and Pixy2. Make sure you have set the communication interface on Pixy2 to “SPI with SS”:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixymon_index#interface-tab

Then try to isolate the communcations by sending the version query and receiving the version response. This section of the porting guide describes this query/response and includes some sample code that you can modify.

Once you get this working, you should be able to fairly easily get the rest of the code working (e.g. TPixy.h)

Hope this helps!

Edward