adding code examples for Metro M7
This commit is contained in:
parent
f9be51b204
commit
a3fd1012f6
2 changed files with 84 additions and 0 deletions
19
Metro_M7_Examples/Digital_Input/code.py
Normal file
19
Metro_M7_Examples/Digital_Input/code.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
CircuitPython Digital Input Example - Blinking an LED using a button switch.
|
||||
"""
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
button = digitalio.DigitalInOut(board.D5)
|
||||
button.switch_to_input(pull=digitalio.Pull.UP)
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
led.value = True
|
||||
else:
|
||||
led.value = False
|
||||
65
Metro_M7_Examples/WiFi/code.py
Normal file
65
Metro_M7_Examples/WiFi/code.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os
|
||||
import board
|
||||
import busio
|
||||
from digitalio import DigitalInOut
|
||||
import adafruit_requests as requests
|
||||
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
|
||||
from adafruit_esp32spi import adafruit_esp32spi
|
||||
|
||||
print("ESP32 SPI webclient test")
|
||||
|
||||
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
|
||||
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
|
||||
|
||||
# If you are using a board with pre-defined ESP32 Pins:
|
||||
esp32_cs = DigitalInOut(board.ESP_CS)
|
||||
esp32_ready = DigitalInOut(board.ESP_BUSY)
|
||||
esp32_reset = DigitalInOut(board.ESP_RESET)
|
||||
|
||||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
|
||||
requests.set_socket(socket, esp)
|
||||
|
||||
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
|
||||
print("ESP32 found and in idle mode")
|
||||
print("Firmware vers.", esp.firmware_version)
|
||||
print("MAC addr:", [hex(i) for i in esp.MAC_address])
|
||||
|
||||
for ap in esp.scan_networks():
|
||||
print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))
|
||||
|
||||
print("Connecting to AP...")
|
||||
while not esp.is_connected:
|
||||
try:
|
||||
esp.connect_AP(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
|
||||
except OSError as e:
|
||||
print("could not connect to AP, retrying: ", e)
|
||||
continue
|
||||
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
|
||||
print("My IP address is", esp.pretty_ip(esp.ip_address))
|
||||
print(
|
||||
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
|
||||
)
|
||||
print("Ping google.com: %d ms" % esp.ping("google.com"))
|
||||
|
||||
# esp._debug = True
|
||||
print("Fetching text from", TEXT_URL)
|
||||
r = requests.get(TEXT_URL)
|
||||
print("-" * 40)
|
||||
print(r.text)
|
||||
print("-" * 40)
|
||||
r.close()
|
||||
|
||||
print()
|
||||
print("Fetching json from", JSON_URL)
|
||||
r = requests.get(JSON_URL)
|
||||
print("-" * 40)
|
||||
print(r.json())
|
||||
print("-" * 40)
|
||||
r.close()
|
||||
|
||||
print("Done!")
|
||||
Loading…
Reference in a new issue