My recent quarantine project is an insult printer. So far everything works except that sometimes it prints the first letter weird (N@Ç). I know that I didn't use the smartest solution for my random char printing, but since my Arduino skills are very much at the beginning, I try to experiment and increase them.
It doesn't matter how long those strings are. It results always the same, even with one single word.
Here is a picture how the prints look like:
My current setup:
Arduino Uno R3
Thermal Printer with TTL
PushButton
- Powered by 9V DC Supply to VIn and Gnd on Arduino plus parallel to the printer.
- PushButton also has a 1kOhm resistor from pin 10 to Gnd.
Here is my code:
#include "SoftwareSerial.h"
#include "Adafruit_Thermal.h"
int RX_PIN = 2; // green wire
int TX_PIN = 3; // yellow wire
const int Taster = 10;
int buttonState = 0; // variable for reading the button status
int currState = 0; // 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);
void setup() {
pinMode(10, INPUT);
}
void loop() {
currState = digitalRead(10);
if (currState == HIGH) {
printInsult();
}
else {
printer.sleep();
}
}
void printInsult(){
char* myInsults[16]={
"Jeder hat das Recht \n haesslich zu sein, aber \n du uebertreibst es wirklich!",
"Dein Gesicht auf einer \n Briefmarke und die Post \n geht pleite.",
"Du hinterlaesst eine Luecke \n die dich vollstaendig ersetzt.",
"Du verschoenerst jeden \n Raum wenn du gehst!",
"Wow, du hast irgendwie \n das gewisse Nichts!",
"Erzaehl mal, hast du dich \n absichtlich so angezogen?",
"Die YouTube Kommentare \n ueber dich sind alle wahr.",
"Wenn ich dein Gesicht haette,\n wuerde ich lachend in eine \n Kreissaege laufen!",
"Das war keine Beleidigung. \n Das war eine exakte \n Beschreibung.",
"Du bist so ueberfluessig \n wie ein Sandkasten \n in der Sahara!",
"Wer zuletzt lacht, \n denkt zu langsam.",
"Bitte, geh auf die \n Autobahn ein paar \n Lichter fangen.",
"Du bist so ueberfluessig \n wie ein Fundbuero \n in Polen.",
"Deine Mutter kocht \n Wasser nach Anleitung.",
"Du bist einzigartig, \n jedenfalls hoffen wir \n das Alle.",
"Mehr habe ich von \n dir nicht erwartet...",
};
int insultChoice = random(0, 16);
mySerial.begin(19200); // this is the baud rate of your printer - may vary
//printer.begin();
printer.justify('C');
printer.setSize('M');
randomSeed(analogRead(0));
printer.println(myInsults[insultChoice]);
printer.feed(3); //advance two lines
printer.sleep(); // Tell printer to sleep
delay(2000);
}
I also tried to use an example which I found on GitHub - HaterMatic. There it is called the HaterMatic and works with a coin acceptor. In that sketch it reads a random string and saves it to the buffer. Unfortunately I wasn't successful to rewrite it to my needs (remove the coin acceptor and use only one string list).
So I hope someone has at least a solution for my current issue with the weird/wrong/missing letters.
Cheers