Bitcoin Ticker - ESP32 HELTEC onboard OLED

Hi all,

I have a Heltec ESP32 with onboard OLED screen and the LoRa radio onboard.
I’m wanting to use it for a bitcoin ticker and I’ve found the code:

The code works perfectly, I setup the serial monitor and all the correct information is sent to the to the monitor as required.

I have tried to use commands to get some of this data to display on the on-board OLED but i’m really struggling. I’ve spent over 6 hours trying things and haven’t got anywhere. Could anyone help me please?

The OLED works as I’ve loaded the HELTEC examples, and they work fine.

Any help would be greatly appreciated. Thanks.

Fixed it with this:

#include <Wire.h>
#include <U8g2lib.h>
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(15,4,16);

void setup() {
u8x8.begin();
u8x8.setPowerSave(0);
Serial.begin(115200);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
u8x8.setPowerSave(0);
u8x8.setFont(u8x8_font_5x7_f);
// u8x8.drawString(0,0,“Hello World!”);
u8x8.refreshDisplay(); // only required for SSD1606/7
delay(2000);
u8x8.drawString(0,0,“ConnectingWifi:”);

Here is my final code, it works nice.

Sorry if this is very basic, I’m a noob.

#include <CoinMarketCapApi.h>

/*******************************************************************

  • An example of getting ticker info from coinmarketcap.com *
  •                                                             *
    
  • Written by Brian Lough *
    *******************************************************************/

//------- Install From Library Manager -------
#include <ArduinoJson.h>

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <U8g2lib.h>

U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(15,4,16);

//------- Replace the following! ------
char ssid[] = “S S I D”; // your network SSID (name)
char password[] = “P A S S W R D”; // your network key

WiFiClientSecure client;
CoinMarketCapApi api(client);

// CoinMarketCap’s limit is “no more than 10 per minute”
// Make sure to factor in if you are requesting more than one coin.
unsigned long api_mtbs = 60000; //mean time between api requests
unsigned long api_due_time = 0;

void setup() {

u8x8.begin();
u8x8.setPowerSave(0);

Serial.begin(115200);

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");

u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setFont(u8x8_font_5x7_f);
// u8x8.drawString(0,0,“Hello World!”);
u8x8.refreshDisplay(); // only required for SSD1606/7
delay(500);
u8x8.drawString(0,0,“ConnectingWifi:”);
delay(100);
Serial.println(ssid);
u8x8.drawString(0,1,ssid);
delay(100);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println(“WiFi connected”);
u8x8.drawString(0,3,“WiFi connected”);
Serial.println("IP address: ");

IPAddress ip = WiFi.localIP();
Serial.println(ip);

u8x8.setCursor(0, 4);
u8x8.print(ip);

u8x8.drawString(3,6,“H O D L”);

delay(2500);
u8x8.clear();

}

void printTickerData(String ticker) {

u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setFont(u8x8_font_5x7_f);
// u8x8.drawString(0,0,“Hello World!”);
u8x8.refreshDisplay(); // only required for SSD1606/7
delay(200);

Serial.println("---------------------------------");
Serial.println("Getting ticker data for " + ticker);

// Ticker unfortunately is not the symbol for some reason.
// Go to CoinMarketCap.com and select the coin you would like to check
// The ticker name makes up the last part of the URL
// e.g: http://coinmarketcap.com/currencies/bitcoin/ , “bitcoin” is the ticker value

// Currency is optional, so you can pass only ticker if you want.
// Check out the currency drop down on CoinMarketCap.com to get available values
CMCTickerResponse response = api.GetTickerInfo(ticker, “eur”);
if (response.error == “”) {
Serial.print("ID: ");
Serial.println(response.id);

Serial.print("Name: ");
Serial.println(response.name);
Serial.print("Symbol: ");
Serial.println(response.symbol);

Serial.print("Rank: ");
Serial.println(response.rank); 

Serial.print("Price in USD: ");
Serial.println(response.price_usd);
Serial.print("Price in BTC: ");
Serial.println(response.price_btc);

Serial.print("24h Volume USD: ");
Serial.println(response.volume_usd_24h);
Serial.print("Market Cap USD: ");
Serial.println(response.market_cap_usd);

Serial.print("Available Supply: ");
Serial.println(response.available_supply);
Serial.print("Total Supply: ");
Serial.println(response.total_supply);

Serial.print("Percent Change 1h: ");
Serial.println(response.percent_change_1h);
Serial.print("Percent Change 24h: ");
Serial.println(response.percent_change_24h);
Serial.print("Percent Change 7d: ");
Serial.println(response.percent_change_7d);
Serial.print("Last Updated: ");
Serial.println(response.last_updated);

// These fields will not come back if you do not request a currency
Serial.print("Price in requested currecy: ");
Serial.println(response.price_currency);
Serial.print("24h Volume in requested currency: ");
Serial.println(response.volume_currency_24h);
Serial.print("Market Cap in requested currency: ");
Serial.println(response.market_cap_currency);

//show it on the screen =
u8x8.setCursor(0, 0);
u8x8.print(response.name);

u8x8.drawString(0, 1,"USD: ");
u8x8.setCursor(8, 1);
u8x8.print(response.price_usd);

u8x8.drawString(0, 2,"1hr %: ");
u8x8.setCursor(8, 2);
u8x8.print(response.percent_change_1h);

u8x8.drawString(0, 3,"24hr %: ");
u8x8.setCursor(8, 3);
u8x8.print(response.percent_change_24h);

u8x8.drawString(0, 4,"7day %: ");
u8x8.setCursor(8, 4);
u8x8.print(response.percent_change_7d);

u8x8.drawString(0, 5,"Rank: ");
u8x8.setCursor(8, 5);
u8x8.print(response.rank);
delay(8000);

} else {
Serial.print(“Error getting data: “);
Serial.println(response.error);
}
Serial.println(”---------------------------------”);
}

void loop() {

// u8x8.begin();
// u8x8.setPowerSave(0);
// u8x8.setFont(u8x8_font_chroma48medium8_r);
// u8x8.drawString(0,0,“Hello World!”);
// u8x8.refreshDisplay(); // only required for SSD1606/7
// delay(2000);

unsigned long timeNow = millis();
if ((timeNow > api_due_time)) {
printTickerData(“litecoin”);
printTickerData(“ethereum”);
printTickerData(“dero”);
printTickerData(“bitcoin”);
api_due_time = timeNow + api_mtbs;
}
}

thank you for your sharing.

Getting this error upon verifying:

exit status 1
stray ‘\342’ in program

I have found another way that works for anyone interested. OP is outdated and requires editing. You can follow this post below for another method.

ESP32-Crypto-Currency-Ticker/Coin_Gecko.ino at master · GRHMLGGT/ESP32-Crypto-Currency-Ticker · GitHub

Additionally, I am working on improvements to the original code.