Grow box problem

Oh lawd :sweat_smile: cant compile it right now, im on my phone… Im using a particle photon and particle IDE on build.particle.io

@Jamin yeah i ordered some of those little bugs you were talking about, still waiting…

Edit: the example on particle ide is this, i think its similar to simpletimer…

// Spark Interval Timer demo
//
// Please refer to the github README file for more details:
// https://github.com/pkourany/SparkIntervalTimer/blob/master/README.md
//
// This demo will create several Interval Timers (3 on Core, 5 on Photon) to blink 
// LEDs at different intervals.  The first timer will blink the onboard LED
// while extra LEDs (and small current limiting resistors) must be added
// by the user on pins D3 and D4 (Core) and additionally on D5 and D6 for Photon.
// After 100 blinks, Timer1 will reset to 1/4 of its interval and after 200 more
// blinks, Timer1 is shut down and will stop blinking.


#include "SparkIntervalTimer/SparkIntervalTimer.h"

SYSTEM_MODE(MANUAL);		//For this demo, WiFi and Cloud connections are disabled

// Create IntervalTimer objects
IntervalTimer myTimer;		// 3 for the Core
IntervalTimer myTimer2;
IntervalTimer myTimer3;
#if (PLATFORM_ID == 6)		// 2 more for the Photon
IntervalTimer myTimer4;
IntervalTimer myTimer5;
#endif

// Pre-declare ISR callback functions
void blinkLED(void);
void blinkLED2(void);
void blinkLED3(void);
#if (PLATFORM_ID == 6)		// Extras for Photon
void blinkLED4(void);
void blinkLED5(void);
#endif

const uint8_t ledPin = D7;		// LED for first Interval Timer
const uint8_t ledPin2 = D3;		// LED for second Interval Timer
const uint8_t ledPin3 = D4;		// LED for third Interval Timer
#if (PLATFORM_ID == 6)			// Extras for Photon
const uint8_t ledPin4 = D5;
const uint8_t ledPin5 = D6;
#endif

void setup(void) {
  pinMode(ledPin, OUTPUT);		// Configure LED pins as OUTPUTs
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
 #if (PLATFORM_ID == 6)			//Extras for Photon
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
#endif
  
  // AUTO allocate blinkLED to run every 500ms using hmSec timescale (1000 * 0.5ms period)
  // On Core the first allocated timer is TIMER2.  On Photon, it is TIMER3.
  myTimer.begin(blinkLED, 1000, hmSec);

  // Manually allocate blinkLED2 to hardware timer TIMER4 to run every 250ms using hmSec timescale (500 * 0.5ms period)
  // TIMER4 is common to both Core and Photon.
  myTimer2.begin(blinkLED2, 500, hmSec, TIMER4);
  
  // Auto allocate blinkLED3 to run every 1000ms using hmSec timescale (2000 * 0.5ms period)
  // On Core allocated timer will be first free = TIMER3.  On Photon, it will be TIMER5.
  myTimer3.begin(blinkLED3, 2000, hmSec);
  
#if (PLATFORM_ID == 6)
  // Auto allocate blinkLED4 to run every 65ms using uSec timescale (65000 * 1us period)
  // On Photon (only) allocated timer will be next free = TIMER6.
  myTimer4.begin(blinkLED4, 65000, uSec);
  
  // Manually allocate blinkLED5 to hardware timer TIMER7 blinkLED to run every 5000ms (10000 * .5ms period)
  myTimer5.begin(blinkLED5, 10000, hmSec, TIMER7);
#endif
}

// The first TIMER (myTimer) interrupt will blink the LED, and keep
// track of how many times it has blinked.  After 200 on/off cycles
// the timer interval will be changed to 125ms (250 * 0.5ms).
// After a further 200 pulses, the timer will be shut down.
// All other timers only blink their associated LEDs

volatile unsigned long blinkCount = 0; // use volatile for variables shared with ISR

// functions called by IntervalTimer should be short, run as quickly as
// possible, and should avoid calling other functions if possible.

// Callback for Timer 1
void blinkLED(void) {
	digitalWrite(ledPin,!digitalRead(ledPin));
    blinkCount++;		// increase when LED turns changes
}

// Callback for Timer 2
void blinkLED2(void) {
	digitalWrite(ledPin2,!digitalRead(ledPin2));
}

// Callback for Timer 3
void blinkLED3(void) {
	digitalWrite(ledPin3,!digitalRead(ledPin3));
}

 #if (PLATFORM_ID == 6)		// Extras for the Photon
// Callback for Timer 4
void blinkLED4(void) {
	digitalWrite(ledPin4,!digitalRead(ledPin4));
}

// Callback for Timer 5
void blinkLED5(void) {
	digitalWrite(ledPin5,!digitalRead(ledPin5));
}
#endif


void loop(void) {

  if (blinkCount == 200)	{			// After 200 on/off cycles, change first timer interval
  							// to 125ms (250 * 0.5ms) for next 200 cycles.
    blinkCount++;					// increment count so IF does not trigger again
	myTimer.resetPeriod_SIT(250, hmSec);
	}
  else if (blinkCount >= 400) {				// After 200 more on/off cycles, shut down first timer
  	blinkCount = 0;					// reset count so IF does not keep passing
	myTimer.end();					// Disable the first timer
	}
}

There is a simple rule to follow when smth doesn’t work. Roll back to the bare minimum

Try if you can compile their initial example sketch that comes with a polled timer library.

3 Likes

@Jamin @Pavel thanks once again to both of you for helping me, but i cant seem to get a connection between the nodemcu and blynk… the code is the same as @Jamin posted, i added to debugg lines although and i get stuck here using the arduino IDE serial monitor :

rll��|�l�|�l�b|����r�b�b��nn�lnn���bp��lrlrlp�n��l��bn�|l��b��nn�l��l`�nnl`nr���nb�lr��nb�l�r���l�l`��n�[321] Connecting to SSID

and in the app i get either “reconnecting to server” or “nodemcu is not connected to the server”…
any thoughts why this is happening?

thank you

edit: im using a nodemcu 12-E, arduino IDE with the blynk library 0.3.10, 115200 baud

@bernas_123 just saw that you may not have updated your own SSID and password settings?

change this line:

Blynk.begin(auth, "SSID", "PASS");

and enter the SSID and password for your own WIFI :slight_smile:

yeah got that working :smile: but i think something might be wrong with the code since im not getting any readings nor being able to activate the relays using Vpins, only if i set the buttons to the corresponding digital pins…

code:

#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
/* DEFINITIONS */
#define ledRelay   1    // D1 pin output to Lighting LED's relay (
#define fanRelay   2    // D2 pin output to Extraction Fan relay
#define heatRelay  3    // D3 pin output to Heating relay
#define DHTPIN     4    // D4 pin input from DHT11
#define DHTTYPE DHT11
/* VIRTUAL PORTS */
#define UPTIME_vPIN           0
#define MOIST_BRK_PNT_vPIN    2
#define TEMP_BRK_PNT_LO_vPIN  3
#define TEMP_BRK_PNT_HI_vPIN  4
#define SHUTDOWN_BTN_vPIN     5
#define EXTRACT_BTN_vPIN      6
#define LIGHTING_BTN_vPIN     7
#define HEAT_BTN_vPIN         8
#define HUMID_vPIN           20
#define LIGHTING_vPIN        22
#define HEATING_vPIN         24
#define EXTRACT_vPIN         25
#define TEMP_vPIN            26
#define SHUTDOWN_vPIN        28
/* LIBRARY CMDS */
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer0;
SimpleTimer timer1;
/* AUTH CODE BLYNK */
char auth[] = "fb56674e852a4e60981c49b3c569a6f6";
/*******************************************************************************************************/
/* GLOBAL VAR DEFINE - Enter default values in setup */
bool shutdownButton;
float humid;
float temp;
int moistureBreakpoint;
bool extractionInProgress;
int moistureValueVirtual;
bool extractionButton;
int temperatureBreakpointLow;
int temperatureBreakpointHigh;
bool heatingInProgress;
bool heatingButton;
bool lightingButton;
/*******************************************************************************************************/
void setup() {
  /* SET PINMODE */
  pinMode(ledRelay, OUTPUT); //Output for LED Lighting relay
  pinMode(fanRelay, OUTPUT); //Output for Extraction fan relay
  pinMode(heatRelay, OUTPUT); //Output for Heater relay
  pinMode(DHTPIN, INPUT); //Input for the DHT pin
  /* SET DEFAULT VAR VALUES */
  shutdownButton = 1;
  moistureBreakpoint = 60;
  extractionInProgress = false;
  extractionButton = 0;
  temperatureBreakpointLow = 20;
  temperatureBreakpointHigh = 23;
  heatingInProgress = false;
  heatingButton = 0;
  lightingButton = 0;
  /* START COMMUNICATION */
  Serial.begin(115200);
  while (!Serial) {
    ;
  }
  Blynk.begin(auth, "coiso", "coiso");
  while (Blynk.connect() == false) {
    ;
  }
  /* START LIBRARIES */
  dht.begin();
  timer0.setInterval(2000L, growBoxMaster);
  timer1.setInterval(1000L, sendUptime);
  /* DONE SETTING UP */

}
/*******************************************************************************************************/
BLYNK_WRITE(MOIST_BRK_PNT_vPIN) {
  moistureBreakpoint = param.asInt();
}
BLYNK_WRITE(TEMP_BRK_PNT_LO_vPIN) {
  temperatureBreakpointLow = param.asInt();
}
BLYNK_WRITE(TEMP_BRK_PNT_HI_vPIN) {
  temperatureBreakpointHigh = param.asInt();
}
BLYNK_WRITE(SHUTDOWN_BTN_vPIN) {
  shutdownButton = param.asInt();
}
BLYNK_WRITE(EXTRACT_BTN_vPIN) {
  extractionButton = param.asInt();
}
BLYNK_WRITE(LIGHTING_BTN_vPIN) {
  lightingButton = param.asInt();
}
BLYNK_WRITE(HEAT_BTN_vPIN) {
  heatingButton = param.asInt();
}
/*******************************************************************************************************/
void sendUptime() {
  Blynk.virtualWrite(UPTIME_vPIN, millis() / 1000);
}

void growBoxMaster() {
  dhtReadings();
  shutdownMaster();
  moistureMaster();
  heatingMaster();
  lightingMaster();
}

// Get Readings
void dhtReadings() {
  humid = dht.readHumidity();
  temp  = dht.readTemperature();
  if (isnan(humid) || isnan(temp) ) {
    return;
  }
  Blynk.virtualWrite(HUMID_vPIN, humid);
  Blynk.virtualWrite(TEMP_vPIN, temp);
}


void shutdownMaster()
{
  Serial.println("------- ShutdownMaster started -------");
  if (!shutdownButton)  {
    digitalWrite(ledRelay, LOW);
    digitalWrite(fanRelay, LOW);
    digitalWrite(heatRelay, LOW);
    Blynk.virtualWrite(SHUTDOWN_vPIN, 1023);
    Serial.println("SHUTDOWN");
  }
  Serial.print("shutdownButton - ");
  Serial.println(shutdownButton);
}

void moistureMaster() {
  Serial.println("------- moistureMaster started -------");

  if ((humid > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = HIGH))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = LOW))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid < moistureBreakpoint) && (extractionInProgress) && (extractionButton = HIGH))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid < moistureBreakpoint) && (extractionInProgress) && (extractionButton = LOW))  {
    extractionInProgress = false;
    stopExtraction();
  }

  Serial.print("humid - ");
  Serial.println(humid);

  Serial.print("extractionInProgress - ");
  Serial.println(extractionInProgress);

  Serial.print("moistureBreakpoint - ");
  Serial.println(moistureBreakpoint);

}

void startExtraction()
{
  digitalWrite(fanRelay, HIGH);
  Blynk.virtualWrite(EXTRACT_vPIN, 1023);
  Serial.println("Extraction - started");
}

void stopExtraction()
{
  digitalWrite(fanRelay, LOW);
  Blynk.virtualWrite(EXTRACT_vPIN, 0);
  Serial.println("Extraction - stoped");
}




void heatingMaster()
{
  Serial.println("------- heatingMaster started -------");

  if ((temp < temperatureBreakpointLow) && (!heatingInProgress) && (!heatingButton))  {
    heatingInProgress = true;
    startHeating();
  }
  else if ((temp < temperatureBreakpointLow) && (!heatingInProgress) && (heatingButton))  {
    heatingInProgress = false;
    stopHeating();
  }
  else if ((temp >= temperatureBreakpointHigh) && (heatingInProgress) && (!heatingButton))  {
    heatingInProgress = false;
    stopHeating();
  }
  else if ((temp >= temperatureBreakpointHigh) && (heatingInProgress) && (heatingButton))  {
    heatingInProgress = true;
    startHeating();
  }

  Serial.print("temp - ");
  Serial.println(temp);

  Serial.print("heatingInProgress - ");
  Serial.println(heatingInProgress);

  Serial.print("temperatureBreakpointLow - ");
  Serial.println(temperatureBreakpointLow);

  Serial.print("temperatureBreakpointHigh - ");
  Serial.println(temperatureBreakpointHigh);

  Serial.print("heatingButton - ");
  Serial.println(heatingButton);
}


void startHeating(){
  digitalWrite(heatRelay, HIGH);
  Blynk.virtualWrite(HEATING_vPIN, 1023);
  Serial.println("Heating - started");
}

void stopHeating(){
  digitalWrite(heatRelay, LOW);
  Blynk.virtualWrite(HEATING_vPIN, 0);
  Serial.println("Heating - stoped");
}

void lightingMaster()
{
  Serial.println("------- lightingMaster started -------");
  if (!lightingButton)  {
    digitalWrite(ledRelay, HIGH); 
    Blynk.virtualWrite(LIGHTING_vPIN, 1023);
    Serial.println("Lighting - started");
  }
  else if (lightingButton)  {
    digitalWrite(ledRelay, LOW); 
    Blynk.virtualWrite(LIGHTING_vPIN, 0);
    Serial.println("Lighting - stopped");
  }
  Serial.print("lightingButton - ");
  Serial.println(lightingButton);
}

/*******************************************************************************************************/
void loop()
{
  Blynk.run();
  timer0.run();
  timer1.run();
}

serial(it continues with the same thing):

load 0x4010f000, len 1384, room 16 
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
Lighting - started
lightingButton - 0
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
Lighting - started
lightingButton - 0
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
Lighting - started
lightingButton - 0
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0

Have you considered, just for the sake of trying, to put BLYNK_WRITE(V0) etc. instead of using defines? I’m pretty sure it doesn’t matter, but just to confirm it’s not some sort of weird bug.

@bernas_123, @Lichtsignaal might be correct. Try adding the V to the defines.

I have never had the issue myself but worth a try.

#define MOIST_BRK_PNT_vPIN    V2

hey guys still doesnt work… i dont getting any reading or any action from the buttons…

[5315] Connected to WiFi
[5315] IP: 192.168.1.89
[5315] Blynk v0.3.10 on NodeMCU
[5316] Connecting to blynk-cloud.com:8442
[5406] <[02|00|01|00] fb56674e852a4e60981c49b3c569a6f6
[5465] >[00|00|01|00]�
[5466] Ready (ping: 1ms).
[5466] <[11|00|01|00]Hver[00]0.3.10[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]NodeMCU[00]build[00]Oct 15 2016 13:02:05[00]
[5530] >[00|00|01|00]�
[6530] <[14|00|02|00|06]vw[00]0[00]6
[6909] >[14|02]{[00|05]
[6910] >vr[00]20
[7001] >[14|02]|[00|05]
[7001] >vr[00]26
[7530] <[14|00|03|00|06]vw[00]0[00]7
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
[7894] <[14|00|04|00|0A]vw[00]22[00]1023
Lighting - started
lightingButton - 0
[8530] <[14|00|05|00|06]vw[00]0[00]8
[8805] >[14|02]�[00|05]
[8805] >vr[00]20
[8806] >[14|02]�[00|05]
[8806] >vr[00]26
[9530] <[14|00|06|00|06]vw[00]0[00]9
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
[9899] <[14|00|07|00|0A]vw[00]22[00]1023
Lighting - started
lightingButton - 0
[9999] >[14|02]�[00|05]
[9999] >vr[00]20
[9999] >[14|02]�[00|05]
[9999] >vr[00]26
[10530] <[14|00|08|00|07]vw[00]0[00]10
[10946] >[14|02]�[00|05]
[10947] >vr[00]20
[10993] >[14|02]�[00|05]
[10994] >vr[00]26
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
[11550] <[14|00|09|00|0A]vw[00]22[00]1023
Lighting - started
lightingButton - 0
[11687] <[14|00|0A|00|07]vw[00]0[00]11
[12530] <[14|00|0B|00|07]vw[00]0[00]12
[13013] >[14|02]�[00|05]
[13013] >vr[00]20
[13014] >[14|02]�[00|05]
[13014] >vr[00]26
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
[13820] <[14|00|0C|00|0A]vw[00]22[00]1023
Lighting - started
lightingButton - 0
[13877] <[14|00|0D|00|07]vw[00]0[00]13
[14530] <[14|00|0E|00|07]vw[00]0[00]14
[14847] >[14|02]�[00|05]
[14848] >vr[00]20
[14848] >[14|02]�[00|05]
[14848] >vr[00]26
------- ShutdownMaster started -------
shutdownButton - 1
------- moistureMaster started -------
humid - nan
extractionInProgress - 0
moistureBreakpoint - 60
------- heatingMaster started -------
temp - nan
heatingInProgress - 0
temperatureBreakpointLow - 20
temperatureBreakpointHigh - 23
heatingButton - 0
------- lightingMaster started -------
[15820] <[14|00|0F|00|0A]vw[00]22[00]1023
Lighting - started
lightingButton - 0
[15990] <[14|00|10|00|07]vw[00]0[00]15
[16046] >[14|02]�[00|05]
[16046] >vr[00]20
[16047] >[14|02]�[00|05]
[16047] >vr[00]26
[16530] <[14|00|11|00|07]vw[00]0[00]16
[16993] >[14|02]�[00|05]
[16993] >vr[00]20
[17044] >[14|02]�[00|05]
[17044] >vr[00]26
[17530] <[14|00|12|00|07]vw[00]0[00]17

EDIT: the relays trigger if i set the button to digital pins…

also a strange thing happens when i go to the homescreen and return, the app keeps sayng that is reconnecting to the server even if the nodemcu is not connected to a power source

anyone has any idea what could be the problem? it’s so close…:sweat:

roll back to simples, just get your DHT11 to give you something besides NAN - then add more, then add more…

Whats Nan? Do you think theres a problem with the dht that is messing with the code flow? The strange thing is that none of the virtual pins work and blynk keeps reconnecting when i return to the app, having to restart for it to work…

NaN is an indication that the sensor has not read a value. DHT needs lots of time to proces the data it receives, so use the SimpleTimer to read the DHT every 10s for example (which is al ready way too often if you ask me, but ok, for arguments sake :wink: ). Now it should return a value. If it doesn’t, try another Pin.

Also, try an example from the DHT library and run it stand alone, just to confirm your sensor is working properly and the wiring is OK.

NaN is “not a number”