which rdy reset cs pin to use for esp32 feather V2 spi socket to adafruit.io

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
notsource
 
Posts: 2
Joined: Wed May 31, 2023 10:58 am

which rdy reset cs pin to use for esp32 feather V2 spi socket to adafruit.io

Post by notsource »

Hi im not sure which Pins I need to use with SPI . I tried gpio5 (cs), gpio4(rdy) gpio13 (reset). but this attribute is not in board. dir(board) i see onlx AXX DXX. Even if I check the Pinout layout there is HSPI/D/Q/CS0/HD/WP/CLK. Im confused :(


board: adafruit esp32 huzza feather V2
os: adafruit-circuitpython-adafruit_feather_esp32_v2-en_US-8.1.0.bin
libs: adafruit-circuitpython-bundle-8.x-mpy-20230601

Code: Select all

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs_pin = digitalio.DigitalInOut(board.D15)
ready_pin = digitalio.DigitalInOut(board.A4)
reset_pin = digitalio.DigitalInOut(board.A0)
esp = esp32spi.ESP_SPIcontrol(spi, cs_pin, ready_pin, reset_pin)

Code: Select all

import time
import board
import busio
import adafruit_sgp30
import neopixel
import digitalio
import adafruit_esp32spi.adafruit_esp32spi as esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
import ssl

# Initialize Neopixel on pin D0 with 1 LED
pixel_pin = board.NEOPIXEL
num_pixels = 1
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1)

test = dir(board)
print(test)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs_pin = digitalio.DigitalInOut(board.D15)
ready_pin = digitalio.DigitalInOut(board.A4)
reset_pin = digitalio.DigitalInOut(board.A0)




esp = esp32spi.ESP_SPIcontrol(spi, cs_pin, ready_pin, reset_pin)

# Set up Adafruit.io credentials
AIO_USERNAME = "user"
AIO_KEY = "key"
AIO_GROUP = "adafruit"
AIO_FEED_ECO2 = "sgp30-eCO2"
AIO_FEED_TVOC = "sgp30-TVOC"

# Create an HTTPS socket and connect to Adafruit.io
socket.set_interface(esp)
context = ssl.create_default_context()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the server
server_address = ("io.adafruit.com", 443)
sock.connect(server_address)

# Wrap the socket with SSL
wrapped_sock = ssl.wrap_socket(sock, server_side=False, ssl_context=context)


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the server
server_address = ("io.adafruit.com", 443)
sock.connect(server_address)

# Wrap the socket with SSL
wrapped_sock = ssl.wrap_socket(sock, server_side=False, ssl_context=context)

# Function to send data to Adafruit.io
def send_to_adafruit_io(value):
    url = "https://io.adafruit.com/api/v2/{}/feeds/{}/data".format(AIO_USERNAME, AIO_FEED)
    payload = {"value": value}
    headers = {"X-AIO-KEY": AIO_KEY, "Content-Type": "application/json"}
    response = adafruitio.post(url, json=payload, headers=headers)
    print("Data sent to Adafruit.io:", response.text)

# Define the pulse function
def pulse_green():
    
    for i in range(0, 255, 5):
        if i <= 162:
          b = i
          
        pixels[0] = (0, i, b)
        # time.sleep(0.01)
        time.sleep(0.01)

    for i in range(255, -1, -5):
        if b > 4:
          b = b - 5
          
        pixels[0] = (0, i, b)
        time.sleep(0.01)
        
def pulse_yellow():
    
    for i in range(0, 256, 5):
        pixels[0] = (i, i, 0)
        time.sleep(0.01)
    for i in range(255, -1, -5):
        pixels[0] = (i, i, 0)
        time.sleep(0.01)

i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)

# Create library object on our I2C port
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)

print("SGP30 serial #", [hex(i) for i in sgp30.serial])

# sgp30.set_iaq_baseline(0x8973, 0x8AAE)
# sgp30.set_iaq_relative_humidity(celsius=23, relative_humidity=44)

elapsed_sec = 0
c = 0

while True:
    # Pulse the pixel with green blue color 0,162,255
    
    print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
    if c == 10:
      c = 0
      # Send the eCO2 data to Adafruit.io
      send_to_adafruit_io(AIO_FEED_ECO2, sgp30.eCO2)
      # Send the TVOC data to Adafruit.io
      send_to_adafruit_io(AIO_FEED_TVOC, sgp30.TVOC)
      # Wait for some time before sending the next data
      time.sleep(3)  # Adjust the delay as per your requirements
    
    c = c + 1
    time.sleep(1)
    elapsed_sec += 1
    if elapsed_sec > 10:
        elapsed_sec = 0
        print(
            "**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
            % (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
        )
    if sgp30.eCO2 > 400 and sgp30.TVOC == 0:
        print(
            "***** eCO2 level > 400 Pulse Yellow*****")
        pulse_yellow()
    if sgp30.eCO2 > 400 or sgp30.TVOC > 0:
        print(
            "***** eCO2 level > 400 Pulse Yellow*****")
        pulse_yellow()
    else:
        pulse_green()



regards


Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”