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?
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.
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
}
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?
// 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