NodeMCU 0.9 (ESP-12 Module) and serial monitoring help

I am having issues getting serial monitoring to work:
upload: 115200
Board: NodeMCU 0.9 (ESP-12 Module)
IDE: 1.8.8
Lib: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Is there an issue with the code preventing serial monitoring ? I need to adjust the digital write values on the moisture sensors however with out the serial monitoring it's been a cumbersome task.

I appreciate any feedback or help.

Thanks!

/****************************************
   Define Constants
 ****************************************/
#define sensor    A0       // Hook water sensor to pin A0 of NODEMCU module
#define LED       D2       // Led signals to relay that illuminates strobe LED
/****************************************
   Auxiliar Functions
 ****************************************/

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

/****************************************
   Main Functions
 ****************************************/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(sensor, INPUT);   // Analog pin setup for read
  pinMode(LED, OUTPUT);    // LED pin as output for strobe LED circuit 

}

void loop() {
  float adcValue = analogRead(sensor);    // Read the ADC channel
//adjust adcValue so LED illuminates as needed. 
  if (adcValue > 400){
    digitalWrite(LED, HIGH);
  }
  if (adcValue < 200){
    digitalWrite(LED, LOW);
  }

}

How is your callback function getting called?

void callback(char* topic, byte* payload, unsigned int length)

From the parameters this looks like an MQTT callback function but there is no mention of MQTT in the sketch

Test to print on serial monitor whatever you type

#define LED 2
char c ;


void setup() {
  Serial.begin(115200) ;
  Serial.println(".... initializing ....") ;
  pinMode(LED, OUTPUT) ;
}

void loop() {
  if(Serial.available() ) {
    c = Serial.read() ;
    Serial.print ( c ) ;
    digitalWrite( LED, ! digitalRead(LED) ) ;
  }
}

I get an error ?

/****************************************
Define Constants
/
#define sensor A0 // Hook water sensor to pin A0 of NODEMCU module
#define LED D2 // Led signals to relay that illuminates strobe LED
/

Auxiliar Functions
****************************************/

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}

/****************************************
Main Functions
****************************************/

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(sensor, INPUT); // Analog pin setup for read
pinMode(LED, OUTPUT); // LED pin as output for strobe LED circuit

}

void loop() {
float adcValue = analogRead(sensor); // Read the ADC channel
//adjust adcValue so LED illuminates as needed.
if (adcValue > 400){
digitalWrite(LED, HIGH);
}
if (adcValue < 200){
digitalWrite(LED, LOW);
}

}

Arduino: 1.8.8 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

20211025-1_Simplex:41:6: error: redefinition of 'void setup()'
41 | void setup() {
| ^~~~~
Arduino\20211025-1_Simplex\20211025-1_Simplex.ino:23:6: note: 'void setup()' previously defined here
23 | void setup() {
| ^~~~~
20211025-1_Simplex:49:6: error: redefinition of 'void loop()'
49 | void loop() {
| ^~~~
Arduino\20211025-1_Simplex\20211025-1_Simplex.ino:29:6: note: 'void loop()' previously defined here
29 | void loop() {
| ^~~~
exit status 1
redefinition of 'void setup()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You do?
What does it say?

How many setup() and loop() functions have you got in your sketch and how many tabs have you got in the current sketch in the IDE ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.