Integrating physical devices with IOTA — The IOTA payment terminal

The 9th part in a series of beginner tutorials on integrating physical devices with the IOTA protocol.


Introduction

This is the 9th part in a series of beginner tutorials where we explore integrating physical devices with the IOTA protocol. This tutorial is the final part in a sequence of tutorials where we will try to replicate a traditional fiat based debit card payment solution with an IOTA based solution. In this tutorial we will be building a simple IOTA based payment terminal using some low cost off-the-shelf components.

Before you start building this project you should first take a look at the 6th, 7th and 8th tutorials in this series as they all provide the foundation for building the project in this tutorial.


The Use Case

Now that the hotel owner has his functional IOTA debit card payment system up and running there is one final issue he needs to address. This issue is related to how his new IOTA debit card solution can be used in a practical end user payment scenario. Up until this point, interaction with the system has been based on a classic monitor and keyboard connected to the USB ports on our Raspberry PI. While this is fine for administrative tasks such as creating and issuing new IOTA debit cards, it may not be very practical as an end user payment interface. Imagine the waiter in the hotel restaurant having to drag around a large monitor and keyboard whenever a guest wants to pay for dinner. Or having a large monitor and keyboard connected to the swimming-pool locker. This would be both impractical and expensive. What we need is something like a portable payment terminal or some simple user interface that could be integrated in to the swimming-pool locker. Designing and building a slick and sexy portable payment terminal or human machine interface (HMI) is a little beyond the scope of this tutorial. However, using some low-cost off-the shelf components we should be able to build a prototype that could function as a proof-of-concept (PoC) for a future industrialized version.


Components

The components you will need to build this project is as follows:

  1. Raspberry PI
  2. 12 Key — 4x3 Matrix — Membrane Type Keypad
  3. 1602 LCD Display with I2C
  4. RC522 RFID Reader/Writer module
  5. LED, breadboard, some wires and a resistor

Note!
All components except the keypad and 1602 LCD display have been discussed in previous tutorials so i will be skipping any further details on them in this tutorial.

The 12 Key — 4x3 Matrix — Membrane Type Keypad
The 12 Key — 4x3 Matrix — Membrane Type Keypad is a simple keypad that can be used as an input device to any project that requires numeric input. The keypad is popular among tinkerers for its low cost and ease of use. You should be able to get one of ebay for a couple of bucks.

Note!
You can also get these keypads in a 16 (4x4) key configuration. This may come in handy in cases where you need to execute other functions besides getting the numeric input. Notice that you will have to do some adjustments to the keypad library used in this tutorial if you choose to use the 16 key version.

The 1602 LCD Display with I2C
The 1602 LCD Display is a very handy and compact display commonly used for projects that requires simple character and numeric based communication. The 1602 has an adjustable back-light feature that makes it function equally well in light and dark environments. I have chosen to use the I2C version of the 1602 LCD in this project. The I2C version of the 1602 LCD has an additional I2C module (LCM1602) attached to the back of the LCD that allows for serial communication. Using the I2C module, we only need a minimum number of GIO pins and connections to get the LCD up and running with the PI.

1602 LCD (Front)
1602 LCD with I2C module attached (Back)

Wiring the project

Use the following connection diagram to connect the various components used in this project.


Required Software and libraries

Before we start writing our Python code for this project we need to make sure that we have all the required software and libraries installed on our Raspberry PI. See previous tutorials for more information on installing the Raspbian OS, Python, Pyota and the RC522 RFID Reader/Writer library.

To get our 1602 LCD and Keypad to function correctly, we first need to add a couple of new Python libraries to our project.

To include these libraries in your project, simply download the I2C_LCD_driver.py and keypad.py files and put them in the same folder where you installed the MFRC522-python library.

See here to learn more about using the different functions provided by the I2C_LCD_driver.py library.

Note!
Before we can get the 1602 LCD working with I2C we have to make sure that I2C communication is enabled on the Raspberry PI. See
here to learn more about enabling I2C on the Raspberry PI.

Note!
Depending on the version of Raspberry PI you are using you may have to do some changes to the I2CBUS and ADDRESS variables at the beginning of the I2C_LCD_driver.py file. For older versions of the PI you may have to change the I2CBUS variable to 0. You may also have to change the ADDRESS variable to the address used by your LCD. My I2C address is 27 so i’ll change the value to 0x27.


The Python code

The Python code used in this project is a variation of the code used in the previous tutorial, only difference is that we will be getting user input from the keypad instead of a classical keyboard. We will also be replacing the monitor with the 1602 LCD for visual communication.

You can download the source code from here


Running the project

To run the the project, you first need to save the code in the previous section as a text file in the same folder as where you installed the MFRC522-python library.

Notice that Python program files uses the .py extension, so let’s save the file as iota_terminal.py on the Raspberry PI.

To execute the program, simply start a new terminal window, navigate to the folder where you saved iota_terminal.py and type:

python iota_terminal.py

You should now see a message on the LCD asking for the amount of <blinks> you want to purchase. Use the numbers on the keypad to input the desired amount and press # when done. You may use the * key to make corrections.

Next you will be asked for the PIN code currently assigned to your IOTA debit card. Use the numbers on the keypad to input the 4 digit PIN code and press # when done. You may use the * key to make corrections.

Next you will be asked to hold your IOTA debit card close to the RFID reader. As soon as the card is detected by the RFID reader the IOTA payment transaction will be executed. Updates on the transaction process will be displayed on the LCD.

As soon as the transaction is confirmed by the IOTA tangle, the LED will start blinking according to the number blinks payed for.


Donations

If you like this tutorial and want me to continue making others, feel free to make a small donation to the IOTA address shown below.

GTZUHQSPRAQCTSQBZEEMLZPQUPAA9LPLGWCKFNEVKBINXEXZRACVKKKCYPWPKH9AWLGJHPLOZZOYTALAWOVSIJIYVZ