importtimeimport board
import busio
from digitalio import DigitalInOut, Direction, Pull
from adafruit_espatcommands import adafruit_espatcommands
import ujson
from adafruit_ht16k33 import segments
importgc
MY_SSID ="adafruit"
MY_PASS ="password"#URL = "http://wifitest.adafruit.com/testwifi/index.html"
URL ="http://api.coindesk.com/v1/bpi/currentprice.json"
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
resetpin = DigitalInOut(board.D5)# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
display = segments.Seg7x4(i2c)
display.print('----')print("Get bitcoin price online")print("Free memory:",gc.mem_free() / 1024)
esp = adafruit_espatcommands.espatcommands(uart,115200, reset_pin = resetpin, debug=True)print("Connected to AT software version ", esp.get_version())whileTrue:
try:
display.print('----')# Connect to WiFi if not alreadyif esp.remote_AP!= MY_SSID:
esp.join_AP(MY_SSID, MY_PASS)print("My IP Address:", esp.local_ip)# great, lets get the JSON data
header, body = esp.request_url(URL)
json = ujson.loads(body)
bitcoin = json["bpi"]["USD"]["rate_float"]print("USD per bitcoin:", bitcoin)
display.print(int(bitcoin))time.sleep(5 * 60)# 5 minutesexceptRuntimeError:
print("Failed to connect, retrying")continueprint(body)gc.collect()print("Free memory:",gc.mem_free() / 1024)
import time
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from adafruit_espatcommands import adafruit_espatcommands
import ujson
from adafruit_ht16k33 import segments
import gc
MY_SSID = "adafruit"
MY_PASS = "password"
#URL = "http://wifitest.adafruit.com/testwifi/index.html"
URL = "http://api.coindesk.com/v1/bpi/currentprice.json"
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
resetpin = DigitalInOut(board.D5)
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
display = segments.Seg7x4(i2c)
display.print('----')
print("Get bitcoin price online")
print("Free memory:", gc.mem_free() / 1024)
esp = adafruit_espatcommands.espatcommands(uart, 115200, reset_pin = resetpin, debug=True)
print("Connected to AT software version ", esp.get_version())
while True:
try:
display.print('----')
# Connect to WiFi if not already
if esp.remote_AP != MY_SSID:
esp.join_AP(MY_SSID, MY_PASS)
print("My IP Address:", esp.local_ip)
# great, lets get the JSON data
header, body = esp.request_url(URL)
json = ujson.loads(body)
bitcoin = json["bpi"]["USD"]["rate_float"]
print("USD per bitcoin:", bitcoin)
display.print(int(bitcoin))
time.sleep(5 * 60) # 5 minutes
except RuntimeError:
print("Failed to connect, retrying")
continue
print(body)
gc.collect()
print("Free memory:", gc.mem_free() / 1024)
Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.
Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.
Python for Microcontrollers — Python on Microcontrollers Newsletter: CircuitPython supported by 70 SBCs and more! #Python #Adafruit #CircuitPython @micropython @ThePSF
Adafruit IoT Monthly — OpenCV Critter Cam, LoraWAN on Raspberry Pi 2040, and more!
Comments Off on Display the price of Bitcoin with CircuitPython using an Adafruit Feather and HUZZAH ESP8266 breakout @adafruit @circuitpython #bitcoin @esp8266