Go to Post Its not the type of material you use, but how you use it... - jrocket567 [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

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #13   Spotlight this post!  
Unread 10-02-2015, 13:12
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
 


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 06:27.

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