OCCRA
Go to Post Searching is your friend - try it. - Katie Reynolds [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 3 votes, 4.33 average. Display Modes
  #1   Spotlight this post!  
Unread 02-11-2015, 06:12 PM
mikefas mikefas is offline
Registered User
FRC #3104
 
Join Date: Feb 2015
Location: us
Posts: 2
mikefas is an unknown quantity at this point
Pixy I2C

I am trying to figure out how to interface a Pixy Camera with our Roborio using the i2C port. Does anyone have experience with the Pixy or i2C communications?

Also, can we instead use an Arduino as a mediator, we already wrote the code for the Arduino and It would be easier to do it via the Arduino to Roborio if possible.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-11-2015, 06:18 PM
Rakusan2 Rakusan2 is offline
Registered User
AKA: Tomas Rakusan
FRC #3571 (Milton Mustangs)
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2011
Location: Milton, ON, Canada
Posts: 23
Rakusan2 is an unknown quantity at this point
Re: Pixy I2C

My team got the Arduino communicating with the roborio over I2C using the following code on the roborio
Code:
//this is outside a method
I2C Wire = new I2C(Port.kOnboard, 4);

//this is inside a method
if (Global.driver.Buttons.Back.changedDown) {
	String WriteString = "go"; //this is being sent to the Arduino
	char[] CharArray = WriteString.toCharArray();
	byte[] WriteData = new byte[CharArray.length];
	for (int i = 0; i < CharArray.length; i++) {
		WriteData[i] = (byte) CharArray[i];
	}
	Wire.transaction(WriteData, WriteData.length, null, 0);
}
And this code on the Arduino which was made to turn on an LED when it received the message "go"
Code:
#include <Wire.h>

void setup()
{
  pinMode (13, OUTPUT);
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  String LED = "";
 
  while ( Wire.available() > 0 )
  {
    char n=(char)Wire.read();
    if(((int)n)>((int)(' ')))
   LED += n; 
  }
  
  if (LED == "go") 
  {
    
    digitalWrite (13, HIGH);
  
    
  }
}

Last edited by Rakusan2 : 02-11-2015 at 06:19 PM. Reason: spelling mistake
Reply With Quote
  #3   Spotlight this post!  
Unread 02-12-2015, 07:58 AM
gpetilli gpetilli is offline
Registered User
FRC #1559
 
Join Date: Jan 2009
Location: Victor, NY
Posts: 289
gpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to all
Re: Pixy I2C

We are using pixy to lock onto yellow totes in AUTO. My team found it easier to decode packets via the serial port (connected to roboRIOC) than the I2C. We can share code if you need it.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-12-2015, 08:16 AM
matthewdenny's Avatar
matthewdenny matthewdenny is offline
Registered User
FRC #6054 (Dukes)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: United States
Posts: 334
matthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant futurematthewdenny has a brilliant future
Re: Pixy I2C

I'd be interested in the code.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-12-2015, 09:32 AM
mikefas mikefas is offline
Registered User
FRC #3104
 
Join Date: Feb 2015
Location: us
Posts: 2
mikefas is an unknown quantity at this point
Re: Pixy I2C

That would be great, if serial is possible it would be a lot easier.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-13-2015, 10:25 AM
AlexanderTheOK AlexanderTheOK is offline
Guy
no team
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Los Angeles
Posts: 176
AlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud ofAlexanderTheOK has much to be proud of
Re: Pixy I2C

I would also like to see said code.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-13-2015, 03:57 PM
2B || !2B's Avatar
2B || !2B 2B || !2B is offline
/* No Comment */
FRC #1559 (DevilTech)
Team Role: Programmer
 
Join Date: Apr 2013
Rookie Year: 2013
Location: New York
Posts: 19
2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough
Re: Pixy I2C

Hi there. Here is what out team is using to pry information out of the pixy. I hope this helps! I'm not sure why the code block is anti-tabbing...

(the code gpetilli mentioned)

Code:
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.SerialPort.Port;
//Warning: if the pixy is plugged in through mini usb, this code WILL NOT WORK b/c the pixy is smart and detects where it should send data
public class Pixy {
SerialPort pixy;
Port port = Port.kMXP;
PixyPacket[] packets;
PixyException pExc;
String print;
public Pixy() {
pixy = new SerialPort(19200, port);
pixy.setReadBufferSize(14);
packets = new PixyPacket[7];
pExc = new PixyException(print);
}
//This method parses raw data from the pixy into readable integers
public int cvt(byte upper, byte lower) {
return (((int)upper & 0xff) << 8) | ((int)lower & 0xff);
}
public void pixyReset(){
pixy.reset();
}
//This method gathers data, then parses that data, and assigns the ints to global variables
public PixyPacket readPacket(int Signature) throws PixyException {
int Checksum;
int Sig;
byte[] rawData = new byte[32];
try{
rawData = pixy.read(32);
} catch (RuntimeException e){
}
if(rawData.length < 32){
System.out.println("byte array length is broken");
return null;
}
for (int i = 0; i <= 16; i++) {
int syncWord = cvt(rawData[i+1], rawData[i+0]); //Parse first 2 bytes
if (syncWord == 0xaa55) { //Check is first 2 bytes equal a "sync word", which indicates the start of a packet of valid data
syncWord = cvt(rawData[i+3], rawData[i+2]); //Parse the next 2 bytes
if (syncWord != 0xaa55){ //Shifts everything in the case that one syncword is sent
i -= 2;
}
//This next block parses the rest of the data
Checksum = cvt(rawData[i+5], rawData[i+4]);
Sig = cvt(rawData[i+7], rawData[i+6]);
if(Sig <= 0 || Sig > packets.length){
break;
}
packets[Sig - 1] = new PixyPacket();
packets[Sig - 1].X = cvt(rawData[i+9], rawData[i+8]);
packets[Sig - 1].Y = cvt(rawData[i+11], rawData[i+10]);
packets[Sig - 1].Width = cvt(rawData[i+13], rawData[i+12]);
packets[Sig - 1].Height = cvt(rawData[i+15], rawData[i+14]);
//Checks whether the data is valid using the checksum *This if block should never be entered*
if (Checksum != Sig + packets[Sig - 1].X + packets[Sig - 1].Y + packets[Sig - 1].Width + packets[Sig - 1].Height) {
packets[Sig - 1] = null;
throw pExc;
}
break;
}
}
//Assigns our packet to a temp packet, then deletes data so that we dont return old data
PixyPacket pkt = packets[Signature - 1];
packets[Signature - 1] = null;
return pkt;
}
}
Code:
public class PixyException extends Exception {
public PixyException(String message){
super(message);
}
}
Code:
public class PixyPacket {
public int X;
public int Y;
public int Width;
public int Height;
}
__________________
There are no brakes on the software train

Last edited by 2B || !2B : 02-13-2015 at 04:01 PM. Reason: I forgot to mention something.
Reply With Quote
  #8   Spotlight this post!  
Unread 02-14-2015, 09:13 AM
gsampel gsampel is offline
Registered User
FRC #3104 (Cyber Rams)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2011
Location: Stamford, CT
Posts: 3
gsampel is an unknown quantity at this point
Re: Pixy I2C

2B || !2B ,
I am the lead programmer on Mike's team, thank you so much for your code, We are cutting it a little close to the deadline and this definitely helps.
Also, awesome name.
Thanks,
gsampel
Reply With Quote
  #9   Spotlight this post!  
Unread 02-14-2015, 10:46 AM
gsampel gsampel is offline
Registered User
FRC #3104 (Cyber Rams)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2011
Location: Stamford, CT
Posts: 3
gsampel is an unknown quantity at this point
Re: Pixy I2C

How exactly do we wire the Pixy, the stock cable does not seem like the correct one to connect directly to the RoboRio
Reply With Quote
  #10   Spotlight this post!  
Unread 02-14-2015, 08:01 PM
gpetilli gpetilli is offline
Registered User
FRC #1559
 
Join Date: Jan 2009
Location: Victor, NY
Posts: 289
gpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to all
Re: Pixy I2C

Quote:
Originally Posted by gsampel View Post
How exactly do we wire the Pixy, the stock cable does not seem like the correct one to connect directly to the RoboRio
In case you are a newer team, you can remove the roboRIO from your robot before you bag it and work on code any time there is a competition anywhere (Typically next 6 Thur, Fri, Sat).

Look at the Pixy Docs - i dont remember if they call it rs232 or serial port. roboRIO also has a serial port. I will ask our electrical team to post more details as to what they did.
Reply With Quote
  #11   Spotlight this post!  
Unread 02-14-2015, 08:11 PM
gsampel gsampel is offline
Registered User
FRC #3104 (Cyber Rams)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2011
Location: Stamford, CT
Posts: 3
gsampel is an unknown quantity at this point
Re: Pixy I2C

Is this the sort of thing were we can put together our own cable, or will we need to use the actual serial cable? I don't think we have one, so we would have to make one, probably out of a few scrapped PWM cables. I would find it really helpful to see a picture of your connection or what cable you used.
thanks,
gsampel
Reply With Quote
  #12   Spotlight this post!  
Unread 02-15-2015, 06:54 AM
gpetilli gpetilli is offline
Registered User
FRC #1559
 
Join Date: Jan 2009
Location: Victor, NY
Posts: 289
gpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to allgpetilli is a name known to all
Re: Pixy I2C

Quote:
Originally Posted by gsampel View Post
Is this the sort of thing were we can put together our own cable, or will we need to use the actual serial cable? I don't think we have one, so we would have to make one, probably out of a few scrapped PWM cables. I would find it really helpful to see a picture of your connection or what cable you used.
thanks,
gsampel
yes, you can make your own cable. I seem to remember needing the hook the PIXY up via USB to a laptop to turn on the serial output. Serial outputs have multiple names so look for serial, uart, or rs232.
Reply With Quote
  #13   Spotlight this post!  
Unread 03-19-2015, 06:54 PM
Sayol4 Sayol4 is offline
Registered User
FRC #1153
 
Join Date: Mar 2015
Location: Walpole
Posts: 1
Sayol4 is an unknown quantity at this point
Re: Pixy I2C

Does anyone have a picture or instructions on how to connect the pixy to the Roborio using the ribbon cables?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:15 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi