Irrigation system with BME280 sensor problem

Hi,
I’m Andrew and very new here.
coding skills are mediocre at best, dabbled in plenty of coding languages, enough to be a bit familiar then I lose interest and try another, so I may be mixing it up a bit by mistake.

I’ve done some trawling through a tonne of posts on various forums, but can’t seem to find much information for the BME280 on Cayenne and can’t seem to figure out this error.
I managaged to get it compiling with just the relay module and even added a bit of code I found on here for the addition of a DHT11 with no problems, but run into issues with the BME280.
The code posted below is a mixture of about 6 projects i’ve found and merged as well as my own input, I’m sure its something simple, but the extra help/guidence would be greatly appreciated.
Project running on a NodeMCU 1.0

Cheers
Andrew


#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include <SPI.h>
#include <DFRobot_BME280.h>


#define SEA_LEVEL_PRESSURE  1013.25f
#define Relay1 D1
#define Relay2 D2
#define Relay3 D3
#define Relay4 D4
#define Relay5 D5
#define Relay6 D6
#define Relay7 D7
#define Relay8 D8
#define SEALEVELPRESSURE_HPA (978.36)

DFRobot_BME280 bme;

// WiFi network info.
char ssid[] = "MyWIFI";
char wifiPassword[] = "Superduperhardpassword";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "usename goes here";
char password[] = "Cayenne project password";
char clientID[] = "clientID";

float temp, pressure, hum, alt;

void setup()
{
  Serial.begin(115200);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT);
  pinMode(Relay5, OUTPUT);
  pinMode(Relay6, OUTPUT);
  pinMode(Relay7, OUTPUT);
  pinMode(Relay8, OUTPUT);
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
  digitalWrite(Relay3, HIGH);
  digitalWrite(Relay4, HIGH);
  digitalWrite(Relay5, HIGH);
  digitalWrite(Relay6, HIGH);
  digitalWrite(Relay7, HIGH);
  digitalWrite(Relay8, HIGH);


  Cayenne.loop();

  //Send BME280 data to Cayenne
  Cayenne.virtualWrite(0, temp); //Send temperature
  Cayenne.virtualWrite(1, pressure); // Send pressure
  Cayenne.virtualWrite(2, hum); // Send humidaty
}
void Get_Values()
{
  temp = bme.temperatureValue();
  pressure = bme.pressureValue() / 100.0F;
  hum = bme.humidityValue();
  alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);
  delay(100);
  
//print sensor data
  Serial.println("Collect data");

  Serial.print("Temperature :");
  Serial.print(temp);
  Serial.println(" C");

  Serial.print("Pressure:");
  Serial.print(pressure);
  Serial.println(" hPa");

  Serial.print("Humidity :");
  Serial.print(hum);
  Serial.println(" %");

  Serial.print("Approx. Altitude:");
  Serial.print(alt);
  Serial.println(" m");

  Serial.println("------END------");


}
// Relay wired as normally open low activation
CAYENNE_IN(1)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay1, LOW);
  } else {
    digitalWrite(Relay1, HIGH);
  }
}
CAYENNE_IN(2)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay2, LOW);
  } else {
    digitalWrite(Relay2, HIGH);
  }
}
CAYENNE_IN(3)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay3, LOW);
  } else {
    digitalWrite(Relay3, HIGH);
  }
}
CAYENNE_IN(4)
{
  int status = getValue.asInt();

  if (status == 0) {
    digitalWrite(Relay4, LOW);
  } else {
    digitalWrite(Relay4, HIGH);
  }
}
CAYENNE_IN(5)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay5, LOW);
  } else {
    digitalWrite(Relay5, HIGH);
  } 
}
CAYENNE_IN(6)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay6, LOW);
  } else {
    digitalWrite(Relay6, HIGH);
  }
}

CAYENNE_IN(7)
{
  int status = getValue.asInt();
  if (status == 0) {
    digitalWrite(Relay7, LOW);
  } else {
    digitalWrite(Relay7, HIGH);
  }
}
CAYENNE_IN(8)
{
  int status = getValue.asInt(); 
  if (status == 0) {
    digitalWrite(Relay8, LOW);
  } else {
    digitalWrite(Relay8, HIGH);
  }
}

I dont see any error mentioned.
My shot in the dark is that you are using SPI interface the wrong way because of NodeMCU pins assigment.

You have defined for relays
#define Relay5 D5
#define Relay6 D6
#define Relay7 D7
#define Relay8 D8

This pins are hardware SPI on NodeMCU, since you did not deffine “software” pins in code.
All above writen by assumption your BME is on SPI type of connection

welcome to the cayenne Community @andrew.tann.
First of all try connecting BME280 to your nodemcu with a plain sketch and get reading in your serial monitor https://github.com/DFRobot/DFRobot_BME280/blob/master/examples/basicTestI2C/basicTestI2C.ino @Agroelektronik i think he is using i2c and his code is incomplete. connect BME280 SCL to D1(GPIO 5) and SDA to D2(GPIO 4).

Thanks for replying.

Forgot to post the error sorry.


Linking everything together…
“C:\Users\andre\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc” -g -w -Os -nostdlib -Wl,–no-check-sections -u call_user_start -u _printf_float -u _scanf_float -Wl,-static “-LC:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1/tools/sdk/lib” “-LC:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1/tools/sdk/ld” “-LC:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1/tools/sdk/libc/xtensa-lx106-elf/lib” “-Teagle.flash.4m1m.ld” -Wl,–gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o “C:\Users\andre\AppData\Local\Temp\arduino_build_248526/Irrigation_code_Final_weatherBME.ino.elf” -Wl,–start-group “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\sketch\Irrigation_code_Final_weatherBME.ino.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\CayenneHandlers.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\CayenneMQTTClient\CayenneMQTTClient.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\CayenneMQTTClient\MQTTClient.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\CayenneUtils\CayenneDataArray.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\CayenneUtils\CayenneUtils.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTConnectClient.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTDeserializePublish.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTPacket.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTSerializePublish.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTSubscribeClient.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\MQTTCommon\MQTTUnsubscribeClient.c.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\CayenneMQTT\Platform\Arduino\MQTTArduino.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFi.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFiAP.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFiGeneric.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFiMulti.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFiSTA.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\ESP8266WiFiScan.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\WiFiClient.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\WiFiClientSecure.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\WiFiServer.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\WiFiServerSecure.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\ESP8266WiFi\WiFiUdp.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\Wire\Wire.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\DFRobot_BME280-master\DFRobot_BME280.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526\libraries\SPI\SPI.cpp.o” “C:\Users\andre\AppData\Local\Temp\arduino_build_248526/arduino.ar” -lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,–end-group “-LC:\Users\andre\AppData\Local\Temp\arduino_build_248526”
C:\Users\andre\AppData\Local\Temp\arduino_build_248526/arduino.ar(core_esp8266_main.cpp.o):(.text._ZL12loop_wrapperv+0x4): undefined reference to `loop’

C:\Users\andre\AppData\Local\Temp\arduino_build_248526/arduino.ar(core_esp8266_main.cpp.o): In function `loop_wrapper’:

C:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\cores\esp8266/core_esp8266_main.cpp:57: undefined reference to `loop’

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for “CayenneMQTTESP8266.h”
Used: C:\Users\andre\OneDrive\Documents\Arduino\libraries\CayenneMQTT
Not used: C:\Users\andre\OneDrive\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\andre\OneDrive\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\andre\OneDrive\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\andre\OneDrive\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Using library CayenneMQTT at version 1.2.0 in folder: C:\Users\andre\OneDrive\Documents\Arduino\libraries\CayenneMQTT
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi
Using library Wire at version 1.0 in folder: C:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\Wire
Using library DFRobot_BME280-master in folder: C:\Users\andre\OneDrive\Documents\Arduino\libraries\DFRobot_BME280-master (legacy)
Using library SPI at version 1.0 in folder: C:\Users\andre\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\SPI
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).


From what I can determine the error has somethignto do with the loop ‘undefined reference to `loop’
But I cannot get past that.

I’ve hopefully fixed the SPI connection and removed the virtual pins, but am still getting the same error.

Here is the updated code (excluding the relay controls as I already know this works.


#include <CayenneMQTTESP8266.h>
#include <SPI.h>
#include “cactus_io_BME280_SPI.h”

//Pins called from GPIO pin mumbers not printed pin numbers
#define Relay1 5
#define Relay2 4
#define Relay3 0
#define Relay4 2
#define Relay5 14
#define Relay6 12
#define Relay7 13
#define Relay8 15
#define BME_SCK 16 // Serial Clock (D0)
#define BME_MISO 3 // Serial Data Out (D7)
#define BME_MOSI 1 // Serial Data In (Tx)
#define BME_CS 10 // Chip Select (SD3)

BME280_SPI bme(BME_CS,BME_MOSI,BME_MISO,BME_SCK);

// WiFi network info.
char ssid = “”;
char wifiPassword = “”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “”;
char password = “”;
char clientID = “”;

void setup()
{
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, HIGH);
digitalWrite(Relay8, HIGH);

Serial.println(“Bosch BME280 Barometric Pressure - Humidity - Temp Sensor | cactus.io”);

if (!bme.begin()) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}

bme.setTempCal(-1);

Serial.println(“Pressure\tHumdity\t\tTemp\t\tTemp”);

Cayenne.loop();

{

bme.readSensor();

Serial.print(bme.getPressure_MB()); Serial.print("\t\t");    // Pressure in millibars
Serial.print(bme.getHumidity()); Serial.print("\t\t");
Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");

// add a 2 second delay to slow down the output
delay(2000);

}


Hey, thanks for the, welcome and reply

I’ve since removed the I2c, as I realised it was incomplete and not an area i’ve done a lot with/confident with.
I’ll try a plain sketch and see how I go. I also updated the library awy from DFRobot to Cactus.io, as I find it a bit more intuitive.
Will update after the plain sketch

Cheers
Andrew

made changes to your code:

#include <CayenneMQTTESP8266.h>
#include <SPI.h>
#include “cactus_io_BME280_SPI.h”

//Pins called from GPIO pin mumbers not printed pin numbers
#define Relay1 5
#define Relay2 4
#define Relay3 0
#define Relay4 2
#define Relay5 14
#define Relay6 12
#define Relay7 13
#define Relay8 15
#define BME_SCK 16 // Serial Clock (D0)
#define BME_MISO 3 // Serial Data Out (D7)
#define BME_MOSI 1 // Serial Data In (Tx)
#define BME_CS 10 // Chip Select (SD3)

BME280_SPI bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);

// WiFi network info.
char ssid[] = “”;
char wifiPassword[] = “”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “”;
char password[] = “”;
char clientID[] = “”;

void setup()
{
  Serial.begin(115200);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT);
  pinMode(Relay5, OUTPUT);
  pinMode(Relay6, OUTPUT);
  pinMode(Relay7, OUTPUT);
  pinMode(Relay8, OUTPUT);
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
  digitalWrite(Relay3, HIGH);
  digitalWrite(Relay4, HIGH);
  digitalWrite(Relay5, HIGH);
  digitalWrite(Relay6, HIGH);
  digitalWrite(Relay7, HIGH);
  digitalWrite(Relay8, HIGH);

  Serial.println(“Bosch BME280 Barometric Pressure - Humidity - Temp Sensor | cactus.io”);

  if (!bme.begin()) {
    Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
    while (1);
  }
}
void loop() {


  Cayenne.loop();


  bme.setTempCal(-1);

  Serial.println(“Pressure\tHumdity\t\tTemp\t\tTemp”);



  bme.readSensor();

  Serial.print(bme.getPressure_MB()); Serial.print("\t\t");    // Pressure in millibars
  Serial.print(bme.getHumidity()); Serial.print("\t\t");
  Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");

  // add a 2 second delay to slow down the output
  delay(2000);
}