
In this tutorial we will see how to send data from Arduino card to a thermal printer: If you press the push button , the printer prints the word ‘Arduino’.
Arduino
QR701 thermal printer 5V-2A charger
Test plate
Connecting wires
To perform the assembly, we connect:
the VH pin of the printer to the (+) terminal of the charger
the first GND pin of the printer to the GND pin of the Arduino board
the second GND pin of the printer to the GND pin of the Arduino card
the TR pin of the printer to pin 6 of the Arduino card
This is the program that prints data sent from the Arduino card to the printer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
/*------------------------------------------------------------------------ Example sketch for Adafruit Thermal Printer library for Arduino. Demonstrates a few text styles & layouts, bitmap printing, etc. IMPORTANT: DECLARATIONS DIFFER FROM PRIOR VERSIONS OF THIS LIBRARY. This is to support newer & more board types, especially ones that don't support SoftwareSerial (e.g. Arduino Due). You can pass any Stream (e.g. Serial1) to the printer constructor. See notes below. ------------------------------------------------------------------------*/ #include "Adafruit_Thermal.h" #include "adalogo.h" #include "adaqrcode.h" // Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ---- // If using hardware serial instead, comment out or remove these lines: #include "SoftwareSerial.h" #define TX_PIN 6 // Arduino transmit YELLOW WIRE labeled RX on printer #define RX_PIN 5 // Arduino receive GREEN WIRE labeled TX on printer 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. // Here's the syntax for hardware serial (e.g. Arduino Due) -------------- // Un-comment the following line if using hardware serial: //Adafruit_Thermal printer(&Serial1); // Or Serial2, Serial3, etc. // ----------------------------------------------------------------------- const int btnPin = A0; // le bouton est connecté à la broche A0 de la carte Adruino int btnVal = 0; void setup() { pinMode(btnPin,INPUT_PULLUP); // This line is for compatibility with the Adafruit IotP project pack, // which uses pin 7 as a spare grounding point. You only need this if // wired up the same way (w/3-pin header into pins 5/6/7): pinMode(7, OUTPUT); digitalWrite(7, LOW); // NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page. mySerial.begin(9600); // Initialize SoftwareSerial //Serial1.begin(19200); // Use this instead if using hardware serial printer.begin(); // Init printer (same regardless of serial type) // The following calls are in setup(), but don't *need* to be. Use them // anywhere! They're just here so they run one time and are not printed // over and over (which would happen if they were in loop() instead). // Some functions will feed a line when called, this is normal. } void loop() { btnVal=analogRead(btnPin); if(btnVal<200){ // We press the push button printer.println(F("Arduino")); } } |
Tuyet 24-05-2222
This is really interesting, You are a very skilled blogger. I've joined your rss feed and look forward to seeking more of your magnificent post. Also, I have shared your website in my social networks!
Rhonda 13-05-2222
whoah this blog is magnificent i like studying your articles. Stay up the great work! You realize, lots of persons are looking round for this info, you could aid them greatly.
Florencia 05-05-2222
We are a group of volunteers and opening a new scheme in our community. Your web site provided us with valuable info to work on. You've done an impressive job and our entire community will be grateful to you.
Vanita 02-05-2222
Hi, I do think this is a great website. I stumbledupon it ; ) I may come back yet again since i have book marked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.
Mohammad 18-04-2222
I got this web site from my friend who told me regarding this web page and now this time I am browsing this web site and reading very informative content here.
Sherry 09-04-2222
I don't even know how I ended up here, but I thought this post was great. I do not know who you are but certainly you're going to a famous blogger if you are not already ;) Cheers!
Franchesca 08-04-2222
I am sure this piece of writing has touched all the internet viewers, its really really nice article on building up new weblog.
Dorie 01-04-2222
I'm extremely pleased to uncover this great site. I wanted to thank you for your time just for this fantastic read!! I definitely really liked every part of it and i also have you saved as a favorite to see new stuff on your site.
Bart 20-03-2222
Greetings! Very helpful advice within this post! It is the little changes that make the greatest changes. Many thanks for sharing!
Daniele 12-03-2222
Excellent post. I was checking continuously this blog and I am impressed! Very useful info particularly the last part :) I care for such information much. I was looking for this certain info for a long time. Thank you and best of luck.
Maryanne 02-03-2222
Woah! I'm really loving the template/theme of this site. It's simple, yet effective. A lot of times it's difficult to get that "perfect balance" between usability and visual appeal. I must say that you've done a fantastic job with this. In addition, the blog loads extremely quick for me on Opera. Exceptional Blog!
Verna 20-02-2222
Normally I don't read article on blogs, but I wish to say that this write-up very pressured me to check out and do it! Your writing taste has been surprised me. Thank you, very great article.