ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BHudson
 
Posts: 10
Joined: Wed Dec 20, 2017 12:46 am

ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep

Post by BHudson »

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

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)

User avatar
BHudson
 
Posts: 10
Joined: Wed Dec 20, 2017 12:46 am

Re: ItsyBitsy nrf52840 Retaining Pin State in Deep Sleep

Post by BHudson »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”