Skip to content

Commit e412b28

Browse files
authored
Merge pull request #15 from brentru/add-espatcontrol-support
ESP_AT Support
2 parents 52f8b9c + 946eee9 commit e412b28

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

README.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ Dependencies
2121
This driver depends on:
2222

2323
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
24-
* `Adafruit CircuitPython ESP32SPI <https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI>`_
24+
25+
You'll also need a library to communicate with an ESP32 as a coprocessor using a WiFiManager object. This library supports connecting an ESP32 using either SPI or UART.
26+
27+
* SPI: `Adafruit CircuitPython ESP32SPI <https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI>`_
28+
29+
* UART: `Adafruit CircuitPython ESP_ATcontrol <https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol>`_
2530

2631
Please ensure all dependencies are available on the CircuitPython filesystem.
2732
This is easily achieved by downloading
@@ -115,4 +120,4 @@ Now, once you have the virtual environment activated:
115120
116121
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
117122
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
118-
locally verify it will pass.
123+
locally verify it will pass.
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Usage example of the ESP32 over UART
3+
using the CircuitPython ESP_ATControl library.
4+
5+
Dependencies:
6+
* https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol
7+
"""
8+
from random import randint
9+
import board
10+
import busio
11+
from digitalio import DigitalInOut
12+
13+
# Import Adafruit IO REST Client
14+
from adafruit_io.adafruit_io import RESTClient, AdafruitIO_RequestError
15+
16+
# ESP32 AT
17+
from adafruit_espatcontrol import adafruit_espatcontrol, adafruit_espatcontrol_wifimanager
18+
19+
#Use below for Most Boards
20+
import neopixel
21+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
22+
23+
#Uncomment below for ItsyBitsy M4#
24+
#import adafruit_dotstar as dotstar
25+
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
26+
27+
#Uncomment below for Particle Argon#
28+
#status_light = None
29+
30+
# Get wifi details and more from a secrets.py file
31+
try:
32+
from secrets import secrets
33+
except ImportError:
34+
print("WiFi secrets are kept in secrets.py, please add them there!")
35+
raise
36+
37+
# With a Metro or Feather M4
38+
uart = busio.UART(board.TX, board.RX, timeout=0.1)
39+
resetpin = DigitalInOut(board.D5)
40+
rtspin = DigitalInOut(board.D6)
41+
42+
# With a Particle Argon
43+
"""
44+
RX = board.ESP_TX
45+
TX = board.ESP_RX
46+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
47+
rtspin = DigitalInOut(board.ESP_CTS)
48+
uart = busio.UART(TX, RX, timeout=0.1)
49+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
50+
from digitalio import Direction
51+
esp_boot.direction = Direction.OUTPUT
52+
esp_boot.value = True
53+
"""
54+
55+
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200,
56+
reset_pin=resetpin, rts_pin=rtspin, debug=False)
57+
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)
58+
59+
# Set your Adafruit IO Username and Key in secrets.py
60+
# (visit io.adafruit.com if you need to create an account,
61+
# or if you need your Adafruit IO key.)
62+
ADAFRUIT_IO_USER = secrets['adafruit_io_user']
63+
ADAFRUIT_IO_KEY = secrets['adafruit_io_key']
64+
65+
# Create an instance of the Adafruit IO REST client
66+
io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)
67+
68+
try:
69+
# Get the 'temperature' feed from Adafruit IO
70+
temperature_feed = io.get_feed('temperature')
71+
except AdafruitIO_RequestError:
72+
# If no 'temperature' feed exists, create one
73+
temperature_feed = io.create_new_feed('temperature')
74+
75+
# Send random integer values to the feed
76+
random_value = randint(0, 50)
77+
print('Sending {0} to temperature feed...'.format(random_value))
78+
io.send_data(temperature_feed['key'], random_value)
79+
print('Data sent!')
80+
81+
# Retrieve data value from the feed
82+
print('Retrieving data from temperature feed...')
83+
received_data = io.receive_data(temperature_feed['key'])
84+
print('Data from temperature feed: ', received_data['value'])

0 commit comments

Comments
 (0)