BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Polling Adafruit Stemma Soil Sensor seems to break my code

• Adafruit Bluefruit 32u4 + Adafruit Stemma Soil Sensor
• Using Blynk for IOS latest version (Not-beta)
• Latest Blynk Library

I have verified that the Bluefruit and the Stemma soil sensor work. I am able to connect to the Bluefruit using the Blynk App and write to Virtual Pins if I just send millis(), as in the example or if I even send data from a DHT-11; however, as soon as I try to poll data from an Adafruit Stemma Soil Sensor and virtual write the data, it seems to break the project and I receive no data in the app. It seems that as soon as I introduce the code polling the soil sensor, even trying to virtual write millis() ceases to work. I had the same issue with an Arduino Uno and a HM-10 bluetooth module. I don’t know if it is because the Stemma Sensor uses SDA and SCL pins or what, but it is rather odd. Any help would be appreciated.


#define BLYNK_USE_DIRECT_CONNECT
//#define BLYNK_PRINT Serial

#include <BlynkSimpleSerialBLE.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BluefruitLE_SPI.h>
#include <SPI.h>

#include "Adafruit_seesaw.h"
Adafruit_seesaw SoilSensor;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXX";

// SHARED SPI SETTINGS (see adafruit webpages for details)
#define BLUEFRUIT_SPI_CS               8
#define BLUEFRUIT_SPI_IRQ              7
#define BLUEFRUIT_SPI_RST              -1    // Optional but recommended, set to -1 if unused
#define BLUEFRUIT_VERBOSE_MODE         true

// Create ble instance, see pinouts above
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

BlynkTimer timer;

void myTimerEvent(){
  float capc = map(SoilSensor.touchRead(0), 0, 1016, 0, 100);
  float temp = ((SoilSensor.getTemp())*1.8) + 32;

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from Stemma Soil sensor!");
    return;
  }
  
  Blynk.virtualWrite(V5, temp); 
  Blynk.virtualWrite(V3, capc); 
}


void setup() {
  Serial.begin(9600);
  ble.begin(BLUEFRUIT_VERBOSE_MODE);
  ble.factoryReset(); // Optional
  ble.setMode(BLUEFRUIT_MODE_DATA);
  
  Serial.println("Waiting for connections...");
  timer.setInterval(1000L, myTimerEvent);
  Blynk.begin(auth, ble);
}

void loop() {
  Blynk.run();
  timer.run();
}