Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Need help with arduino to i2c on roborio! (http://www.chiefdelphi.com/forums/showthread.php?t=132572)

SoftwareRachel 01-10-2015 03:03 PM

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. :mad: :confused:

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? :confused: ), 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! :)

Owen Busler 01-10-2015 03:20 PM

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.

dyanoshak 01-10-2015 03:39 PM

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

choffman123 01-10-2015 07:26 PM

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.

ThomasClark 01-12-2015 02:07 AM

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.

SoftwareRachel 01-13-2015 11:34 AM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by ThomasClark (Post 1426598)
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! :)

seg9585 01-13-2015 11:38 AM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by ThomasClark (Post 1426598)
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)

Tom Line 01-17-2015 04:16 PM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by seg9585 (Post 1427329)
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.

cad321 01-25-2015 08:16 PM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by ThomasClark (Post 1426598)
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?

ThomasClark 01-26-2015 06:45 PM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by cad321 (Post 1433859)
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.

Sn3akyP3t3 02-08-2015 11:46 PM

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

Sn3akyP3t3 02-09-2015 08:28 PM

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.

Rakusan2 02-10-2015 01:12 PM

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);
 
   
  }
}


The Doctor 02-04-2016 05:02 PM

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...

The Doctor 02-04-2016 05:15 PM

Re: Need help with arduino to i2c on roborio!
 
Quote:

Originally Posted by SoftwareRachel (Post 1425690)
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)


All times are GMT -5. The time now is 08:18 AM.

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