# Casting Variables for I2C

**URL:** <https://community.particle.io/t/casting-variables-for-i2c/48813>\
**Category:** Troubleshooting\
**Tags:** electron\
**Created:** [March 31, 2019, 7:46pm UTC](https://community.particle.io/t/casting-variables-for-i2c/48813 "2019-03-31T19:46:49Z")\
**Posts on this page:** 1\
**Showing post:** 35

<div class="post-metadata">

**Author:** ![MikeP171](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MikeP171](https://community.particle.io/u/MikeP171)\
**Post date:** [June 8, 2019, 3:26pm UTC](https://community.particle.io/t/casting-variables-for-i2c/48813/35 "2019-06-08T15:26:37Z")

</div>

Hi Guys,  
I was able to get my project to work finally, albeit the inverse setup I originally intended, with the Arduino as the master. This current setup is with the Electron as the Master. Here is my setup with code and output to follow.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/c/d/cd00f1acd9c5853702366e6b8275748a5b880e1b.jpeg)  
Arduino slave:

```cpp
#include <Wire.h>

void setup() {
Wire.begin();
  Serial.begin(9600);
  Serial.print("setup has completed.");//mp
}

void loop() {
  Wire.beginTransmission(1);
  Wire.write(234); //modify this! //numerical 256 is the limit on this -MP
  Wire.endTransmission();
  Serial.println("loop finished.");
  delay(1000); //mp
}

```

ELECTRON MASTER:

```cpp
#include <Wire.h>
int wireVal = 0;
int led = D7;
String incomingString= "";

void setup() {
    pinMode(led, OUTPUT);
    Serial.begin(9600);
    Wire.begin(1);
    Wire.onReceive(receiveData);
}

void loop() {
    digitalWrite(led, wireVal);
}

void receiveData (int byteCount) {
    while (0 < Wire.available()) {
    wireVal = Wire.read();
    Serial.println("wireVal is: ");
    Serial.println(wireVal);
    }
}

```

![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/1/9/194f56d316f6896abbcb67e2d1c4084b2359a72e.png)

If I wanted to transmit a string, I would define a string variable on both boards correct? So what would my syntax look like for this type of data transmission over i2c?

Also, if I actually wanted to flip roles arduino would be the master instead. Would I need resistors?

---

_[View the full topic](https://community.particle.io/t/casting-variables-for-i2c/48813)._
