GET LIVE BITCOIN PRICE V2

by RonFrtek in Circuits > Arduino

711 Views, 1 Favorites, 0 Comments

GET LIVE BITCOIN PRICE V2

Get BITCOIN LIVE PRICE TTGO ESP32 - Cryptocurrency Tutorial V2

In this Version 2 tutorial we will learn how to get the Bitcoin price from the internet using the TTGO ESP32 and Visuino, we will also learn how to add a SSL certificate to the ESP32 board.

In this tutorial we are going to use Bitstamp API access, In the first original tutorial we were using a Coindesk API.
Link to the first tutorial here

Watch the Video!

What You Will Need

FJ2UWKAKELE68YW.jpg
VisuinoAdvrtisementNewDesign1.jpg
Wifi-1-icon.png

Start Visuino, and Select the Arduino TTGO T-Display ESP32 Board Type

FRBIHI1KSKPYNHX.jpg
2020-12-07_1-41-57.jpg

The Visuino: https://www.visuino.eu also needs to be installed. Download Free version or register for a Free Trial.

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "TTGO T-Display ESP32" as shown on Picture 2

Get Server SSL Certificate for Your ESP

2021-10-24_17-44-18.jpg
2021-10-24_17-45-18.jpg
2021-10-24_17-45-45.jpg

  • Go to https://projects.petrucci.ch/esp32/?page=ssl and paste the https://www.bitstamp.net in the Edit box and click "Get Certificate" button (Picture1)
  • Click on the "DigiCert SHA2 Extended Validation Server CA" Image (Picture2)
  • (Picture 3) In the Table below "cert:" select the certificate field and copy it to the Clipboard (you will need it in the next step)

In Visuino Set WiFi

FG0627QKTYDLQ5J.jpg
FO80P8EKTYDLQ5K.jpg
FA2J66LKTYDLQ5F.jpg
F99NFALKTYDLQ5G.jpg
F11M7MZKTYDLQ5H.jpg
2021-10-24_17-50-12.jpg

  • Select TTGO T-Display ESP32 board and in the properties window expand "Modules>WiFi>Connect To Access Points
  • Click on the Connect To Access Points 3 Dots
  • In the AccessPoints window drag "WiFi Access Point" to the left side
  • In the properties window set SSID (name of your WiFi hotspot or router)
  • In the properties window set Password (password of your WiFi hotspot or router)
  • Close AccessPoints window
  • Select TTGO T-Display ESP32 board and in the properties window expand "Modules>WiFi>Sockets
  • Click on the Sockets 3 Dots
  • In the "Sockets window" drag TCP/IP Secure Client (SSL) to the left
  • In the properties window set Host to: www.bitstamp.net
  • select "CACert" and click on the 3 dots button and in the "CACert window" paste the Certificate that you got in the previous step
  • Close the "Sockets window"

In Visuino Set Display

bitcoin-icon64.png
2021-10-24_17-56-19.jpg
2021-10-24_17-56-40.jpg
2021-10-24_17-56-57.jpg
2021-10-24_17-57-22.jpg
2021-10-24_17-57-39.jpg
2021-10-24_17-57-56.jpg
2021-10-24_17-58-21.jpg
2021-10-24_17-58-53.jpg
2021-10-24_17-59-34.jpg
2021-10-24_18-00-05.jpg
2021-10-24_17-59-14.jpg
  • Select TTGO T-Display ESP32 board and in the properties window expand "Modules>Display>Orientation"
  • Set Orientation to:goRight

Select TTGO T-Display ESP32 board and in the properties window expand "Modules>Display>Elements" Click on the Elements 3 Dots

  • In the Elements window Drag "Draw Text" to the left and in the properties window set size to 2 and text to ASK.
  • In the Elements window Drag "Text Field" to the left and in the properties window set size to 3, color to "aclGold" and Y to 20.
  • In the Elements window Drag another "Draw Text" to the left and in the properties window set size to 2 ,text to BID and Y to 48.
  • In the Elements window Drag another "Text Field" to the left and in the properties window set size to 3, color to "aclGold" and Y to 66.
  • In the Elements window Drag another "Draw Text" to the left and in the properties window set size to 2 ,text to LAST and Y to 92.
  • In the Elements window Drag another "Text Field" to the left and in the properties window set size to 3, color to "aclGold" and Y to 110.
  • Optionally you can add bitmap to the Display, to do that in the Elements window drag "Draw Bitmap" to the left side and in the properties window set X to 160, Y to 30
  • Click on the Bitmap 3 Dots
  • In the Bitmap Editor Load the Bitcoin bitmap (picture 1) and close the Bitmap editor
  • You can find other bitmaps at https://iconarchive.com/search?q=bitcoin

In Visuino Add Components

F7OD8PKKTYDLSUR.jpg
F7CPEX1KTYDLSUU.jpg
F98HW09KTYDLSUT.jpg
FEIXAMXKTYDLSUV.jpg
FT3FTZ3KTYDLSUY.jpg
FBP4N2DKTYDLSUS.jpg
2021-10-24_18-11-52.jpg
FYAR7K7KTYDLSUW.jpg
2021-10-24_18-14-13.jpg
FXHP4FQKTYDLSUX.jpg
2021-10-24_18-10-38.jpg

  • Add "HTTP Client" component
  • Select "HTTPClient1" and in the properties window set Host to www.bitstamp.net
  • Click on the Requests 3 Dots
  • In the "Requests window" drag "GET" to the left side
  • In the properties window set URL to: /api/v2/ticker/btcusd/
  • Close the requests window
  • Add "Char To Text" component
  • Select "CharToText1" and in the properties window se Max Length to 2000
  • Add "Clock Generator" component
  • Select "ClockGenerator1" and in the properties window set frequency to 0.2, this will be the refresh time, you can adjust it if you want.
  • Add "Delay" components and in the properties window set "Interval (uS)" to 2000000
  • Add "Split JSON Object" component

In Visuino Parsing JSON

FTEJZ01KTYDLU2G.jpg
2021-10-24_18-20-05.jpg

  • With the mouse right click on the "SplitJSON1" and in the menu click on the "Parse JSON Object.."
In the "JSON Object" window paste this sample code(avalible on https://www.bitstamp.net/api/v2/ticker/btcusd/ )

Or copy paste the following:

{"high": "61517.51", "last": "59946.59", "timestamp": "1635092369", "bid": "59913.89", "vwap": "60635.81", "volume": "1111.78956785", "low": "59510.00", "ask": "59930.59", "open": "61306.64"}

  • Close the "JSON Object" window
  • "SplitJSON1" component will now create new pins

In Visuino Connecting Components

btc.png
2021-10-24_18-28-04.jpg
2021-10-24_18-27-39.jpg
2021-10-24_18-27-26.jpg

  • Connect "ClockGenerator1" pin Out to "HTTPClient1" pin Clock
  • Connect "TTGO T-Display ESP32" pin [Connected] to "Delay1" pin Start
  • Connect "TTGO T-Display ESP32" pin [Remote Connected] to "HTTPClient1" pin Clock
  • Connect "HTTPClient1" pin Content to "CharToText1" pin In
  • Connect "HTTPClient1" pin to TTGO T-Display ESP32 > WiFi>TCP Secure Client1 pin In
  • Connect "Delay1" pin Out to "CharToText1" pin Clock and TTGO T-Display ESP32 > WiFi>TCP Secure Client1 pin Disconnect
  • Connect "CharToText1" pin Out to "SplitJSON1" pin In
  • Connect "SplitJSON1" pin [Ask] to TTGO T-Display ESP32 >Display Text Field1 pin[In]

  • Connect "SplitJSON1" pin [Bid] to TTGO T-Display ESP32 >Display Text Field2 pin[In]
  • Connect "SplitJSON1" pin [Last] to TTGO T-Display ESP32 >Display Text Field3 pin[In]
  • Note: you can also play with the other pins from "SplitJSON1" component

Generate, Compile, and Upload the Code

F3U9JCIKTYDLVCT.png

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the TTGO ESP32 module it will connect to the network and display the current Bitcoin price data.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Tutorial, you can download it and open it in Visuino: https://www.visuino.eu

Note: In the File Project when you open it in Visuino, change the WiFi settings (Access point and password) to your settings.

You can learn more about the Bitstamp API here https://www.bitstamp.net/api/