NodeMCU resource cannot be turned on, will turn off automatically

Currently, I am working on using NodeMCU to turn on an pin, for example pin D5, to activate a pin on the other device (such as Arduino UNO). I am using Bluetooth to send the status of D5 to UNO. Then UNO will read the status and turn on some pins instead.

NodeMCU is connected to Thinger. However, I am not able to turn on D5 from dashboard. When i try to turn on, the value will automatically switch to off state.

Instead, when I am trying to turn on pin D5 from devices API, I am able to do so. Call anyone tell me why is this happening?

Hi, check this:

I dont remember specific if this board has inverted logic (with a HIGH instruction gives a LOW output an viceversa) if is this the case, you may define to control the pins by:
thing["LED"] < < invertedDigitalPin(9);

And with that with a HIGH instruction will give a HIGH output.

Hope this helps.

Thank you ega,

I remember nodeMCU is just having inverted logic for the BUILTIN LED, I don’t remember the normal GPIOs have inverted logic.

But still, I will try the solution tomorrow and update my progress here.

I remember the same, that at least the led has inverted logic,

In any case, the worst case is that the device should work inverted, when is triggered by the widget.

Let us know how it goes.

Regards.

below is my code.
I have tried the inverted pin that you have suggested. It doesnt fix the issue. I still can turn on LED using device API, but not through dashboard. Can I know what to do?

//wired communication using serial test 

/*---------------THINGER PART-------------------*/
#define _DEBUG_
//only works when disable TLS
#define _DISABLE_TLS_
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>

//CREDENTIALS
#define USERNAME "xxx"
#define DEVICE_ID "xxx"
#define DEVICE_CREDENTIAL "xxx"

//new house Free Wifi - xxx
//old house GSH WIFI - xx

#define SSID "Free wifi"
#define SSID_PASSWORD "xx"

/*----------Thinger credentials----------*/
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

//D6 as receive info pin
#define led_pin D6

/*--------------------SERIAL COMM--------------------*/
#include <SoftwareSerial.h>
SoftwareSerial nodemcuserial(D1,D2); //RX, TX

void setup() {
  //open SM (nodemcu-PC)
  Serial.begin(9600);

  //open SM (nodemcu-arduino)
  nodemcuserial.begin(38400);

  pinMode(led_pin, OUTPUT);

/////////////////////////////////////////////////////////////////
  thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["led"] << [](pson& in)
  {
    digitalWrite(led_pin, in ? LOW : HIGH); //as you told me I have inverted the logic** 
  }

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
  sendtoarduino();

}

//void sendtoarduino()
{
  int data1 = digitalRead(led_pin);

    //print to PC
    Serial.print(data1);            Serial.print("A");
    Serial.print('\n');

   //print to Arduino
    nodemcuserial.print(data1);    nodemcuserial.print("A");
    nodemcuserial.print('\n');
    
    delay(100); //might cause problem here
  
}

Hi, I guess the issue is in the widget setup, if it works without issues from the API, the issue is not in the microcontroller’s code.

Have you checked the previous link I sent?

Thank you for being patient with me.

I had followed the steps you told me. But I am having problems to turn on multiple LEDs at once.

I feel like asking some stupid questions. But please do enlighten me.

If I would like to turn on 3 LEDs, should my execution code be like this?

thing[“led1”] << digitalPin(led1);
thing[“led2”] << digitalPin(led2);
thing[“led3”] << digitalPin(led3);

I find myself to be able to turn on 1 led but not the others. I am curious whether this is because of my coding. Can you please help me on this?

Hi, no worries, that’s why we are here

First of all, could you made it work to turn on and off one led?

Another question, do you want to turn on and of the led at the same time or independent?

Yes, I am able to turn on 1 LED. using commands similar to
thing[“led1”] << digitalPin(led1);

For now, I would like to turn on 3 LEDs separately using dashboard of Thinger.
This is the code that I have used.

thing[“led1”] << digitalPin(led1);
thing[“led2”] << digitalPin(led2);
thing[“led3”] << digitalPin(led3);

I am able to create widgets named led2 and led3 in the dashboard, but I am not able to turn on the resource of led2 and led3. Not sure why. It will turn off automatically.

This is the video showing what I’m experiencing. I think it might be I have used the wrong code. But I have followed the coding guide, so what did I miss?

https://drive.google.com/file/d/1A0-KWh9YTIxu21NUL6VTaJLMzOf3RQt2/view?usp=drivesdk

Hi,
Ok share the whole code in the right way to check it what could be wrong.

Regards

So here is my code

/*---------------THINGER PART-------------------*/
#define _DEBUG_
//only works when disable TLS
#define _DISABLE_TLS_
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>

//CREDENTIALS
#define USERNAME "JinHang"
#define DEVICE_ID "nodemcu"
#define DEVICE_CREDENTIAL "xxx"

#define SSID "Free wifi"
#define SSID_PASSWORD "xxx"

/*-----------------Thinger credentials-----------------*/
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

#define led_pin   D0
#define led_pin2 D1
#define led_pin3 D2

/*--------------------SERIAL COMM--------------------*/
//#include <SoftwareSerial.h>
//SoftwareSerial nodemcuserial(D7,D8); //RX, TX

///*-----------------------MILLIS-----------------------*/
//unsigned long currenttime, previoustime;
//const int elapsedtime = 45;

void setup()
{
  //open SM (nodemcu-PC)
  Serial.begin(9600);

  //open SM (nodemcu-arduino slave)
  //nodemcuserial.begin(38400);

  pinMode(led_pin, OUTPUT);

/----------------------------------------------------------------------------/
thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  
  //1st led to turn on
  pinMode(led_pin,OUTPUT); 
  thing["led1"] << [](pson &in){
  digitalWrite(led_pin, in ? HIGH : LOW);};

  //2nd thing to turn on 
  pinMode(led_pin2,OUTPUT); 
  thing["led2"] << [](pson &in){
  digitalWrite(led_pin2, in ? HIGH : LOW);};

  //3rd thing to turn on 
  thing["led3"] << digitalPin(led_pin3);

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());
}

void loop() 
{
  thing.handle();
}

I used different variations of lighting up 3 LED, the 2nd and 3rd LED wont light up (it will turn off immediately). The first LED can light up, unfortunately it is not very stable, sometimes it doesnt even light up.

Hi, try this definition, the 3rd led’s pin was not defined as an output, by this way the three leds should work according the api, maybe with inverted logic, I dont know, try and let me know how it goes

  pinMode(led_pin,OUTPUT); 
  pinMode(led_pin2,OUTPUT); 
  pinMode(led_pin3,OUTPUT); 

  thing["led1"] << digitalPin(led_pin);
  thing["led2"] << digitalPin(led_pin2);
  thing["led3"] << digitalPin(led_pin3);

Hope this helps