Demonstration Video
The device updates itself every hour.
All the components fit inside the casing. The original version was meant to have a 9v battery fit inside to power the device, but it was found that a micro USB cable is more power efficient.


/*Crypto Tracker e-paper display Project
*
* By: Matteo Fazio
* 2021
*/
//Wifi
#include <WiFi.h>
#include <Wire.h>
//Reading from coindesk
#include <ArduinoJson.h>
#include "arduino_secrets.h"
//Dispay
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <U8g2_for_Adafruit_GFX.h>
//#include "imagedata.h"
// 1,54" 200x200 V2 (new):ESP32:
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(26, 25, 33, 27)); // CS, DC, RST, Busy, clk =18 // GDEH0154D67
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
double refreshRate = 3600000000;
// 900000 = 15mins
//3600000000 = 1 hour
// WiFi settings
const char* ssid = SECRET_SSID;
const char* password = SECRET_PASS;
const char* host = "api.coindesk.com"; // API server
int price = 0;
//int previousPrice =0;
void setup() {
// Serial
Serial.begin(115200);
delay(10);
//Connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
// Initialize display
display.init();
display.setFullWindow();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
/*
String priceTrend(int price, int previousPrice){
String trend = "";
if(price > previousPrice)
return trend = "^";
else
return trend = "v";
Serial.print(trend);
}
*/
//const char BitcoinPrice[] = "BitcoinPrice: ";
void displayBTC(float price){
String priceString = String(price, 0);
String BTC = "BTC $";
//String trend = priceTrend(price, previousPrice);
String BitcoinPrice = BTC + priceString;
// + trend
display.setRotation(1);
display.setFont(&FreeMonoBold12pt7b);
//u8g2Fonts.setFont(u8g2_font_logisoso34_tf);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(BitcoinPrice, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.print(BitcoinPrice);
}while (display.nextPage());
}
int attempts = 0;
void loop() { //__main___
// Connect to API
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
//Create a URI for the request
String url = "/v1/bpi/currentprice.json";
//http://api.coindesk.com/v1/bpi/currentprice/BTC.json
Serial.print("Requesting URL: ");
Serial.println(url);
//Ssend the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(100);
// Read all the lines of the reply from server and print them to Serial
String answer;
while(client.available()){
String line = client.readStringUntil('\r');
answer += line;
}
client.stop();
Serial.println();
Serial.println("closing connection");
// Process answer
Serial.println();
Serial.println("Answer: ");
Serial.println(answer);
// Convert to JSON
String jsonAnswer;
int jsonIndex;
for (int i = 0; i < answer.length(); i++) {
if (answer[i] == '{') {
jsonIndex = i;
break;
}
}
// Get JSON data
jsonAnswer = answer.substring(jsonIndex);
Serial.println();
Serial.println("JSON answer: ");
Serial.println(jsonAnswer);
jsonAnswer.trim();
// Get rate as float
int rateIndex...
Read more »
Please can you provide the pinout connections between the esp32 and the e-ink screen. Thanks