tl;dr source code & gallery
I’m sure almost everyone has heard at least once about Arduino and/or Raspberry Pi low cost computers. Both are used in countless ingenious DIY electronic projects, on their own or by using one of the many expansion modules available, due to their low price and small credit-card size form factor (even smaller if we refer to Raspberry Pi Zero model).
They are totally different concepts because they were conceived to perform different tasks: while Arduino is actually an almost indestructible open source¹ microcontroller which we can start playing with using a simple script (in C/C++; one application at a time) from the minute one, Raspberry Pi is a full minicomputer² on one small board (SBC) that runs a dedicated Linux OS distribution (so it can be programmed using a wide variety of languages) which allows us to run different programs very much like we do on our desktop computers.
“If your application is more about controlling things, the Arduino is probably a better choice. While if you need to process lots of data the PI is your best bet”
— Arduino vs Raspberry Pi — Which is best?
That said, more like a microcontroller than a minicomputer, we have our hero NodeMCU: an Arduino-compatible dev board with built-in WIFI for less than $5 that also supports Lua scripting language (there are several variants of ESP8266 chipset out there but it’s highly recommended to buy from the second-generation ESP-12E variant because it has a built-in power regulator).
Install standalone Arduino IDE following these instructions depending on your machine’s OS
Launch Arduino IDE
Add the link http://arduino.esp8266.com/stable/package_esp8266com_index.json to Additional Boards Manager URLs
Open Boards Manager… (menu Tools > Board…)
Search for ESP8266 and install it
Open menu Tools > Board… and select NodeMCU x.x…
We will use stock “Arduino language” (limiting the project to a single file with .ino extension known as “sketch”) along this journey which is basically a set of C/C++ functions (IMO they have done an excellent job in general abstracting the different interfaces because even a beginner would able to read and understand easily almost all the code). Advanced use cases perhaps will need a real IDE³ plus the use of plain C/C++ language.
Launch Arduino IDE
Connect the board to the computer (it’s quite common to tape the back to ensure that no metal scrap can short-circuit the board)
Select the correct
COMport for your serial adapter (Tools > Port…)⁴
Load Blink sketch (File > Examples > ESP8266 > Blink). Nothing to explain here as we can see the code is very easy to understand⁵.
Add the following line to the very beginning of the example (because the example is written for an older module version and not for ESP-12):
#define LED_BUILTIN 2
Upload it and wait a few seconds (the led should blink quickly during the uploading)
Welcome to life!
In order to make a real “Hello, World!” example we will modify the previous Blink example to print that well-known message.
Serial.begin(9600); Serial.print(“Hello, World”);lines within
Open Serial Monitor (Tools > Serial Monitor)
Select 9600 baud option in the drop-down list
Push the reset button on the board
As we have seen before, our tiny and dirt cheap NodeMCU has a built-in WIFI chipset. Therefore, the second thing we will do is display in the Serial Monitor all the wireless networks available around us using again one of the included examples: WifiScan (Files > Examples > ESP8266WiFi > WiFiScan).
Be sure to set the same baud rate in the code (
Serial.begin(xxx);) as in the Serial Monitor drop-down list.
This time there is no example included showing us how to make the connection to our lovely Internet, so we will create a new script (File > New) containing the code below (as we can see the code is almost self-explanatory and doesn’t need any additional comment 🤞):
Check twice the ssid and/or password values before start to think the board is broken 😉
Create a new sketch and paste the code below
api_keyvariables (get your API key here⁶)
There is a wrapper around CoinMarketCap API available for NodeMCU but it seems pretty abandoned and old so we will use our own implementation.
At this point we all agree on this: it makes no sense to use an IoT device of any kind to dump the information to the Serial Monitor. So, we should use a display to make our BitCoin Ticker really useful.
Although there are a vast offer of I2C/SPI displays models (ie SSD1306 or SH1106 models) to buy (these kind of add-on boards are also known as “shields”) we don’t want to mess around with cables, GPIOs, breadboards, voltages and that sort of thing by the moment so, for just less than $7, we can buy an ESP8266+OLED built-in on PCB.
Using the easiest (also the cheapest) option described above we must install the U8g2lib library (even if we follow another path that library support almost all types of displays so I can stop recommending it), paste the code below and upload it.
We have to setup the display driver at the beginning using one of the default constructors the library give us. Printed on its back side we can find where SDA and SCL are connect to. For example SDA-D1 and SCL-D2 means that the first one is connected to GPIO5 (D1) and the second to GPIO04 (D2). So later we use these values as data (5 in this case) and clock (4).
Example working for the ESP8266+OLED said above:
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(*/* rotation=*/ *U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 4, /* data=*/ 5);
For more details on those parameters refer to this example.
“To infinity and beyond!” — Buzz Lightyear
As we have already seen in a couple of hours and a few lines of code we can have our own Bitcoin Ticker running. So based on this and reading in depth all the shared links we will able to improve it or start a new project totally different. No limits! 🚀
Thanks for reading. If you enjoyed this article, feel free to hit that clap button 👏 as much as you can to help others find it.
This article was originally published on Medium
 We can buy an official Arduino in their online store for about $25 without WIFI module (supporting the company to continue researching and improving their products) but as it is an open source product there are some manufacturers who have created perfect clones that we can buy for less than $3 (Ebay is also a great place to buy them).
 One of the “biggest cons” of Raspberry Pi is that its hardware is not open source (Broadcom has an agreement with the Foundation to sell its chipset on exclusivity) so we cannot buy any cheaper Chinese clone anywhere.
 There are more powerful alternatives (personally I always stay as far as I can from that Eclipse thing) to the official “IDE” such as PlatformIO (which looks promising but perhaps quite complicated IMO) or this other Visual Studio Code extension for Arduino (which is backed by Microsoft)
 On macOS you will probably have to install one of these drivers (Bluetooth is not a valid port to uploading our sketches 😆)
 Anyway here is your new Bible.
 They will be migrating their Public API to a “Professional API” on Dec 4th, 2018. For our intentions their FREE tier meets our needs 😉
Level up every day