- Published on
WiFi-connected Dollar to Turkish Lira to the LCD Screen
- Authors
- Name
- Batınay Ünsel
- @btny_unsl
WiFi-connected Dollar to Turkish Lira to the LCD Screen
This project utilizes a microcontroller to display exchange rates of major currencies.
Requirements
To run this project, you will need the following components:
- Microcontroller compatible with MicroPython (e.g., ESP8266, ESP32, Raspberry Pi Pico W)
- LCD display
- LCD adapter with I2C interface
- Wi-Fi connection
Installation
- Download or clone the project files into a folder.
- Flash the MicroPython firmware onto the microcontroller(In this project, Raspberry Pi Pico-W).
- Download and install the required libraries onto the microcontroller.
- Make the necessary connections: Connect the LCD display and I2C adapter to the microcontroller.
- Enter your Wi-Fi network's SSID and password into the appropriate variables.
API
This project utilizes the Genel Para API to retrieve exchange rates. The API used in this project is provided by Genel Para and can be accessed at the following endpoint:
- API URL:
https://api.genelpara.com/embed/doviz.json
The API provides exchange rate data for various currencies, including USD, EUR, GBP, etc.
Please note that you may need to sign up or obtain an API key from Genel Para to use their API effectively. Refer to the Genel Para API documentation for more details on accessing and using the API.
Code
dollarlcd.py
import urequests as requests
import time
import network
import socket
from machine import Pin, I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
# Wi-Fi connect
ssid = 'WiFiName'
password = 'password'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('Connected')
status = wlan.ifconfig()
print( 'ip = ' + status[0] )
# API URL
api_url = 'https://api.genelpara.com/embed/doviz.json'
def get_dollar_value():
try:
response = requests.get(api_url)
data = response.json()
#return float(data[0]['data']['value'])
#current_USD_value = (data[0]['data']['value'])
current_USD_value = (data["USD"]["satis"])
return current_USD_value
except KeyError:
print('There is illegal data in your API response.')
return None
def display_dollar_value():
dollar_value = get_dollar_value()
if dollar_value is not None:
lcd.clear()
lcd.putstr('Dollar: ' + str(dollar_value))
try:
while True:
display_dollar_value()
time.sleep(60) # updating every 60 seconds
except KeyboardInterrupt:
pass
Usage
- Power up the microcontroller.
- The current exchange rate for USD will be displayed on the LCD screen.
- The value will be updated every 60 seconds.
Photo Example
Contributing
- Fork this project.
- Create a new branch:
git checkout -b my-feature-branch
- Make your changes and save:
git commit -am 'Description of your changes'
- Push to your branch:
git push origin my-feature-branch
- Open a new Pull Request on GitHub.