I have a problem which i was struggling with for the past 4 days, I'm a beginner. I am trying to make arduino nano 33 ble sense send it's onboard temperature, pressure and humidity sensor through I2C to a NodeMcu v0.9 which then sends the data to the arduino Iot cloud. I'm using the <I2C_Anything.h> and <Wire.h> libraries. Everything but the connection between the Arduino and Nodemcu works fine, may i have some help? Here is the arduino (Master) code:
#include <Arduino_LPS22HB.h>
#include <Arduino_HTS221.h>
#include <Wire.h>
#include <I2C_Anything.h>
const byte SLAVE_ADDRESS = 42;
void setup() {
Serial.begin(9600);
Wire.begin();
while (!Serial);
if (!BARO.begin()) {
Serial.println("Failed to initialize pressure sensor!");
while (1);
}
if (!HTS.begin()) {
Serial.println("Failed to initialize humidity temperature sensor!");
while (1);
}
}
void loop() {
float pressure = BARO.readPressure();
Serial.print("Pressure = ");
Serial.print(pressure);
Serial.println(" kPa");
float temperature = BARO.readTemperature();
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" C");
float htstemperature = HTS.readTemperature();
Serial.print("Temperature = ");
Serial.print(htstemperature);
Serial.println(" °C");
float humidity = HTS.readHumidity();
Serial.print("Humidity = ");
Serial.print(humidity);
Serial.println(" %");
Wire.beginTransmission (SLAVE_ADDRESS);
I2C_writeAnything (temperature);
I2C_writeAnything (humidity);
I2C_writeAnything (pressure);
Wire.endTransmission ();
delay(100);
}
And here is the NodeMcu (Reciever) code:
#include "arduino_secrets.h"
/*
Sketch generated by the Arduino IoT Cloud Thing
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float htstemperature;
float humidity;
float pressure;
float temperature;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <Wire.h>
#include <Wire.h>
#include <I2C_Anything.h>
const byte MY_ADDRESS = 42;
void setup() {
Wire.begin (MY_ADDRESS);
Wire.begin(D1, D2);
Serial.begin (9600);
Wire.onReceive(receiveEvent);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code h
}
void receiveEvent (int howMany){
if (howMany >= (sizeof temperature) + (sizeof humidity)+ (sizeof pressure))
{
I2C_readAnything (temperature);
I2C_readAnything (humidity);
I2C_readAnything (pressure);
}
}
The temperature, humidity and pressure float are defined on another tab.
Also this is my first time using the forums so i may have put this in the wrong page.