Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By juanmanuel85
#80039 Hi, this is my first post , hope you could help me
What im trying to do: a ticket printer with a push button that counts +1 each time i print a ticket

why nodemcu 8266 : because i would like to see later how many i printed on my mobile

extra info: this code worked allready fine on arduino, note that im just using nodemcu as an arduino by now
without wifi. i didnt add internet yet, just trying to see if it works the same way

Problem: it prints half of the ticket and stops everything (while in arduino prints each time i press the push button perfect)

why i dont just use arduino: because i would like to add wifi to this project and its easier with nodemcu

Questions: Could it be that ESP8266 prints less information than arduino?
How could i solve this?

code:
Code: Select all#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"

int estado = 0;
int ticket = 0;
#define TX_PIN D7 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN D8
SoftwareSerial mySerial(RX_PIN, TX_PIN);
Adafruit_Thermal printer(&mySerial);
void setup() {
  Serial.begin (9600);
   mySerial.begin(19200);  // Initialize SoftwareSerial
  printer.begin();       

pinMode (D4, INPUT_PULLUP);//PULSADOR
//pinMode (13, OUTPUT); // LED
}

void loop() {
  Serial.println (estado);
  // put your main code here, to run repeatedly:
estado = digitalRead (D4);
if ( estado == LOW) {
  ticket=ticket+1;
 printer.println("***  welcome  ***\n");
 printer.println(ticket);
 printer.println("*** INCLUYE UNA BEBIDA  ***");
printer.print("FECHA:24/01/2018\t");
 printer.println("HORA: 00:07");
 printer.println("DIA: SABADO");   
  printer.println(" \n");
   
  }

}


Thank you very much :)
User avatar
By QuickFix
#80045 The Adafruit library should be compatible with the ESP8266, but there were some problems with it in the past.
Make sure you use the latest version from repository, where this bug is fixed. :idea:

Also best practice is to use a simple and small as possible demo as a starting point to see where things go wrong, like trying any of the examples that come with a library; a lot of times a bug isn't inside the code you expect it to be in.
User avatar
By schufti
#80047 Hi,
I miss two general items in your sketch:
a) key debounce
b) semaphor that you allready are serving a print request

as the esp8266 is n-times faster compared to arduino (empty loop() is called several times per ms), it is most likely that with one button press you run into print routine several times and esp crashes due to stack overrun or similar.
First implement a lockout to avoid cascading print calls, then - if necessary - look for key debounce. Sometimes HW debounce is sufficient (10nF cap parallel to button).
User avatar
By juanmanuel85
#80049
schufti wrote:Hi,
I miss two general items in your sketch:
a) key debounce
b) semaphor that you allready are serving a print request

as the esp8266 is n-times faster compared to arduino (empty loop() is called several times per ms), it is most likely that with one button press you run into print routine several times and esp crashes due to stack overrun or similar.
First implement a lockout to avoid cascading print calls, then - if necessary - look for key debounce. Sometimes HW debounce is sufficient (10nF cap parallel to button).

Thanks for your reply, Im allready using a 10k resistor should i add the 10nf cap as well?