Go to Post People aren't getting angry at teams who play defense. They are getting angry at the teams who play BattleBots in the middle of a FIRST match. - dlavery [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: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 01-10-2015, 03:03 PM
SoftwareRachel's Avatar
SoftwareRachel SoftwareRachel is offline
Registered User
FRC #4505
 
Join Date: Feb 2014
Location: Maryland
Posts: 12
SoftwareRachel is an unknown quantity at this point
Smile Need help with arduino to i2c on roborio!

Hi everyone!
This season, our team will be using an led strip with an arduino so we can control individual lights . We then want to connect our arduino to our roborio so we can control the arduino from our java code. We've done a lot of research but we can't figure out how to write the code for this.

For example, if we want the strip of led lights to be rainbow in autonomous, we know how to do that with the arduino code, but once we connect the arduino to the roborio (i2c port, right? ), what code would we write in eclipse to trigger the arduino? Everything we've looked at has used DigitalModule which seems to not be used this year. Thanks for the help!
Reply With Quote
  #2   Spotlight this post!  
Unread 01-10-2015, 03:20 PM
Owen Busler's Avatar
Owen Busler Owen Busler is offline
Build Captain
FRC #0303 (Test Team)
Team Role: Leadership
 
Join Date: Aug 2014
Rookie Year: 2014
Location: Bridgewater, NJ
Posts: 131
Owen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant futureOwen Busler has a brilliant future
Re: Need help with arduino to i2c on roborio!

Instead of using the i2c you could use an analog output from the roboRio into the arduino. On the roboRio you would output 5v during auto and 0v during teleop. Then the arudino would output rainbow when it has a 5v input and it could change when it receives 0v.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-10-2015, 03:39 PM
dyanoshak dyanoshak is offline
Registered User
AKA: David Yanoshak
FRC #2158 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Austin, TX
Posts: 189
dyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond repute
Re: Need help with arduino to i2c on roborio!

I realize that this example is in LabVIEW but similar APIs should be available in Java. Hopefully this will give you a push in the right direction.

AndyMark released some example code that drives a touch-screen shield on the RIOduino (the REV Robotics Arduino-compatible MXP board). The screen code won't be of interest, but the last part of their example shows how they communicate between the roboRIO and the RIOduino through the I2C port.

Take a look at the example under the "Files & Documents" tab on the RIOduino with 2.8" Touchscreen (am-2999) bundle page.

Again, their example is in LabVIEW, but the same APIs should exist in Java.

Hope this helps!

-David
__________________
David Yanoshak
Co-founder REV Robotics | www.revrobotics.com
Reply With Quote
  #4   Spotlight this post!  
Unread 01-10-2015, 07:26 PM
choffman123's Avatar
choffman123 choffman123 is offline
4042 Mentor
FRC #4042 (Spartan Eagles 4042)
Team Role: Mentor
 
Join Date: Jun 2012
Rookie Year: 2012
Location: Maine
Posts: 1
choffman123 is an unknown quantity at this point
Re: Need help with arduino to i2c on roborio!

I'm a lazy coder but, for a super quick turnaround, you might use a few digital IO on the roborio to interact with the arduino and have a few pins on the arduino set to input. when the arduino reads a pin is high it would change the LED modes.

on the arduino, if pin 2 is High, Blue LED's blink... Etc.

you could use 4 DIO's and then use them like binary to multiply your LED modes.

or use 1 pwm and use pulsein(); on the arduino and you could have 180 modes... we did something similar with a pot as input for our driver-station board last year.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-12-2015, 02:07 AM
ThomasClark's Avatar
ThomasClark ThomasClark is offline
Registered User
FRC #0237
 
Join Date: Dec 2012
Location: Watertown, CT
Posts: 146
ThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud of
Re: Need help with arduino to i2c on roborio!

This I2C tutorial will still work on a roboRIO, if you make a couple changes. Mainly, your robotInit() method just needs to have this:

Code:
public void robotInit() {
    i2c = new I2C(I2C.Port.kOnboard, 168);
}
Another easy way would be to just use USB. Use the SerialPort class in your Java code to send data to the Arduino, and use Serial.read() on the Arduino to get the data. This has the advantage that it's really easy to test using the Serial Console in the Arduino IDE.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-13-2015, 11:34 AM
SoftwareRachel's Avatar
SoftwareRachel SoftwareRachel is offline
Registered User
FRC #4505
 
Join Date: Feb 2014
Location: Maryland
Posts: 12
SoftwareRachel is an unknown quantity at this point
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by ThomasClark View Post
This I2C tutorial will still work on a roboRIO, if you make a couple changes. Mainly, your robotInit() method just needs to have this:

Code:
public void robotInit() {
    i2c = new I2C(I2C.Port.kOnboard, 168);
}
Another easy way would be to just use USB. Use the SerialPort class in your Java code to send data to the Arduino, and use Serial.read() on the Arduino to get the data. This has the advantage that it's really easy to test using the Serial Console in the Arduino IDE.
Thank you! That helps out a lot!
Reply With Quote
  #7   Spotlight this post!  
Unread 01-13-2015, 11:38 AM
seg9585's Avatar
seg9585 seg9585 is offline
Registered User
AKA: Eric
FRC #4276 (Surf City Vikings)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2001
Location: Boeing (Seal Beach, CA)
Posts: 517
seg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond repute
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by ThomasClark View Post
This I2C tutorial will still work on a roboRIO, if you make a couple changes. Mainly, your robotInit() method just needs to have this:

Code:
public void robotInit() {
    i2c = new I2C(I2C.Port.kOnboard, 168);
}
Another easy way would be to just use USB. Use the SerialPort class in your Java code to send data to the Arduino, and use Serial.read() on the Arduino to get the data. This has the advantage that it's really easy to test using the Serial Console in the Arduino IDE.
Let me know if the I2C method actually works, so far we have been unable to get communication working on the I2C OnBoard port, only the MXP. We suspect it's an issue specific to Java (See thread about the LIDAR sensor in the Technical forum)
__________________
My FIRST legacy:

Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)
Reply With Quote
  #8   Spotlight this post!  
Unread 01-17-2015, 04:16 PM
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,509
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by seg9585 View Post
Let me know if the I2C method actually works, so far we have been unable to get communication working on the I2C OnBoard port, only the MXP. We suspect it's an issue specific to Java (See thread about the LIDAR sensor in the Technical forum)
FYI - we are unable to get the Lidar working on the I2C onboard board with LabVIEW - it returns read and write errors. It is working with the I2C MXP port though.
Reply With Quote
  #9   Spotlight this post!  
Unread 01-25-2015, 08:16 PM
cad321 cad321 is online now
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by ThomasClark View Post
Another easy way would be to just use USB. Use the SerialPort class in your Java code to send data to the Arduino, and use Serial.read() on the Arduino to get the data. This has the advantage that it's really easy to test using the Serial Console in the Arduino IDE.
How might one go about implementing this? Would I just plug the arduino into the usb port, set my baud rate and my port (not sure which port), and then finally use the Serial.read() command to receive what I had output over the arduino serial?
Reply With Quote
  #10   Spotlight this post!  
Unread 01-26-2015, 06:45 PM
ThomasClark's Avatar
ThomasClark ThomasClark is offline
Registered User
FRC #0237
 
Join Date: Dec 2012
Location: Watertown, CT
Posts: 146
ThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud ofThomasClark has much to be proud of
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by cad321 View Post
How might one go about implementing this? Would I just plug the arduino into the usb port, set my baud rate and my port (not sure which port), and then finally use the Serial.read() command to receive what I had output over the arduino serial?
That's right. I haven't tried it, but you might be able to see the name of the serial port from the web interface.
Reply With Quote
  #11   Spotlight this post!  
Unread 02-08-2015, 11:46 PM
Sn3akyP3t3 Sn3akyP3t3 is offline
Registered User
None #3277
 
Join Date: Feb 2015
Location: TRF
Posts: 2
Sn3akyP3t3 is an unknown quantity at this point
Re: Need help with arduino to i2c on roborio!

I saw this post awhile back and had come across a forum in the past that ensured that USB serial communication between the Raspberry Pi and Arduino is possible so I thought that it would be easy to setup a serial connection via USB. I looked at the online documentation for the WPILib SerialPort implementation and saw that documentation mentions "Driver for the RS-232 serial port on the RoboRIO".

Not being discouraged I tried some open source USB serial libraries and met failure with both of them. I figured I'll share my experience. RXTX, 64 bit precompiled binaries for Windows, was attempted, compiled, and transferred to the RoboRio, but once there it ran into runtime failure as something about the library was not available for some reason. The next library tried was java-simple-serial-connector or jSSC. This library looked promising as something quite simple with only one single jar file to add as a library in Eclipse. Unfortunately, as a WPILib project it fails to build, but has no problem as a Java application. Not sure what the issue is with that.

I returned to searching forums for some means of reading serial from USB and came across this post again. I decided to look at the code for SerialPort and I'm seeing that the option to read from USB appears to indeed exist as an option which I'm writing code for right now to test with, but ran out of time for the day. I'm hoping this is the solution and that it helps someone else. "usbSerialPort = new SerialPort(9600, Port.kUSB);" Some code example to work with for communicating between Arduino and a Pi, modify for Java, is http://www.bitsharr.com/rtxu6LvK
Reply With Quote
  #12   Spotlight this post!  
Unread 02-09-2015, 08:28 PM
Sn3akyP3t3 Sn3akyP3t3 is offline
Registered User
None #3277
 
Join Date: Feb 2015
Location: TRF
Posts: 2
Sn3akyP3t3 is an unknown quantity at this point
Re: Need help with arduino to i2c on roborio!

Tested out the code today with high hopes, but it ended up throwing an error at the point that the call to SerialPort's USB device was made. The catch of the error proved to be fruitless as the returned error was the empty string. The code to inspect will be available in today's Github commit if someone wishes to take a look on their own. https://github.com/FRC-3277/2015Recy...dBasedRefactor

For now I'm going to test with I2C to read and as a last resort I believe RS-232 is available, but if that depends on the SerialPort library it may be a better idea to re-write the Arduino code library in Java and avoid that class if its buggy.
Reply With Quote
  #13   Spotlight this post!  
Unread 02-10-2015, 01:12 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: 22
Rakusan2 is an unknown quantity at this point
Smile Re: Need help with arduino to i2c on roborio!

My team got the Arduino communicating with the roborio over I2C using the following code on the roborio
Code:
static I2C Wire = new I2C(Port.kOnboard, 4);

if (Global.driver.Buttons.Back.changedDown) {
	String WriteString = "go";
	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
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);
  
    
  }
}
Reply With Quote
  #14   Spotlight this post!  
Unread 02-04-2016, 05:02 PM
The Doctor's Avatar
The Doctor The Doctor is offline
Robotics is life
AKA: Hackson
FRC #3216 (MR. T)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: United States
Posts: 139
The Doctor is on a distinguished road
Re: Need help with arduino to i2c on roborio!

Quote:
Another easy way would be to just use USB. Use the SerialPort class in your Java code to send data to the Arduino, and use Serial.read() on the Arduino to get the data. This has the advantage that it's really easy to test using the Serial Console in the Arduino IDE.
This has never worked for me...
__________________
Robots + Python + pentesting == me;
Blog ~ GitHub ~ Keybase
If you have a pressing issue to discuss with me, kik me at slush.puddles since I don't check CD very often.

Last edited by The Doctor : 02-04-2016 at 05:05 PM. Reason: formatting
Reply With Quote
  #15   Spotlight this post!  
Unread 02-04-2016, 05:15 PM
The Doctor's Avatar
The Doctor The Doctor is offline
Robotics is life
AKA: Hackson
FRC #3216 (MR. T)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: United States
Posts: 139
The Doctor is on a distinguished road
Re: Need help with arduino to i2c on roborio!

Quote:
Originally Posted by SoftwareRachel View Post
Hi everyone!
This season, our team will be using an led strip with an arduino so we can control individual lights .
We're doing the same thing! (we did last year as well)
__________________
Robots + Python + pentesting == me;
Blog ~ GitHub ~ Keybase
If you have a pressing issue to discuss with me, kik me at slush.puddles since I don't check CD very often.
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 08:18 AM.

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