Having trouble sending a string via I2C

  arduino, arduino-uno, c++

I have an arduino with 3 sensors connected and need to send the information I’m getting from the said sensors to another arduino and have it displayed on a connected lcd. I tried to go about this by changing the float values I’m getting into a string, sending the string to the other arduino and displaying that on the lcd. But when I try to execute this, I get an error saying :

" In function ‘void receiveEvent(int)’:
16:24: error: incompatible types in assignment of ‘int’ to ‘char [7]’ "

#include <Wire.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int sensePin = A0;
int sensorInput;

int lightPin = A1;
int lightInput;

int gasPin = A2;
int gasInput;
int buzzer = 13;

int b_state = 3;

float temp;
float light;

char t_buffer[7];

int state = 0;

void setup()
{
  Wire.begin();
  pinMode(A0, INPUT);
  pinMode(A1,INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(A2, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(b_state, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16, 2);
  
  attachInterrupt(digitalPinToInterrupt(3), buttons, FALLING);
}

void loop()
{ 
  gasInput = analogRead(gasPin);
  sensorInput = analogRead(sensePin);
  lightInput = analogRead(lightPin);
  
  temp = (float)sensorInput / 1024;
  temp = temp * 5;
  temp = temp - 0.498;
  temp = temp * 100;
  
  light = ((float)lightInput - 26) / 8.97;
  
  dtostrf(temp, 6, 2, t_buffer);

  Serial.print("Current Temperature: ");
  Serial.println(temp);
  Serial.print("Current Light: ");
  Serial.println(light);
  Serial.print("Gas (conc.?): ");
  Serial.println(gasInput);
  
  Wire.beginTransmission(9);
  Wire.write(t_buffer, 7);
  Wire.endTransmission();
  
  delay(100);
  
  if (state == 0){
  lcd.setCursor(0, 0);
  lcd.print("Temp (C): ");
  lcd.setCursor(0,1);
  lcd.print(t_buffer);
  }
  
  else {
  lcd.setCursor(0,0);
  lcd.print("Light Intensity: ");
  lcd.setCursor (0,1);
  lcd.print(light);
  }
  
  if (gasInput > 800)
    digitalWrite(buzzer, HIGH);
  else
    digitalWrite(buzzer, LOW);
}

void buttons()
{
  lcd.clear();
  state = !state;
}
#include <Wire.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float temp;
char t_buffer[7];

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  Wire.begin(9); 
  Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
  t_buffer = Wire.read();
  //temp = t_buffer.toFloat();
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Temp (C): ");
  lcd.setCursor(0,1);
  lcd.print(temp);
}

Also I have 2 separate float values that I need to send and I’m thinking I could time the transmissions properly and send them both one after the other. Is this a good way of doing this or is there an alternative way?

The circuit

Source: Windows Questions C++

LEAVE A COMMENT