Hello ![]()
I'm trying to make the mini thermal printer print a shopping list when a button is pressed on an Arduino Uno board. I am using this mini thermal printer Arduino Code | Mini Thermal Receipt Printers | Adafruit Learning System and this button Rugged Metal Pushbutton with Red LED Ring [16mm Red Momentary] : ID 559 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits. Even though the code does not seem complicated, I somehow don't manage it.
The printertest script works. The button itself works on a simple script with the build-in LED on pin 13 (even though it only dims the brightness, not completely shuts it off). However, in the code below it does not work anymore. I have no idea why, I checked the code a hundred times now. Maybe I just bought an inadequate switch for that purpose? Maybe you can help me. Eternal gratefulness for sure! ![]()
All the best,
Emma
//http://www.suppertime.co.uk/blogmywiki/2012/10/howtopoems/
#include "SoftwareSerial.h"
#include "Adafruit_Thermal.h" // you need to download this and put it in your Arduino library
int RX_PIN = 6; // This is the green printer wire
int TX_PIN = 7; // This is the yellow printer wire
const int buttonPin = 5; // the number of the pushbutton pin - doesn't change
const int led = 13;
//const int buttonPin = 5;
int buttonState = 0; // variable for reading the pushbutton status
int debounce_delay = 300; // set variables to hold the state of the button
//int prevState = 0;
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.
void setup() {
pinMode(buttonPin, INPUT);
pinMode(led, OUTPUT);
Serial.begin(19200); // this is the baud rate my printer
printer.begin();
}
void loop(){
// read the state of the button:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
delay(debounce_delay);
digitalWrite(led, HIGH);
printList();
}
else {
digitalWrite(led, LOW);// if you want something to happen when the button is released, put it here
// such as a beep, or a display saying 'your poem is on its way'
}
}
void printList(){
// put author names & dates here, in order
printer.underlineOn();
printer.justify('C');
printer.setSize('L');
printer.println(F("Ingredients for"));
printer.boldOn();
printer.println(F(" Banana Bread:"));
printer.doubleHeightOff();
printer.boldOff();
printer.underlineOff();
printer.setLineHeight(50);
printer.justify('L');
printer.setSize('S');
printer.println(F("- Flour (200 grams)\n- Banana (150 grams)\n- Sugar (50 grams)\n- Cinnamon (1 gram)"));
printer.justify('R');
printer.justify('L');
delay(2000); // 2 second pause to help prevent multiple presses
}
