Need help with I2C Communication between RoboRio and Arduino

I need help with communication between the roborio and an arduino board. Basically when my robot enters disabled mode, it calls the constructor of an arduino class which basically sends an I2C message.


import edu.wpi.first.wpilibj.I2C;

public class ArduinoI2C {
	public ArduinoI2C() {
		I2C arduino = new I2C(I2C.Port.kOnboard, 4);
		String WriteString = "test"; // "test" will be the message we will send to the arduino
		char[] CharArray = WriteString.toCharArray(); //Turns the message into an array
		byte[] WriteData = new byte[CharArray.length]; //Turns the array into a byte
		for (int i = 0; i < CharArray.length; i++) {
			WriteData[i] = (byte) CharArray[i];
		arduino.transaction(WriteData, WriteData.length, null, 0); //Send the message "test" to the Arduino

And when the Arduino receives the message, an LED lights up on the Arduino

#include <Wire.h>
#define LED_PIN 9
void setup() {
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event

void loop() {

// 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);
    if(((int)n)>((int)(' ')))
   LED += n; 
  if (LED == "test") 
    for(int x = 0; x<10; x++) {
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(LED_PIN, LOW);

When I tested this, nothing happened. Can anyone tell me why? Any recommendations? something wrong with my code? (Note: I am not good with coding :stuck_out_tongue: )**

The notes I have from implementing I2C was that sometimes you need a 10K pull up resistor on the SCL pin to 5v.

The picture on this page shows a wiring diagram.

I’m at work atm, and don’t have my personal laptop, but I’ve gone through this, and I can post code that I knows works when I get home. I ran into this same issue when I was fooling with an Arduino and LEDs.