Arduino, pixy, and RoboRio Communications

My name is Noah, and I am part of team 4125 in Oregon. I am having troubles with receiving data from the arduino. I am writing to the arduino, but not receiving. I am trying to use a pixy for vision processing for the gears.

#include <SPI.h>  
#include <Pixy.h>
#include <Wire.h>

// This is the main Pixy object 
Pixy pixy;

void setup()
{
  Serial.begin(9600);
  Serial.print("Starting...
");
  Wire.begin(84);
  Wire.onReceive(receiveEvent);
  

  pixy.init();
}

void loop()
{ 
  
}
void receiveEvent(int howMany)
{
  uint16_t blocks;
  int j;
  blocks = pixy.getBlocks();
  while(Wire.available())
  {
    char c = Wire.read();
    if (c == 1){
      if (blocks)
      {
        pixy.blocks[j].print();
      }
    }
  }
}
 

This is my code for the arduino. I don’t know what else I can say to help explain. but I can answer some questions asked. Thanks.

Noah,

You do not need to use an arduino to communicate with the Pixy cam. There multiple interface options from the Pixy that the roboRIO can connect to directly. Last year we used the simple digital\analog x interface which tells you if it sees a target or not (digital), and where within the frame the target is (analog). This interface connects directly to 1 digital input and 1 analog input on the roboRIO.

The C++ class we created for this is shown here:

/*
 * PixyCamera.cpp
 *
 *  Created on: Mar 30, 2016
 *      Author: Gaelhawks
 */
#include "WPILib.h"
#include "Common.h"
#include "PixyCamera.h"


PixyCamera::PixyCamera()
{
    goalLocator = new AnalogInput(PIXY_ANALOG_INPUT);
    goalDetector = new DigitalInput(PIXY_GOAL_DETECTOR);
}

bool PixyCamera::GoalDetected()
{
    if(goalDetector->Get())
    {
        return true;
    }
    else
    {
        return false;
    }
}

float PixyCamera::GoalLocation()
{
    float cameraVoltage;

    cameraVoltage = goalLocator->GetVoltage();
    return cameraVoltage;
}

bool PixyCamera::OKtoShoot(float desiredGoal)
{
    // use lateralTrimValue in here somehow???
    // like: (CENTERED_GOAL_VOLTAGE + lateralTrimValue*0.1)
    if(GoalDetected() && (fabs)(GoalLocation() - desiredGoal) < VOLTAGE_TOLERANCE)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void PixyCamera::UpdateDash()
{
    SmartDashboard::PutBoolean("Pixy OK to Shoot: ", OKtoShoot(CENTERED_GOAL_VOLTAGE));
    SmartDashboard::PutBoolean("Pixy Goal Detected: ", GoalDetected());
    SmartDashboard::PutNumber("Pixy Camera Voltage: ", GoalLocation());
    SmartDashboard::PutNumber("Pixy Lateral Trim: ", lateralTrimValue);
}

This year we are using the I2C interface which provides more detailed data about multiple targets. This thread https://www.chiefdelphi.com/forums/showthread.php?t=154355&has C++ code that we have used to successfully communicate with the Pixy.

Hope this helps.