NodeMCU 1.0 unable to power up when connected to small therm
Posted:
Mon Apr 13, 2020 8:59 am
by Eternyt
Hello,
I notice a strange problem (at least for my limited electronic knowledge) while putting all together my project. I decided to power up both the thermal printer and the NodeMCU 1.0 from the same PSU. Also, the RX and TX pins of the printer are already connected to the NodeMCU (the TX has the voltage divider to not damage the board). I'm using the Vin pin of the NodeMCU to power it up, not the 5V.
Now, when I power it up, the nodeMCU is unable to boot properly. If I disconnect the printer (so all 4 pins), power up, then reconnect the printer all work properly. Also, if the TX and RX pin are connected to the board, no matter what, the serial monitor of the NodeMCU is unusable. I attach a png of my schematic.
What can cause this problem?
Thanks in advance!
Re: NodeMCU 1.0 unable to power up when connected to small t
Posted:
Mon Apr 13, 2020 11:22 am
by Eternyt
I just realized that I didn't post the code.
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Adafruit_Thermal.h>
#include <SoftwareSerial.h> // This is a special one made for the esp, the standard one is in " " and not in < >
#define TX_PIN 15 // Arduino transmit labeled RX on printer
#define RX_PIN 13 // Arduino receive labeled TX on printer
#define FORMAT 15 // Number of carachter of the format variable
#define ARG 500 // Number of carachter of the arg variable
ESP8266WebServer server(80);
SoftwareSerial SoftwSerial; // I'm using the esp specific, not the Arduino one. It behaves slightly different
Adafruit_Thermal printer(&SoftwSerial);
const char* ssid = "MySsid";
const char* password = "MyPassword";
char stringCut[15][100] = {}; // At max this code can handle 15 endl, max 100 carachter
int posiz[15] = {};
int cont = 0, errore = 0;
/* This function is no longer in use
int countEndl(String str) {
int len = str.length();
int index = 0, cont = 0, tempor;
for (int i = 0; i < len; i++) {
tempor = str.indexOf("\n", index); // The endl is made from two different carachter
Serial.print("Position of endl: ");
Serial.println(tempor);
if (tempor > 0) {
// I need to save the position of every endl
posiz[cont] = tempor-2; // I'm saving the last carachter position before an endl
cont++;
index = tempor+1;
Serial.println("Cont++");
}
}
Serial.print("Numero di acapi trovati: ");
Serial.println(cont);
for (int z = 0; z < cont; z++) {
Serial.println(posiz[z]);
}
return cont;
}
*/
void DivideOnEndl(String str) {
char arg[ARG] = {};
str.toCharArray(arg, ARG); // Copy the string in a char array
char *index = NULL;
if ((index = strtok(arg, "\n")) != NULL) {
strcpy(stringCut[cont], index);
cont++;
while ((index = strtok(NULL, "\n")) != NULL && cont < 15) {
strcpy(stringCut[cont], index);
cont++;
}
}
/* Debug purpose only
Serial.println("Le stringhe sono così suddivise: ");
Serial.println(cont);
for (int i = 0; i < cont; i++) {
Serial.println(stringCut[i]);
}
*/
}
int print(String format, String arg) {
printer.wake();
printer.reset();
// printer.wake();
Serial.print("Format is: ");
Serial.println(format);
if (format == "plainText") {
Serial.println("Entering plainText function");
printer.print(arg);
printer.println(); // Feed two lines to make all the text came out
printer.println();
printer.println();
return 0; // Success
} else if (format == "dotted") { // Putting ° before every string
Serial.println("Entering dotted function");
DivideOnEndl(arg);
for (int i = 0; i < cont; i++) {
printer.print("° ");
printer.print(stringCut[i]); // There is still an ENDL, so no need to println
}
printer.println(); // Feed two lines to make all the text came out
printer.println();
printer.println();
cont = 0; // Reset the variable, otherwise the next time it will also print all the older print
return 0; // Success
} else if (format == "checkbox") { // Putting [] before every string
Serial.println("Entering checkbox function");
DivideOnEndl(arg);
for (int i = 0; i < cont; i++) {
printer.print("[ ] ");
printer.print(stringCut[i]); // There is still an ENDL, so no need to println
}
printer.println(); // Feed two lines to make all the text came out
printer.println();
printer.println();
cont = 0; // Reset the variable, otherwise the next time it will also print all the older print
printer.sleep();
return 0; // Success
} else {
Serial.println("Format not valid");
return 1;
}
}
void handleBody() {
// It receive the JSON data of the POST request
// server.send(200, "text/plain", "You are pointing at /printer ");
// Serial.print(server.arg("plain")); // Debug
if (server.hasArg("plain") == false) {
server.send(404, "text/plain", "The message was empty, or the server was unable to decode it.");
return; // Exit the function
}
if (server.method() != HTTP_POST) {
server.send(405, "text/plain", "Method not allowed");
return;
}
String message = "POST form was:\n";
String response = "Printing... \n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
// Print only if there is paper in the printer
if (printer.hasPaper()) {
errore = print(server.arg(0), server.arg(1));
} else {
errore = 2;
}
response += "Print error (0: succesful, 1: print error, 2: no paper): ";
response += errore;
response += "\n";
Serial.print(message);
server.send(200, "text/plain", response);
}
void handleNotFound() {
// digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
// digitalWrite(led, 0);
}
void setup() {
// delay(10*1000); // To patch a problem in the circuit
// For the printer
SoftwSerial.begin(9600, SWSERIAL_8N1, RX_PIN, TX_PIN, false, 256);
printer.begin(); // Heating time, default is 120. Higher the heat time, slower the print, darker the results
// printer.setDefault();
// printer.sleep(); // I need to call printer.wake() before using it
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Waiting to connect... ");
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/printer", handleBody); // Associate the handler function to the path
server.onNotFound(handleNotFound); // If the url request is incorrect
server.begin(); //Start the server
Serial.println("Server listening");
// Debug purpose only
Serial.print("Paper status: ");
Serial.println(printer.hasPaper());
}
void loop() {
server.handleClient(); // Listening all incoming request
}
Re: NodeMCU 1.0 unable to power up when connected to small t
Posted:
Mon Apr 20, 2020 2:51 pm
by timmeh87
The TX pin of the nodemcu (the one connected to the serial bridge) has the strange requirement that it must be high during boot. You are almost certainly accidentally pulling it down. Normally the serial bridge would keep it in the correct state.
To be exactly clear check what the boot pin requirements are for the nodemcu and make sure all of those pins are in the correct state. one of them is shared with the serial port. you might consider using one of the other serial ports if possible or using a pull up resistor if possible
Re: NodeMCU 1.0 unable to power up when connected to small t
Posted:
Wed Apr 22, 2020 7:24 am
by Eternyt
Many thanks for the reply!
I have checked and yes I am probably messing up GPIO15 during boot (GPIO15 is my TX pin on the schematic). Now I will try to switch SoftwareSerial to GPIO1 and 3 so that I should not have any problem anymore.
I will update this thread as soon as I finished switching the GPIO pins.