In this example we will display the price in USD of 1 bitcoin, the data is taken from coindesk’s API and displayed on an oled display.
This is similar to our previous examples, you do not need to use a Wemos mini or the OLED shield below but this makes the project easier to build
Here is the oled shield for the Wemos mini
Here is the wemos mini
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #include <ESP8266WiFi.h> #include <Wire.h> #include <SFE_MicroOLED.h> #include <ArduinoJson.h> const char * ssid = "iainhendry" ; const char * pass = "iain061271" ; #define PIN_RESET 255 // #define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D String id; String value; String json; MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C Example WiFiClient client; // delay between updates const unsigned long postingInterval = 60L * 1000L; unsigned long lastConnectionTime = 0; void setup() { delay(100); Serial.begin(115200); Serial.println(); Serial.println(); Serial.print( "Connecting to " ); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print( "." ); } Serial.println( "" ); Serial.println( "WiFi connected" ); Serial.println( "IP address: " ); Serial.println(WiFi.localIP()); Serial.print( "Connecting to " ); oled.begin(); oled.clear(ALL); oled.setCursor(0,0); oled.display(); oled.clear(PAGE); oled.clear(ALL); oled.print( "Bitcoin price" ); oled.setCursor(0,1); oled.print( "loading.." ); oled.display(); // Display what's in the buffer (splashscreen) delay(50); } int check_connect = 0; void httpRequest() { client.stop(); // if there's a successful connection: if (client.connect( "api.coindesk.com" , 80)) { Serial.println( "connecting..." ); client.println( "GET /v1/bpi/currentprice.json HTTP/1.1" ); client.println( "Host: api.coindesk.com" ); client.println( "User-Agent: ESP8266/1.1" ); client.println( "Connection: close" ); client.println(); lastConnectionTime = millis(); } else { // if you couldn't make a connection: Serial.println( "connection failed" ); } } void loop() { int cnt; if (cnt++ == 10000) { cnt = 0; if (check_connect++ == 50) { check_connect = 0; if (WiFi.status() != WL_CONNECTED) { } } } if (millis() - lastConnectionTime > postingInterval) { httpRequest(); unsigned int i = 0; //timeout counter int n = 1; // char counter char json[500] = "{" ; while (!client.find( "\"USD\":{" )){} while (i<20000) { if (client.available()) { char c = client.read(); json[n]=c; if (c== '}' ) break ; n++; i=0; } i++; } StaticJsonBuffer<500> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(json); String newjson = root[ "code" ]; String value = root[ "rate" ]; id = newjson.substring(9,12); // value = newjson.substring(41,51); oled.display(); oled.clear(PAGE); // Clear the display's internal memory oled.clear(ALL); // Clear the library's display buffer oled.setCursor(0,1); oled.print(value); oled.display(); id= "" ; value= "" ; } } |
testing
You should see something like this on the oled display

Links
Here are some of the products I used
by hotcoin.net
Looks like there is a memory leak somewhere as the sketch stops after about 95 – 100 iterations.