Skip to content

After 15 min or so my FeatherS3 crashes unexpectedly #7405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xav-e opened this issue Jan 1, 2023 · 12 comments
Closed

After 15 min or so my FeatherS3 crashes unexpectedly #7405

xav-e opened this issue Jan 1, 2023 · 12 comments

Comments

@xav-e
Copy link

xav-e commented Jan 1, 2023

CircuitPython version

Adafruit CircuitPython 7.3.3 on 2022-08-29; FeatherS3 with ESP32S3

Code/REPL

# ------------------------------------------------------------------------------------
# First Module
"""
BMP280 -> Sensor Data> Temperature, pressure, and altitude
"""
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""Simpletest Example that shows how to get temperature,
   pressure, and altitude readings from a BMP280"""
# ------------------------------------------------------------------------------------
# Second Module
"""
OLED-FEATHERWING
"""
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: Unlicense
"""
Author: Mark Roberts (mdroberts1243) from Adafruit code
This test will initialize the display using displayio and draw a solid white
background, a smaller black rectangle, miscellaneous stuff and some white text.
"""
# ------------------------------------------------------------------------------------
# Thrid Module
"""DHT11 - Temperature and Humidity measurement"""
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
# SPDX-License-Identifier: MIT
# ------------------------------------------------------------------------------------
# Fourth Module
"""Potenciometers"""
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# ------------------------------------------------------------------------------------
# Fifth Module
""" Lux Sensor"""
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries

# SPDX-License-Identifier: Unlicense
# ------------------------------------------------------------------------------------
# Sixth Module
""" DS1307 - RTC Module"""
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
#Simple demo of reading and writing the time for the DS1307 real-time clock.
# Change the if False to if True below to set the time, otherwise it will just
# print the current date and time every second.  Notice also comments to adjust
# for working with hardware vs. software I2C.
"""
# ------------------------------------------------------------------------------------

# Seventh Module
"""MQTT Broker & Wi-Fi Connection module"""
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# ------------------------------------------------------------------------------------

""" Modifications to the models issued by Xavier Zambrano for Aqua-S3"""
# ------------------------------------------------------------------------------------

"""Imported Libraries and Modules"""

# ------------------------------------------------------------------------------------
# We import the board library which is used to provide access to a series of board-specific objects, including pins.
import board

# We import the displayio module contains classes to manage display output including synchronizing with refresh rates and partial updating
import displayio

# We import the terminalio module contains classes to display a character stream on a display. The built in font is available as terminalio.FONT
import terminalio

# We import the time module provides various time-related functions. We'll use it to implement delays in our code
import time

# We import the gc library to check how much memory our code is taking up
import gc

# We import the bmp280 library to set the interface with the BMP280 Temperature, Pressure, Sea level Pressure & Altitude sensors
import adafruit_bmp280

# We import the dht library to set the interface with the DHT11 Temperature & Humidity sensor
import adafruit_dht

# We import the bh1750 library to set the interface with the BH1750 Lux sensor
import adafruit_bh1750

# We import the ds1307 library to define the interface with the DS1307 RTC Module
import adafruit_ds1307

# We import the sh1107 library to interface with the methods of the featherwing OLED 128x64 OLED display
import adafruit_displayio_sh1107

# We import the ssl module provides SSL contexts to wrap sockets in, i.e., it defines requirements for secure communication between connection oriented sockets
# So, this module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption
# and peer authentication facilities for network sockets, both client-side and server-side
import ssl

# We import the socket module which provides sockets through a pool.
# So, is a simple socket pool that suports multiple factories and backends that allows us to send messages across our network.
import socketpool

# We import the wifi module which provides necessary low-level functionality for managing wifi connections. Use socketpool for communicating over the network.
# This module is required to establish a connection between our ESP32-S3 and our LAN
import wifi

# We use the following library to set up the required methods to send and receive messages using the MQTT protocol
import adafruit_minimqtt.adafruit_minimqtt as MQTT

# We import the json module to interface with JSON Files
import json

# We import the APDS9960 lybrary to set the interface with the APDS9960 RGB COLOR, Proximity and Gesture sensors
from adafruit_apds9960.apds9960 import APDS9960

# We import the analogio to interface with the ADC module in ESP32-S3
# This module contains classes to provide access to analog IO typically implemented with digital-to-analog (DAC) and analog-to-digital (ADC) converters.
from analogio import AnalogIn

# We import the label library to handle formatting in the featherwing OLED display
from adafruit_display_text import label

# can try import bitmap_label above for alternative
# ------------------------------------------------------------------------------------

"""OBJECT, PIN & SETUP DEFINITIONS"""

# ------------------------------------------------------------------------------------
"""Potenciometers Object & Analog Pin Definitions"""
pot_a = AnalogIn(board.A1)  # potentiometer connected to A1, power & ground
pot_b = AnalogIn(board.A8)  # potentiometer connected to A8, power & ground

# Use for I2C
""" For the featherwing 128x64 OLED display"""
displayio.release_displays()
# oled_reset = board.D9
# For using the built-in STEMMA QT connector on a microcontroller
i2c = board.STEMMA_I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
"""For the BMP280 sensors"""
# Create sensor object, communicating over the board's default I2C bus
# uses board.SCL and board.SDA
I2C = board.I2C()
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(I2C)
# change this to match the location's pressure (hPa) at sea level
bmp280.sea_level_pressure = 1007.25
"""For the BH1750 sensors"""
# Create a sensor object for the BH1750 lux sensor
# uses board.SCL and board.SDA
iic = board.I2C()
# For using the built-in STEMMA QT connector on a microcontroller
# i2c = board.STEMMA_I2C()
bh1750 = adafruit_bh1750.BH1750(iic)
"""For the DHT11 sensors"""
# Defining the pin that would read the data from the DHT11
dht = adafruit_dht.DHT11(board.D14)
"""For the DS1307 - RTC Module"""
# uses board.SCL and board.SDA
i2C = board.I2C()
# For using the built-in STEMMA QT connector on a microcontroller
# i2c = board.STEMMA_I2C()
rtc = adafruit_ds1307.DS1307(i2C)
"""For the APDS9960 sensors"""
# uses board.SCL and board.SDA
i2c = board.I2C()
# For using the built-in STEMMA QT connector on a microcontroller
# i2c = board.STEMMA_I2C()
apds = APDS9960(i2c)
# To sense proximity you first must enable it
apds.enable_proximity = True
# To sense gesture you first must enable it
apds.enable_gesture = True
# To sense color you first must enable it
apds.enable_color = True
# ------------------------------------------------------------------------------------
"""To check memory available"""

if gc.mem_free() < 1000:
    print("Insufficient memory. Please resume your code!")
else:
    print("Free memory available in bytes", gc.mem_free())
# ------------------------------------------------------------------------------------
"""RTC Module formatting"""

# Lookup table for names of days (nicer printing).
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
# pylint: disable-msg=using-constant-test

"""To set current time"""
if False:  # change to True if you want to set the time!
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2022, 12, 31, 16, 11, 15, 0, -1, -1))
    # you must set year, mon, date, hour, min, sec and weekday
    # yearday is not supported, isdst can be set but we don't do anything with it at this time
    print("Setting time to:", t)  # uncomment for debugging
    rtc.datetime = t
    print()
# pylint: enable-msg=using-constant-test
# ------------------------------------------------------------------------------------

"""Featherwing OLED 128x64 Formatting & Setup"""
# ------------------------------------------------------------------------------------
"""CONSTANTS DEFINITION"""
# SH1107 is vertically oriented 64x128
WIDTH = 128
HEIGHT = 64
BORDER = 2
"""OBJECT DEFINITION"""
display = adafruit_displayio_sh1107.SH1107(
    display_bus, width=WIDTH, height=HEIGHT, rotation=0
)
"""FORMAT DEFINITION"""
# Make the display context
splash = displayio.Group()
display.show(splash)

# Color definition
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF  # White

# Attribute TileGrid definition
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle in black
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000  # Black
inner_sprite = displayio.TileGrid(
    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)
# ------------------------------------------------------------------------------------

"""MQTT & Wi-Fi BLOCK"""
# ------------------------------------------------------------------------------------
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

print("Connecting to %s" % secrets["ssid"])
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to %s!" % secrets["ssid"])

# Topic Setup

# MQTT Topic
# Use this topic if you'd like to connect to a standard MQTT broker
mqtt_topic = "/home/sensor_data"

# Adafruit IO-style Topic
# Use this topic if you'd like to connect to io.adafruit.com
# mqtt_topic = secrets["aio_username"] + '/feeds/temperature'

# Code
# Define callback methods which are called when events occur
# pylint: disable=unused-argument, redefined-outer-name
def connect(mqtt_client, userdata, flags, rc):
    # This function will be called when the mqtt_client is connected
    # successfully to the broker.
    print("Connected to MQTT Broker!")
    print("Flags: {0}\n RC: {1}".format(flags, rc))


def disconnect(mqtt_client, userdata, rc):
    # This method is called when the mqtt_client disconnects
    # from the broker.
    print("Disconnected from MQTT Broker!")


def subscribe(mqtt_client, userdata, topic, granted_qos):
    # This method is called when the mqtt_client subscribes to a new feed.
    print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos))


def unsubscribe(mqtt_client, userdata, topic, pid):
    # This method is called when the mqtt_client unsubscribes from a feed.
    print("Unsubscribed from {0} with PID {1}".format(topic, pid))


def publish(mqtt_client, userdata, topic, pid):
    # This method is called when the mqtt_client publishes data to a feed.
    print("Published to {0} with PID {1}".format(topic, pid))


def message(client, topic, message):
    # Method called when a client's subscribed feed has a new value.
    print("New message on topic {0}: {1}".format(topic, message))


# Create a socket pool
pool = socketpool.SocketPool(wifi.radio)

# Set up a MiniMQTT Client
mqtt_client = MQTT.MQTT(
    broker=secrets["broker"],
    port=secrets["port"],
    username=secrets["aio_username"],
    password=secrets["aio_key"],
    socket_pool=pool,
    ssl_context=ssl.create_default_context(),
)

# Connect callback handlers to mqtt_client
mqtt_client.on_connect = connect
mqtt_client.on_disconnect = disconnect
mqtt_client.on_subscribe = subscribe
mqtt_client.on_unsubscribe = unsubscribe
mqtt_client.on_publish = publish
mqtt_client.on_message = message

# Connecting to the MQTT Broker Server
print("Attempting to connect to %s" % mqtt_client.broker)
mqtt_client.connect()
# Subscribing to the /home/sensor_data topic
print("Subscribing to %s" % mqtt_topic)
mqtt_client.subscribe(mqtt_topic)
# ------------------------------------------------------------------------------------
"""INFINITE LOOP - MAIN PROGRAM"""
while True:
    """SENSOR READING"""
    # ------------------------------------------------------------------------------------
    """Temperature"""
    textmp = "Temperature: %0.1f C" % bmp280.temperature
    text_temp = label.Label(terminalio.FONT, text=textmp, color=0xFFFFFF, x=4, y=8)
    splash.append(text_temp)
    # ------------------------------------------------------------------------------------
    """ Pressure """
    textpre = "Pressure: %0.1f hPa" % bmp280.pressure
    text_pre = label.Label(terminalio.FONT, text=textpre, color=0xFFFFFF, x=4, y=20)
    splash.append(text_pre)
    # ------------------------------------------------------------------------------------
    """ Altitude """
    textalt = "Altitude: %0.2f m" % bmp280.altitude
    text_alt = label.Label(terminalio.FONT, text=textalt, color=0xFFFFFF, x=4, y=32)
    splash.append(text_alt)
    # ------------------------------------------------------------------------------------
    """ Sea Level Pressure """
    textslp = "Sealv-P: %0.2f hPa" % bmp280.sea_level_pressure
    text_slp = label.Label(terminalio.FONT, text=textslp, color=0xFFFFFF, x=4, y=43)
    splash.append(text_slp)
    # ------------------------------------------------------------------------------------
    """Humidity"""
    try:
        humidity = dht.humidity
        texthum = "Humidity: {} %".format(humidity)
        text_hum = label.Label(terminalio.FONT, text=texthum, color=0xFFFFFF, x=4, y=54)
        splash.append(text_hum)
    except RuntimeError as e:
        # Reading doesn't always work! Just print error and we'll try again
        print("Reading from DHT failure: ", e.args)
    # ------------------------------------------------------------------------------------
    """OLED DISPLAY CLEANING"""
    # ------------------------------------------------------------------------------------
    time.sleep(3)
    splash.remove(text_temp)
    splash.remove(text_pre)
    splash.remove(text_alt)
    splash.remove(text_slp)
    splash.remove(text_hum)
    # ------------------------------------------------------------------------------------
    """Lux"""
    # Display lux value
    textlux = "Light: %.2f Lux" % bh1750.lux
    text_lux = label.Label(terminalio.FONT, text=textlux, color=0xFFFFFF, x=4, y=8)
    splash.append(text_lux)
    # ------------------------------------------------------------------------------------
    """RGB Color"""
    r, g, b, c = apds.color_data
    textrg = "Red: {0} Green: {1}".format(r, g)
    textbc = "Blue: {0} Clear:{1}".format(b, c)
    text_rg = label.Label(terminalio.FONT, text=textrg, color=0xFFFFFF, x=4, y=20)
    splash.append(text_rg)
    text_bc = label.Label(terminalio.FONT, text=textbc, color=0xFFFFFF, x=4, y=32)
    splash.append(text_bc)
    # ------------------------------------------------------------------------------------
    """Real Time Clock"""
    t = rtc.datetime
    # print(t)     # uncomment for debugging
    textday = "{} {}/{}/{}".format(days[int(t.tm_wday)], t.tm_mday, t.tm_mon, t.tm_year)
    texthr = "Time: {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec)
    text_day = label.Label(terminalio.FONT, text=textday, color=0xFFFFFF, x=4, y=43)
    splash.append(text_day)
    text_hr = label.Label(terminalio.FONT, text=texthr, color=0xFFFFFF, x=4, y=54)
    splash.append(text_hr)
    # ------------------------------------------------------------------------------------
    """OLED DISPLAY CLEANING"""
    # ------------------------------------------------------------------------------------
    time.sleep(3)
    splash.remove(text_lux)
    splash.remove(text_rg)
    splash.remove(text_bc)
    splash.remove(text_day)
    splash.remove(text_hr)
    time.sleep(1)
    # ------------------------------------------------------------------------------------
    """Simulated Analog (Gravity) Sensors"""
    # Temperature
    print("Tank Temperature", (pot_a.value,))  # Display Temperature value
    time.sleep(0.25)
    # Dissolved Oxigen
    print("Tank DO", (pot_b.value,))  # Display Dissolved Oxigen value
    time.sleep(0.25)
    # ------------------------------------------------------------------------------------
    # Publishing to the sensor_data to the /home/sensor_data topic
    print("Publishing to %s" % mqtt_topic)
    string = '"t":{0},"p":{1},"h":{2},"a":{3},"s":{4}'.format(
        bmp280.temperature,
        bmp280.pressure,
        dht.humidity,
        bmp280.altitude,
        bmp280.sea_level_pressure,
    )
    json_string = "{" + string + "}"
    # print(json_string)
    mqtt_client.publish(mqtt_topic, json_string)
    time.sleep(5)
    # Unsubscribing to the /home/sensor_data topic
    #print("Unsubscribing from %s" % mqtt_topic)
    #mqtt_client.unsubscribe(mqtt_topic)
    # Disconnecting to the MQTT Broker Server
    #print("Disconnecting from %s" % mqtt_client.broker)
    #mqtt_client.disconnect()
# ------------------------------------------------------------------------------------

Behavior

soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Crash into the HardFault_Handler.
Please file an issue with the contents of your CIRCUITPY drive at
https://github.com/adafruit/circuitpython/issues

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.3.3 on 2022-08-29; FeatherS3 with ESP32S3
FeatherS3DriveContents.zip

Description

The board is the FeatherS3 by Unexpected Maker, it runs okay for like 15min or so and everything works in the server side too, but then it crashes and I do not know why. I've tried to increase the delays, commented out the unsubscribe and disconnect blocks and moved out the connect and subscribe blocks outside the infinite loop. Prior to this changes, all these blocks were run sequentially, but it still crashed after a while.

I admit I'm still getting the hang of all this, but I honestly see no error in neither the wiring nor the code. The only thing I can think of its maybe one of the sensors crashes after a while so everything then crashes.

Or maybe is my internet connection, I've seen that when my UPS internal relays switch to stabilize the power grid voltage of my house this happens too, but as of writing this has happened without that happening

Additional information

The board is the FeatherS3 by Unexpected Maker, it runs okay for like 15min or so and everything works in the server side too, but then it crashes and I do not know why. I've tried to increase the delays, commented out the unsubscribe and disconnect blocks and moved out the connect and subscribe blocks outside the infinite loop. Prior to this changes, all these blocks were run sequentially, but it still crashed after a while.

I admit I'm still getting the hang of all this, but I honestly see no error in neither the wiring nor the code. The only thing I can think of its maybe one of the sensors crashes after a while so everything then crashes.

Or maybe is my internet connection, I've seen that when my UPS internal relays switch to stabilize the power grid voltage of my

@xav-e xav-e added the bug label Jan 1, 2023
@dhalbert
Copy link
Collaborator

dhalbert commented Jan 3, 2023

Could you try CircuitPython 8.0.0-beta.6 and see if the problem is still present?

@dhalbert dhalbert added this to the 8.0.0 milestone Jan 3, 2023
@jepler
Copy link

jepler commented Jan 3, 2023

This is superficially similar to #6791 which also has an S3 and a BME280 sensor.

@xav-e
Copy link
Author

xav-e commented Jan 3, 2023

Oh that's right Jepler it is very similar, thank you so much for reaching out to me

I've been reading his thread and I think there's a solution already for this, I'll finish reading it and update this

Hope you're having a good day!

@xav-e
Copy link
Author

xav-e commented Jan 3, 2023

Could you try CircuitPython 8.0.0-beta.6 and see if the problem is still present?

Of course! I'll tried it out and update this on a moment

Thanks for your help

@tannewt
Copy link
Member

tannewt commented Jan 17, 2023

@xav-e Is it still happening?

@jposada202020
Copy link

Hello is happening for me in my Adafruit CircuitPython 8.0.0-beta.6 on 2022-12-21; Adafruit Feather ESP32S3 4MB Flash 2MB PSRAM with ESP32S3 I am trying to connect to my home assistant, as you can see in the following code, I try to restart the micro-controller, however it does not restart, and the if the USB is connected it will freeze my ubuntu machine. I get a

Error:
 [Errno 128] ENOTCONN
try:
    while True:
        x, y, z = [
            value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration
        ]
        movement = abs(y * 10)
        output = {
            "movx": movement,
        }
        print("Publishing to %s" % mqtt_topic)
        print(movement)
        client.publish(mqtt_topic, json.dumps(output))
        time.sleep(300)

except Exception as e:
    print("Error:\n", str(e))
    print("Resetting microcontroller in 10 seconds")
    time.sleep(10)
    microcontroller.reset()

@DJDevon3
Copy link

Eligible for a retest with 8.0.5 stable. I'm at 2 hours stable on the UM FeatherS3 currently.

@jepler
Copy link

jepler commented Jun 21, 2023

Please re-test once we've merged IDF 5 support into CircuitPython 9.

@jepler jepler modified the milestones: 8.x.x, 9.0.0 Jun 21, 2023
@sveinungkb
Copy link

Please re-test once we've merged IDF 5 support into CircuitPython 9.

Is there a build where this can be tested now?

@tannewt
Copy link
Member

tannewt commented Aug 15, 2023

Not quite. I'm working on it now.

@dhalbert
Copy link
Collaborator

dhalbert commented Dec 1, 2023

Could you now test with a 9.0.0-alpha release? Thanks.

@tannewt
Copy link
Member

tannewt commented Jan 31, 2024

Please comment if this is still an issue and we'll reopen. (Or file a new issue.)

@tannewt tannewt closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants