loading

  • Do you have an online store?
  • Are you a maker?
  • Do you want to optimize the selling process?

If you answer yes to all the questions, please keep reading because this is the instructable you are looking for. Also if you say no to one or more questions keep reading too, maybe you can print your email or make a secret organization mission printer. The posibilities and applications of this are endless.

The IoT is everywhere, now almost everything is conected to the internet and makes our lives easier. So I decided why not make a ticket printer machine that connects directly to an email account where all the orders made in my online store arrives and the print the tickets automatically for you.

But, how it works?

In any e-commerce platform when a client makes an order you receive an email. So this printer is conected via IMAP service to an email account that only receives this notification emails.

When the email arrives it contains some html code, so I used string functions to delete all the html code and only get the information that can be used. Then, I search for the data that I need to generate the ticket and after that I save it into different strings. When I have the data that I want, the ticket is printed.
Also the printer can detect if there is paper and only marks the email as "readed" if the ticket is successfully printed. And if you need to print it again, you only need to go to your inbox an mark that mail as "unread".

Pretty simple, right?

I can not guarantee that my code is compatible with your specific e-commerce system, so in this Instructable I am only going to show you how to get the email and print the body. The transformation into a ticket going to be up to you, but dont worry is easy if you know how to work with strings.

Let's get started, shall we?

Step 1: Gathering All the Parts

For this build you are going to need:

  • 1 x Raspberry Pi model B.
  • 1 x wifi miniature dongle.
  • 1x SD card with Raspbian installed.
  • 1 x Logic level shifter.
  • Some jumper wire (male to female and female to female).
  • 1 x Thermal receipt printer and extras.
  • 1 x Power supply (5v and al least 5A).
  • 1 x Panel mount DC barrel jack.
  • 1 x Pushbutton SPST.
  • 1 x Neopixel (WS2812B).
  • Enclosure and hardware.

You can get all the parts from Adafruit, and the files for laser-cutting the case can be found here: Acrilic Case

Also Adafruit offers a kit with almost everything to build this project, you can see it here.

Step 2: Making All the Wiring and Assembling the Case

Now it's time to make the conections, I recommend you to assemble the case first but without the front plate (the one with the cloud). The wiring is as follows:

  • Raspberry pin 1 -> LV (low voltage) pin in the level shifter.
  • Raspberry pin 2 -> 5v from the barrel jack.
  • Raspberry pin 6 -> GND from the barrel jack.
  • Raspberry pin 8 -> Printer RX (yellow wire).
  • Raspberry pin 9 -> button common terminal.
  • Raspberry pin 10 -> level shifter RXO (rx output)
  • Raspberry pin 12 -> level shifter TXI (tx input)
  • Raspberry pin 14 -> Printer logic GND ( the gnd wire that is with rx and tx from the printer).
  • Raspberry pin 16 -> button normally open terminal.
  • Level shifter TXO -> Neopixel signal input.
  • Level shifter RXI -> Printer TX (green wire).
  • Level shifter HV -> 5v from the barrel jack.
  • Level shifter GND -> GND from the barrel jack.
  • Neopixel GND -> GND from the barrel jack.
  • Neopixel Vin -> 5v from the barrel jack.
  • Printer Vin -> 5v from the barrel jack.
  • Printer GND -> GND from the barrel jack.

And thats all, double check the connections and make sure everything is right. When you finish put the front plate of the printer and tight the screws. I glued a white acrilic at the back of the cloud and them the neopixel, so the entire cloud has a backlight powered by the neopixel.

Step 3: We Have the Hardware, It's Time for the Software

In this step I will assume that you already have installed Raspbian in the SD card and you have the wireless network up and running. A SSH link will be helpfull too. We will need to install some libraries and change a few settings, so let's begin:

Execute: "sudo raspi-config" and them go to Advanced options/serial and select "No" this will allow us to control, the serial port in the raspberry. We need it for controlling the thermal printer. After doing that run: "sudo reboot"

Now it's time for making the Neopixel works with the Raspberry, just follow the guide in this link and come back when you have the Neopixel up and running (stranstest), you don't need no rewire anything.

Now we will install all libraries and resources needed for our program, execute the following commands:

  • "sudo apt-get install python-pip"
  • "sudo pip install imapclient"
  • "sudo apt-get install python-serial python-imaging python-unidecode"
  • "sudo apt-get install git"
  • "git clone https://github.com/DAFRELECTRONICS/IoTprinter"

Now we are going to test the printer, run "cd IoTprinter" and then "sudo python printertest.py". If your printer works you have made everything right. Now we almost finished, but we need to configure our email account, we will be using gmail.

Step 4: Configuring Gmail Account for the Printer

The step number one is go into your gmail, then in in "My account" and after that in "Sign-in & security". Search for "allow less secure apps" an turn it on.

And that all for a basic setup, but we are going to create an special folder with filtering. So we can guarantee that the printer only gets the desired emails.

To create our special folder we are going to click in the arrow in the search field of our inbox and define the parameters that we want. When you enter your parameters for the filter click in "Create filter with this search" at the botton.

In the next screen mark the options "skip inbox" and then "apply the label" and create a new label. This will be the folder name, I named it "Secret messages" but it can be anything. Just be sure that the name matches the one in the script in the raspberry pi. After that create the filter and you will see the new folder in your inbox, all the email with the parameters you defined will end in this folder. In my real aplication for my store th filter paramaters are the store email as sender and in subject is "new order".

Ok, we are ready to configure our script in the raspberry.

Step 5: Configuring the Script in the Raspberry

We need to do a few configurations in order to get things working. Firts in the project folder edit the file mailverifier.py, execute "sudo nano mailverifier.py" Now search for this parameters and change it:

  • Firts of all search for Username, Password and Mailbox. Them put in your account data.
  • If you want enter your custom string for filtering unwanted data in body2 processing.

When you are donde quit editor and save changes. After that run and test the script with "sudo python mailverifier.py" If you have problems when printing searh for the line "body = server.fecth....." and read the comments for fixing the problem.

If everything works well its time for running it automatically at boot. For that run "cd" then "sudo nano /etc/rc.local"

and after the line "#By default this script does nothing" add the following lines:

cd /home/pi/Python-Thermal-Printer
python mailverifier.py &

Exit and save the changes, now reboot the Raspberry Pi and enjoy your new IoT Printer.

Step 6: Color Codes of the Printer and Other Useful Info

If you push the button the inbox gets checked for new data and if you hold it the Raspberry is shut down(the neopixel goes off when this happen).

These are the color error codes:

  • Green: booting script
  • White: starting up the scrip
  • Yellow: no paper in the printer.
  • Red: no emails for printing.
  • Blue: emails for printing available.
  • Purple: no internet connection or error retrieving or porcessing data.

Step 7: Thank You for Reading, Enjoy :)

Thats all That I am going to cover in this Instructable, feel free to start hacking and adapt this base script to your own e-commerce platform. Remenber, I can´t do that for you, because your system may be different from mine.

If you like it, and want to support me give me a like in my sore fanpage: DAFR ELECTRONICS and also vote for this instructable in the contest.

Thank you, I hope you find it helpful. If you have a question feel free to ask .)

Writed by:

Daniel Fernandez R.

<p>Hi, First of all, thank you for the detailed information. Do you know where we can buy some units of Raspberry PI ticket printer ? I noticed that it was discontinued and out of stock in the adafruit website.</p>
<p>Hi I was wondering if this could be hooked up to a tablet pos system? Also this is so cool!!!</p>
<p>Hi, Yes you can if you have an email alert in your pos system. </p><p>Thanks.</p>
This is amazing, this could help a lot of businesses <br>
<p>Thanks :)</p>
<p>Long Live CETI! cool protect bruh (Y)</p>
<p>Thanks :) </p>
Is it possible to change the email servers it uses to another host rather than gmail?
<p>Yes, it's possible. But you need to figure out what is the imap hostname of the email server you want to use. </p>
<p>Great! kEEP IT ON!</p>
<p>Thanks :)</p>
<p>I can put to work without neopixel? You could use a USB printer?</p>
<p>Hi,</p><p>Yes you can, you have two options. The first one is simple not connect the neopixel and the second one is not install the neopixel library and commnet out all neopixel related code in the script. </p><p>You can use a usb printer, but you have to modify the script in order to make it work. </p>
<p>Very cool, man! Very cool! Thanks for sharing!</p>
<p>Thanks :)</p>
<p>Hi, excellent project, thank you!<br><br>I have 2 questions if you don't mind:<br><br>1. Is there a way to make it check for new email (sales) automatically without having to press the button?<br><br>2. When modifying <strong>mailverifier.py </strong>I understand what 'username' and 'password' mean but what do I put in the 'mailbox' field? I'll be using Gmail as well.<br><br>Thank you!</p>
<p>Hi, thank you.</p><p>No problem :)</p><p>1. Yes, it does. By default it's configured to check your email every 60 seconds. And you can modify it in the line that says &quot;MAIL_CHECK_FREQ&quot; is bellow the email login details. When you press the button you make it instantly check the email. </p><p>2. In the mailbox field you put the name of the folder you want to check for new emails. In the step 4 is described, this is in case you are using a filter for only process certain emails(gmail saves it into a different folder instead the inbox). If you want to check your entire inbox just put 'Inbox' in this field and skip the filter stuff. </p><p>Best regards,</p><p>Daniel Fernandez R.</p>
This is a very interesting instructable. I especially like how you used the neopixel for the various error states.
<p>Thanks :)</p>

About This Instructable

31,073views

546favorites

License:

Bio: I´m a guy interested in new tecnologies and the things that we can make in house with a few components and a bit of ... More »
More by Daniel ArturoF:How to load programs to an Arduino UNO from Atmel Studio 7 Neopixel Clock Raspberry Pi IoT ticket printer for online stores 
Add instructable to: