Integrating physical devices with IOTA — The IOTA LED Cube

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

Hugo Gregersen
Nov 12 · 6 min read

Introduction

This is the 11th part in a series of beginner tutorials where we explore integrating physical devices with the IOTA protocol. Its been i while since i published the last tutorial in this series as i have had to make some other priorities. This will change over the next coming months as i now have received donations from the IOTA development fund that will allow me to continue making these tutorials.

While on the topic, i would like to express my honor and thanks to everyone who have donated to the IOTA development fund. In a space where most actions are fueled by short sighted speculation and greed, the IOTA development fund is truly a unique construct that separate IOTA from other projects.

I was thinking we could start off with a smaller project that has more of a “fun” factor than an actual practical use-case. Beside being a cool and fun project to make, this tutorial is still important as it will give you an introduction to a useful feature of the IOTA tangle, namely the Zero Message Que, or ZMQ for short.

The primary goal of this tutorial is to use an LED cube to visualize the transaction throughput of the IOTA tangle.


The Use Case

As mentioned in the previous section, finding a practical use-case for this particular tutorial might be far fetched. However, learning about ZMQ and ZMQ streams is always useful as it can be applied to many other real life use cases. One example is the popular tanglemonitor.com

For the sake of relating this tutorial to the other tutorials in this series. I guess you could imagine the hotel owner placing an LED cube in the reception of his hotel as an interesting visual ornament. At the same time, the cube would have a practical function in terms of visualizing the current health and transaction throughput of the IOTA tangle.

Note!
In this tutorial we will be monitoring all transactions that are being propagated through the IOTA network. For monitoring the health of the tangle, it might be more appropriate to focus on confirmed transactions only. This is totally up to you as the IOTA ZMQ stream provides both.


What is the ZMQ (Zero Message Que)?

ZMQ or ZMQ streams are events or messages being published by an IOTA IRI node if activated. Using a ZMQ listener you could monitor these events and perform actions based on when the event happens, the type of event etc.

In our project we will be monitoring the ZMQ stream for new transactions being attached to the tangle, flashing a random LED on our LED cube whenever this particular event happens.

See here to learn more about the different ZMQ messages being published by the IRI node and the structure of the event message.

Note!
Notice that there is a config setting (ZMQ_ENABLED) in the IRI config file that defines if ZMQ messages are being published by the node. The ZMQ_ENABLED setting is by default set to False and must be changed to True for the node to start publishing ZMQ messages. Here you can also set the port that the ZMQ messages will be published on. Also notice that most public IRI nodes does not have ZMQ enabled. In case you don’t run your own IOTA node, you could ask the IOTA community on the fullnode Discord channel for a public node that has ZMQ enabled. Or, you could use the following ZMQ enabled devnet node currently being hosted by the IOTA foundation:
tcp://zmq.devnet.iota.org This node is publishing ZMQ messages on port 5556


What is an LED cube?

An LED cube is basically a three dimensional matrix (structure) of Light Emitting Diodes (or LED’s for short) wired together using power conducting wires. Using a micro-controller such as the Arduino or Raspberry PI you can make a program that turns on and off the individual LED’s at will, making all kind of interesting light patterns. There are literally hundreds of tutorials out there on how to build your own LED cube if you have have the desire to do so. You can also get complete kits with all the components required to build the cube, including detailed instructions on how to build it. All you need is a soldering iron and a lot of time and patience.

In case you want to go all in on building and programming your own LED cube, you should check out this video for inspiration.

As i personally nether have the time or patience for building my own LED cube from scratch, i decided to get one off ebay for about 25 USD.


The PiCube

The PiCube is kickstarter project that makes a pre-built LED cube that can be mounted directly on top of the Raspberry PI without any wiring or soldering. There is also a github page for the PiCube project where you can get documentation and example code.


Required Software and libraries

Before we start writing our Python code for this project we need to make sure we have all the required software and libraries installed on our Raspberry PI. For this tutorial, the only additional library required is the PyZMQ library. To learn more about the PyZMQ library and how to install it, see the following link: https://zeromq.org/languages/python/


The Python code

The Python code for this project is pretty straight forward so i will not go into details, except saying a few words about how to address the individual LED’s in the cube. In my example, I’m simply selecting a random LED to flash for each new IOTA transaction being attached to the tangle. In your version of the project you might want to flash the LED’s in a particular order, if so, you need to know how to address the individual LED’s in the cube.

The basic concept behind a LED cube is that you have the LED’s connected in isolated circuits represented by vertical and horizontal layers. With respect to the PiCube, the LED’s are connected in 16 isolated vertical layers together with 4 individual horizontal layers, making up a total of 64 LED’s. To turn on/off a particular LED in the cube you simply power on/off both the vertical and horizontal layer where the layers meet (and the LED is located). As each individual layer is connected to a particular GPIO pin on the PI, i can now use the PI’s GPOI.output() function to power on/off the individual LED’s

After some testing i found that the LED’s on the PiCube was connected to the PI’s GPIO pin’s according to the following figure.

And here is the Python code for the project.

The source code for this python script can be downloaded from here


Running the project

To run the the project, you first need to save the scrip from the previous section as text files on your computer.

Notice that Python program files uses the .py extension, so save the files as zmq_cube.py on your Raspberry PI

To execute the scripts, simply start a new terminal window, navigate to the folder where you saved the script and type:

python zmq_cube.py

You should now see random LED’s on your PiCube start flashing, where each flash represents a new transaction being added to the IOTA tangle.

In your terminal window you should also see some basic data for the individual transactions, such as the address, transaction hash, value and tag.


Contributions

If you would like to make any contributions to this tutorial you will find a Github repository here.


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

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Hugo Gregersen

Written by

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade