From the SatoshiPay engine room: An IoT adventure for people without any IoT experience. A contribution by the Solar team.

At SatoshiPay we are constantly building new software that uses the Stellar network to facilitate payments across the globe. We love Stellar, because its transactions are very cheap, super quick and the network is generally quite easy to use.

When our launch event came up on November 26th, a new opportunity arose. Wouldn’t it be great to give our party guests some free lumens and let them interact with the future of payments themselves?

Today we want to share our journey and show you how to build our Stellar-powered candy dispenser yourself!

You will need:

Cereal dispenser

Raspberry Pi with 3.0A power supply, SD card, case

Pair of motors

An old USB keyboard + mouse and a screen to set up the Raspberry Pi

Plastic U profile (we used a 20x20mm one — visit your local hardware store)

Jumper cables, two long metric screws and nuts

Cordless screwdriver, 6mm drill

Small saw, a knife and some tape

Basic knowledge of how to use a linux terminal

If you want to add LEDs to it, you also need:

LED ring

Soldering iron

You do not need:

Any clue about hardware engineering

Any experience in low-level software development

Any Bitcoin, Ether or XRP 😜

The source code of our candy dispenser software can be found at SatoshiPay’s GitHub account: github.com/satoshipay/stellar-candy-dispenser. It is written in JavaScript, using node.js and the official Stellar SDK.

The basics

First of all, make sure you have got all the items from the previous list. Once everything has arrived, let’s start by setting up the cereal dispenser. This step is pretty straight forward — just stick the pieces together, there is only one way you can do it.

The next step is a bit more complicated: Setting up the Raspberry Pi. Put the motherboard into the case, then connect mouse, keyboard, screen and power. If you have ordered a blank micro SD card, you will first need to copy the Raspbian operating system to it. Read more about it in the Raspberry Pi documentation.

Insert the SD card into the card reader and switch the power on to boot. Follow the setup instructions on the screen. Git is already installed on the Raspbian, so you only need to install node.js.

For later debugging and maintenance without a screen it is a good idea to launch an SSH service on the Raspberry, too, and add your laptop’s SSH public key to ~/.ssh/authorized_keys.

Prepare the program

We will now download the program that controls the candy dispenser to our Raspberry at /opt/candy-dispenser and configure it.

Run those commands in a terminal on the Raspberry:

cd /opt

git clone git@github.com:satoshipay/stellar-candy-dispenser.git

Let’s create the configuration file at /opt/stellar-candy-dispenser/.env:

Sample configuration

Replace the account IDs (public keys) with accounts of yours. Just take your favourite Stellar wallet, like Solar, and create two new accounts, funded with at least 1 XLM each. You only need to set up the testnet accounts if you run the program on testnet using npm run dev.

Let’s do a dry run. Unbox the motors, connect one of them to the Raspberry’s GPIO 18 (pin 12), the other motor to GPIO 23 (pin 16). Also connect their power supply wires to a 5V pin (pin 2 or 4) and a ground pin (pin 6, 14, 20, …).

Make sure to turn the Raspberry’s power off first! Connecting the wrong pins could fry the Raspberry for good if the power is on.

Use these commands to test the motors:

sudo npm run test-left

sudo npm run test-right

The motors should run for a moment, first one, then the other. If everything worked so far, then set up the init.d script, so the program is started as a daemonized service when the Raspberry Pi boots.

Take the file from https://github.com/satoshipay/stellar-candy-dispenser/blob/master/etc/init.d/stellar-candy-dispenser, change the dir path to /opt/stellar-candy-dispenser and write the file to /etc/init.d/stellar-candy-dispenser. You can now start the service using sudo service stellar-candy-dispenser start.

Some handicrafts

Let’s attach the motor rotors onto the dispenser knobs. First, pull the knobs out of the dispenser — they have a plastic axis attached to them. Put the knob down, so that the flat front of the knob is on top and clamp the axis, so that it cannot move away — we just put it in between two desks.

Take a rotor and some screws that came with the motor, place the rotor centrally on the knob and use your cordless screwdriver to drive the screws into the knob to attach the rotor. You can now easily stick the rotor on the motor.

You can now already check that the motors can actually turn the knobs. They should be wired to the Raspberry already. Re-attach the knobs to the dispenser and trigger a motor test run as before while holding the motor in place with your fingers, so it won’t spin itself.

Stay calm and drill

Time to fixate the motors, so you don’t need to hold them in place with your fingers anymore:

Take the plastic profile and make sure you can fit the motors into it. A profile sized 21mm wall-to-wall worked well for us.

Drill two 6mm holes into the dispenser’s case and the plastic profile. Make sure that the holes in the dispenser match the holes in the profile! This can be a bit tricky, but don’t worry too much. Since we will be using relatively long screws, we can afford to be a few millimeters off if need be.

Attach the plastic profile to the dispenser’s case using the long screws and two nuts on each screw: The screw’s head presses against the plastic profile, one nut goes on one side of the dispenser’s drilled wall and the second nut goes on the other side of the wall.

There shall be light (optional)

Now comes the advanced bit — you need to get that old soldering iron of yours out!

First you need to solder three jumper cables to the LED ring. You need one on +5V, one on GND and one on DI (DO would work as well). Be careful as there is not much room for mistakes. Make sure you don’t short-circuit the pins.

Now we need to connect the LED ring to the Raspberry’s pins again. But wait… we only have two 5V pins — this is the third 5V consumer!

Don’t worry. We have still got plenty of jumper cables and the soldering iron. All we need to do is to build a Y jumper cable — a cable with one input and two outputs. Just take three jumper cables, cut off one end on each of them (be careful that the remaining ends are what you need to connect it, either male or female) and carefully remove the isolation at the cut-off ends with the knife. Now take the three de-isolated ends, twist them together and add some solder.

Use the improvised Y cable on one of the two 5V pins of the Raspberry to power both motors. Now that there is a free 5V pin, we can now easily connect our LED ring: 5V to 5V, GND to GND and the DI to GPIO 12 (pin 32). Again, make sure the Raspberry is powered off while you do that!

Switch the power back on and make sure our service is running. You should now see a glowing LED ring. The last step is easy — glue the LED ring to the plastic profile. We used double-sided tape for that.

Finishing touches

Last, but not least we need to attach all loose parts, including the Raspberry, to the dispenser case. Some more double-sided tape and zip ties are your friends here.

Power the candy dispenser on and it should be running in less than a minute. The LED ring will light up and start pulsating to let you know everything’s up and running.

It’s a good idea to print the account IDs as QR codes and glue them to the dispenser, so people can easily scan them with their wallet app.

When you are done, just pull the plug. It’s discouraged, but since we are not writing to the filesystem the risk of actually causing trouble should be fairly low.

Round-up

This candy dispenser concept has been developed in a very short amount of time and was optimized for simplicity. It could have been designed in a more elegant and in a cheaper way, but that is not what this project was about.

We were able to successfully build a Stellar-powered candy dispenser in less than three days with no prior knowledge about hardware development and we managed to bring the Stellar network into our office — to be touched, seen and heard.

Being convinced that the Stellar ecosystem and the whole distributed ledger space needs more hardware applications like this one, we hope to inspire more people to try building something beyond software.

Happy holidays and happy hardware hacking!

The @Solar_Wallet team at @SatoshiPay