Build a Physical Bitcoin Ticker With the ESP8266
The Internet of Things can be used in many applications. For instance, in this project, we are going to use ESP8266 to venture a little bit into the Bitcoin industry. The project we will be looking at will involve getting real-time prices of Bitcoin and displaying the prices on an OLED screen. We'll also add some LEDs to show if the price of Bitcoin is going up or down. Let's start!
What You'll Need
| Component | Qty | |
|---|---|---|
| Adafruit ESP8266 module | 1 | |
| FTDI USB module | 1 | |
| LED (green and red) | 2 | |
| 330 Ohm resistor | 2 | |
| OLED display 128×64 pixels with SSD1306 driver | 1 | |
| Breadboard | 1 | |
| Jumper wires | Multiple |
Step by Step
Hardware & Software Requirements
<p>The ESP8266 Wi-Fi chip is the backbone of this project. So the most important hardware requirement is an ESP8266 Wi-Fi board. Any ESP8266 module will do the trick.</p><p>You also require an OLED screen for display functions. There is a wide array of displays that you can use. A 128×64 OLED with SSD1306 driver is recommended after considering several factors, such as compatibility of the display with the ESP8266 module.</p><p>When it comes to the price trend indicator, LEDs are the best bet. So, you will need two LEDs, preferably one red and one green. You should also get a 330Ω limiting resistor for each LED.</p><p>Other hardware components you will need include a 3.3V/5V FTDI module for programming the ESP8266 and jumper wires and a breadboard to connect the different hardware components.</p><p>For software, you will need the latest Arduino IDE from the <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.arduino.cc/en/Main/Software">Arduino official website</a>. You will also need a library for the SSD1306 OLED screen which you can download from the Arduino library manager or get it from <a target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/squix78/esp8266-oled-ssd1306">GitHub</a>. To get the bitcoin price from the internet you will require the Coindesk API at <a target="_blank" rel="noopener noreferrer nofollow" href="https://api.coindesk.com/v1/bpi/currentprice.json">http://api.coindesk.com/v1/bpi/currentprice.json</a>. The API returns the current price of Bitcoin in different currencies.</p>
Hardware Configuration
<p>Now it's time for the fun part – putting everything together. Start by mounting the ESP8266 module and the OLED screen on the breadboard.</p><p>Once that is done, connect the power pins to the OLED screen. Run a jumper wire between the Vin pin of the screen and the 3.3V pin of the ESP8266 and another jumper from GND of the screen to GND of the ESP8266.</p><p>The screen will be communicating with the ESP8266 via I2C. So, we need two jumpers to go from the DATA pin and the CLK pin of the OLED screen to pin 14 and pin 12 of the ESP8266 board respectively. One thing to note before connecting the I2C pins is that the screen can be configured to use either I2C or SPI. Therefore, make sure that your module is configured to use I2C.</p><p>The final step is to connect the RST pin of the OLED screen to ESP8266 board's pin 2. This connection might not be necessary at all times, though it's always advisable to have it.</p>
Code Configuration and Testing
<p>Once you are satisfied with your hardware connections, start configuring your setup. The first piece of code includes the required library files and defines the I2C pins and I2C address:</p><p><code>#define SDA 14</code><br><code>#define SCL 12</code><br><code>#define I2C 0x3D</code></p><p>Create an instance of the LCD display:</p><p><code>SSD1306 display(I2C, SDA, SCL);</code></p><p>To get the current Bitcoin price, use the Coindesk API:</p><p><code>const char* host = "api.coindesk.com";</code></p><p>Define the WiFi credentials:</p><p><code>const char* ssid = "wifi-network";</code><br><code>const char* password = "wifi-password";</code></p><p>In the setup() function, initialize the display and connect to the Wi-Fi network. In the loop() function, connect to the API server, prepare the URL, send the request, read the incoming data, extract the JSON answer, and display the Bitcoin price on the OLED screen.</p><p>Get the complete code in the <a target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/openhardwarelabs/bitcoin-ticker">GitHub repository</a> and change the Wi-Fi name and password in the sketch to match your Wi-Fi networks credentials. Upload the code to the board and open the serial monitor. The ESP8266 should receive the answer from the CoinDesk server almost immediately and display the price on the OLED screen.</p>
Add Alert LEDs to the Ticker
<p>Now that the hardest and most important part of the project is done, we can now proceed to the easier part – adding alert LEDs. We will add two LEDs to our setup that will indicate the price trend. Flashing the green LED will indicate that the price is going up, while flashing the red one will indicate that the price is going down.</p><p>Adding the hardware to the project is simple. All you need to do is place the LEDs in series with the 330Ω limiting resistors on the breadboard. Then connect the LEDs to the ESP8266 pin 5 (red LED) and pin 4 (green LED).</p><p>Apart from making changes to the hardware, you also need to tweak the code. Define which pins of the ESP8266 board the LEDs are connected to:</p><p><code>#define LED_PIN_UP 4</code><br><code>#define LED_PIN_DOWN 5</code></p><p>Define a variable to hold the previous price and the threshold of amount of change needed to flash the LEDs:</p><p><code>float previousValue = 0.0;</code><br><code>float threshold = 0.05;</code></p><p>Set the LED pins as outputs in the setup() function and check in the loop() section if the price went down or up compared to the threshold. Flash the red LED if the price went down and the green LED if the price went up.</p><p>You can now upload the updated project and see it in operation. Either of the LEDs should flash quickly depending on the fluctuation in price.</p>
Enhancements and Further Development
<p>In this project, we have managed to do several things: use the ESP8266 Wi-Fi board to get the price of bitcoin from a web API, display the price on an OLED screen and use LEDs to indicate price fluctuations. However, that's just a tip of the iceberg.</p><p>There are many other things that you can do with this project. For instance, you can tweak the setup to display the price of Bitcoin in more than one currency and add a switch button to change the displayed currency. You can also integrate everything into a nice PCB and build a fun product from it. Therefore, feel free and play around with the project and see what other cool stuff you can make it do.</p>
Wrapping Up
You have successfully created your first physical Bitcoin ticker! This project demonstrates the power of IoT applications by combining hardware components with web APIs to create a real-time data display. The ESP8266's WiFi capabilities, combined with the visual feedback from the OLED screen and LEDs, make this an excellent foundation for more advanced projects. Consider expanding this project by adding multiple currency support, cloud logging, or integrating it into a custom PCB design.