Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Arduino & Roborio cant find each other I2C Issues (http://www.chiefdelphi.com/forums/showthread.php?t=154065)

zDrakon 21-01-2017 19:03

Arduino & Roborio cant find each other I2C Issues
 
code: http://pastebin.com/9uq4S2dQ

Okay, so I'm trying to scan through all the possible addresses that the arduino could be from both Roborio (our code here) and Arduino (Arduino used I2C scanner code: http://playground.arduino.cc/Main/I2cScanner)

We have verified the wiring of the arduino is correctly wired with A4 and A5 connected to the I2C and ground and power to the I2C port of roborio.

Both devices can't find each other.

Anyone have a solution to make both devices find each other?

(Strangely enough we can have Roborio send data to Arduino and Arduino read it but the Arduino can't successfully send data to the roborio with the Roborio giving a response like a System.out.println() in the DriverStation console)

Joe Ross 21-01-2017 22:16

Re: Arduino & Roborio cant find each other I2C Issues
 
Is your arduino configured as a slave?

euhlmann 21-01-2017 22:40

Re: Arduino & Roborio cant find each other I2C Issues
 
Quote:

Originally Posted by zDrakon (Post 1634589)
(Strangely enough we can have Roborio send data to Arduino and Arduino read it but the Arduino can't successfully send data to the roborio with the Roborio giving a response like a System.out.println() in the DriverStation console)

Congrats, you've correctly set up the Arduino as a slave 🎉
In I2C, slaves can only send data for a transaction, not any time they want. For Arduino, that means you can only write in the onRequest handler function, and only the number of bytes the master expects. On the roboRIO side, you need to call I2C.transaction()

avayner 21-01-2017 23:56

Re: Arduino & Roborio cant find each other I2C Issues
 
We've done exactly that, but for some reason onRequest was not being triggered... Any ideas how to troubleshoot this?

euhlmann 22-01-2017 00:47

Re: Arduino & Roborio cant find each other I2C Issues
 
Quote:

Originally Posted by avayner (Post 1634692)
We've done exactly that, but for some reason onRequest was not being triggered... Any ideas how to troubleshoot this?

Could you post the code you're using (roborio and arduino)?

zDrakon 22-01-2017 01:47

Re: Arduino & Roborio cant find each other I2C Issues
 
Roborio code: http://pastebin.com/TiFcYq6L

Arduino: http://pastebin.com/TDPk9W5i

Do keep in mind we did try using onREquest for arduino and set it up as a slave prior but for some reason it didnt work. :( My team is confused, even the mentor is having trouble explaining what's happening.

euhlmann 22-01-2017 15:55

Re: Arduino & Roborio cant find each other I2C Issues
 
I see. Try this

roboRIO:
Code:

static I2C arduino = new I2C(Port.kOnboard, 42);

@Override
public void teleopPeriodic() {
    byte[] sendData = "sample text".getBytes();
    byte[] receiveData = new byte[sendData.length];
    boolean failed = arduino.transaction(sendData, sendData.length, receiveData, receiveData.length);
    if(!failed) {
        System.out.println("Got data: " + new String(receiveData, 0, receiveData.length);
    }
}

Arduino:
Code:

#include <Wire.h>

void setup() {
  Wire.begin(42);
  Wire.onRequest(requestEvent);
  Serial.begin(9600);
}

void loop() {
  delay(100);
}

// send back the same data as we receive
void requestEvent() {
  Serial.println("Got request:");
  while (Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
    Wire.write(c);
  }
}


Harp 27-01-2017 22:52

Re: Arduino & Roborio cant find each other I2C Issues
 
The Arduino didn't read anything from the roborio using this code. We've since switched to using a raspberry pi


All times are GMT -5. The time now is 21:48.

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