Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep

by BHudson on Sun Nov 21, 2021 8:08 pm

I have a project where I want the board to check every minute for a BLE device to be present and then set a pin state depending on the answer. I have the code working except that the pin state is not retained. As soon as the pin is set high, it is set low again unless I have a delay programmed after the pin state setting.

The DotStar state is retained through sleep mode, but the GPIO state is not. What is the difference between them? Why does the DotStar stay on while the pin turns off?

Code: Select all | TOGGLE FULL SIZE
from adafruit_ble import BLERadio
import board
from digitalio import DigitalInOut, Direction, Pull
import time
import adafruit_dotstar
import alarm

dots = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.1)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
at_home = None

homeLed = DigitalInOut(board.D9)
homeLed.direction = Direction.OUTPUT

goneLed = DigitalInOut(board.D7)
goneLed.direction = Direction.OUTPUT

carOn = DigitalInOut(board.D13)
carOn.direction = Direction.INPUT
carOn.pull = Pull.DOWN

targetName = "nxg200-240AC4A41E0C"
radio = BLERadio()
sleep_time = 10
# Set an alarm for one minute from now
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic()+sleep_time)
n_dots = len(dots)
for dot in range(n_dots):
    dots[dot] = RED
    time.sleep(0.25)
    dots[dot] = GREEN
    time.sleep(0.25)
    dots[dot] = BLUE
    time.sleep(0.25)
found = set()
scan_responses = set()

if not carOn.value:
    print("scanning")
    for advertisement in radio.start_scan(timeout=10):
        addr = advertisement.address
        if advertisement.scan_response and addr not in scan_responses:
            scan_responses.add(addr)
        elif not advertisement.scan_response and addr not in found:
            found.add(addr)
            if advertisement.complete_name == targetName:
                at_home = True
                break
        else:
            at_home = False
            continue
else:
    print("Car on")
    goneLed.value = True
    time.sleep(0.5)


if at_home is True:
    for dot in range(n_dots):
        dots[dot] = BLUE
    print("At Home")
    homeLed.value = True
    time.sleep(0.5)
elif at_home is False:
    for dot in range(n_dots):
        dots[dot] = RED
    print("Not at home")
    goneLed.value = True
    time.sleep(0.5)
else:
    for dot in range(n_dots):
        dots[dot] = GREEN
# Deep sleep until alarm then restart
alarm.exit_and_deep_sleep_until_alarms(time_alarm)

BHudson
 
Posts: 9
Joined: Wed Dec 20, 2017 12:46 am

Re: ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep

by BHudson on Thu Nov 25, 2021 12:10 am

After doing some further research, Nordic says the pin state should be retained during deep sleep. I am wondering if there is something in the CircuitPython GPIO library that is de-initializing the hardware and losing the pin state. It's odd that this is the only Adafruit board I have used so far that shows this behavior.

BHudson
 
Posts: 9
Joined: Wed Dec 20, 2017 12:46 am

Please be positive and constructive with your questions and comments.