From Arduino to Tangle
The full article was originally published by Lewis Daly on Medium. Read the full article here.
A guide to Johnny Five, Arduino and IOTA’s MAM
In this post, we’re going to explore a simple case of getting MAM interfacing with an Arduino, using Johnny Five. This post was inspired by @Chrislaive on Discord, with his great example of MAM and Arduino, which you can find here. Thanks Chris!
Aside from the Gists you see below, you can see all of the code for this tutorial here. As always, comments, corrections and pull requests are welcome!
Step 1: Arduino + Johnny Five
First, we need to get johnny five running on the arduino. This is pretty easy to do nowadays. I followed this guide here.
Then, we can run the traditional arduino blink.
$ node blink_test.js
Step 2: IOTA and MAM Libs
Ok, now that we can run JS on our Arduino, we need to get the IOTA libs working.
Shout out to @Chrislaive on Discord for the pointer to https://github.com/rwaldron/johnny-five#setup-and-assemble-arduino. We’re going to use this to get us started with the IOTA libs on Arduino and Johnny-Five
Install the required dependencies:
$ yarn add iota.lib.js $ mkdir lib #Add the submodule - you don't have to do this if you're working from my code! $ git submodule add https://github.com/iotaledger/mam.client.js.git lib/mam.client.js
Make a new file called init_test.js
Here, we’re just making sure that we are including our libraries correctly, and initializing IOTA and MAM properly.
$ node init_test.js
Hopefully this should run correctly, and we should see some output about MAM in the console.
From Arduino -> Tangle
Next up, we’re going to try and actually send a message to the tangle. Unfortunately I left all of my cool sensors at home, so the message won’t have any meaning, but we can at least get it working for a later tutorial.
Here, once the board is ready we send a message of Hello World (in trytes of course) publicly using MAM. The publish function is pretty close to what we did in my last tutorial for reference.
Stay tuned for my next post, where I look at getting data from actual sensors to the Tangle, without needing to use Johnny Five.
If you enjoyed this post, or have any suggestions or questions, let me know in the comments. If you liked this post, give it a ❤ or a 👏, or whatever you crazy cats are calling it nowadays.
P.S. Donations are always welcome!