Wire library doesn't work with Bridge

Good evening people! :slight_smile:

I’ve just connected some sensors on an Arduino UNO, and are pulling them from the Yun over i2c using the Wire library.
And when I was finally done, I wanted to paste them somewhere on the internet. But as soon as I included the Process library (or just Bridge) I no longer received the sensor data?

So, everything is running perfectly fine - but as soon as I add “#include <Process.h>” into my sketch and run it; no data is registered :frowning:

Code:

#include <Wire.h>

#define WATER_TEMP 1
#define HUMIDITY 2
#define AIR_TEMP 3

boolean bytesToRead;
String dataString = "";

void setup() {
 
  Wire.begin(); 
  Serial.begin(9600); 
  bytesToRead = false;
  
}

void loop()
{

  Serial.println("--------READINGS-------");
  
  dataString += "WATER_TEMP,";
  
  Serial.print("WATER_TEMP: ");
  readUno(WATER_TEMP);
  
  dataString += "\nHUMIDITY,";

  Serial.print("HUMIDITY: ");
  readUno(HUMIDITY);
  
  dataString += "\nAIR_TEMP,";

  Serial.print("AIR_TEMP: ");
  readUno(AIR_TEMP);

  //Serial.println(dataString);
  dataString = "";
  
  delay(2000);

}

void readUno(int sensor) {
 
   Wire.beginTransmission(2);
   char sendBytes[sensor];
   Wire.write(sendBytes);
//   Serial.print("SENSOR TO READ:");
//   Serial.println(sizeof(sendBytes));
//   Serial.println("REQUESTING...");
   Wire.endTransmission();
   
   int numBytes = 0;
  
  
  Wire.requestFrom(2, 1);
   
  while(Wire.available() && !bytesToRead) { 
    char c = Wire.read(); 
   // Serial.print("BYTES TO RECIEVE: ");      
    numBytes = c;
    //Serial.println(int(numBytes));
    if(numBytes != 0) {
      bytesToRead = true;
    }
  }
  
  if(bytesToRead) {
      Wire.requestFrom(2, numBytes);   
      //Serial.print("VALUE RECIEVED: ");
      while(Wire.available()) {     
        char c = Wire.read(); 
        Serial.print(c);
        dataString += c;        
      }
      Serial.println("");
      bytesToRead = false;
  }
  
}

Here’s the output without “#include <Process.h>”:

--------READINGS-------
WATER_TEMP: 24.06
HUMIDITY: 39
AIR_TEMP: 26

And here’s with “#include <Process.h>”:

--------READINGS-------
WATER_TEMP: HUMIDITY: AIR_TEMP:

Any ideas? Is there something known about i2c communication and Process library?

Thanks for your time,
pakken

I have wierd behaviour and I use wire and process (though a minimal implementation) I'm not sure it is related but I thought it was worth mentioning See more info here http://forum.arduino.cc/index.php?topic=217571.0 Best regards Jantje

Hello!

Thanks for your answer. I broke down my code to find the issue, and succeeded. So for future reference:

I wanted to transmit a dynamic number of bytes to determine which sensor I wanted to read on the Uno, I made a char array with the size of the sensor index. I knew then I could easily index my sensor values using the slave onRecieve, which take the number of bytes sent as a parameter.

Somehow this didn't work when including the Process library. So I switched to making a byte array instead, with the size of the sensor index, and now everything works. Amazing...

So in my readUno() function I have this instead:

Wire.beginTransmission(2);
   byte index[sensor];
   Wire.write(index, sensor);
   Wire.endTransmission();

Instead of:

Wire.beginTransmission(2);
   char index[sensor];
   Wire.write(index);
   Wire.endTransmission();

good your problem is fixed. Mine is still not. But I'll get there :D Best regards Jantje