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

PyPortal Pynt SD card "SCK in use" error.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PyPortal Pynt SD card "SCK in use" error.

by Buddahaid on Wed Mar 10, 2021 9:43 pm

I'm struggling to solve this problem getting "SCK in use" errors whenever I try to mount the SD card. If I run just a code to mount the card everything is fine but trying to mount the card using any of the demo projects gives the SCK in use error.
I'm using Circuitpython and the MU editor. The UF2 is current and the library is 6.x.
Last edited by Buddahaid on Wed Mar 10, 2021 9:59 pm, edited 1 time in total.

Buddahaid
 
Posts: 10
Joined: Tue Aug 27, 2019 9:10 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by tannewt on Wed Mar 10, 2021 9:56 pm

Please post your current code so we can see everything it is doing.

tannewt
 
Posts: 2390
Joined: Thu Oct 06, 2016 8:48 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by Buddahaid on Wed Mar 10, 2021 10:02 pm

Thank you. This is the Quotes code that came on the Pynt with the addition of code for the SD card. The SD card code runs without error as is.

import time
import board
from adafruit_pyportal import PyPortal
import os
import busio
import digitalio
import storage
import adafruit_sdcard

# See if a card is present
card_detect_pin = digitalio.DigitalInOut(board.SD_CARD_DETECT)
card_detect_pin.direction = digitalio.Direction.INPUT
card_detect_pin.pull = digitalio.Pull.UP
print('SD card present: %s' % card_detect_pin.value)

# Try to connect to the SD card
sdcard = adafruit_sdcard.SDCard(
busio.SPI(board.SCK, board.MOSI, board.MISO),
digitalio.DigitalInOut(board.SD_CS)
)

# Mount the card to a directory
virtual_file_system = storage.VfsFat(sdcard)
storage.mount(virtual_file_system, '/sd')
print('-> the sd directory follows:', os.listdir('/sd'))


# At this point, you can use it like a normal file system.
# Create files, open files, create directories, etc

# Calculate disk space
# Avoid performing this disk size calculation on very large disks (takes too long)
# Works just fine on 8GB disks, hangs on 256GB disks
vfs_stats = os.statvfs('/sd')
# Total size = block size * number of blocks
total_size_in_mb = int(vfs_stats[0] * vfs_stats[2] / (1024 * 1024))
# Free space = block size * number of available blocks
available_space_in_mb = int(vfs_stats[0] * vfs_stats[3] / (1024 * 1024))
print('Disk size: %s MB' % total_size_in_mb)
print('Free space: %s MB' % available_space_in_mb)
print('Used space %s MB' % (total_size_in_mb - available_space_in_mb))

# Create/open a file and write to it
with open('/sd/test.txt', 'w') as output_file:
output_file.write('Hello, world!\n')

# Print contents of SD card root directory
for file_name in os.listdir('/sd'):
stats = os.stat('/sd/' + file_name)
file_size = stats[6] # Size in bytes
is_dir = stats[0] & 0x4000 # Bitmask
if is_dir:
print('Dir: %s' % file_name)
else:
print('File: %s (%s bytes)' % (file_name, file_size))

# Set up where we'll be fetching data from
DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
QUOTE_LOCATION = [0, 'text']
AUTHOR_LOCATION = [0, 'author']

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+"/quote_background.bmp",
text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
text_position=((20, 120), # quote location
(5, 210)), # author location
text_color=(0xFFFFFF, # quote text color
0x8080FF), # author text color
text_wrap=(35, # characters to wrap for quote
0), # no wrap for author
text_maxlen=(180, 30), # max text size for quote & author
)

# speed up projects with lots of text by preloading the font!
pyportal.preload_font()

while True:
try:
value = pyportal.fetch()
print("Response is", value)
except RuntimeError as e:
print("Some error occured, retrying! -", e)
time.sleep(60)

Buddahaid
 
Posts: 10
Joined: Tue Aug 27, 2019 9:10 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by tannewt on Wed Mar 10, 2021 10:09 pm

Try using `board.SPI()` instead of `busio.SPI(board.SCK, board.MOSI, board.MISO),` that will share the SPI bus with anything else that uses it.

tannewt
 
Posts: 2390
Joined: Thu Oct 06, 2016 8:48 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by Buddahaid on Wed Mar 10, 2021 10:25 pm

I've tried that as well before. Tried it again just now and the same error occurs.

It points to:
Traceback (most recent call last):
File "code.py", line 76, in <module>
File "adafruit_pyportal.py", line 308, in __init__
ValueError: SCK in use

Buddahaid
 
Posts: 10
Joined: Tue Aug 27, 2019 9:10 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by tannewt on Thu Mar 11, 2021 12:44 pm

I don't think you need to manage the SD card yourself actually. I think the PyPortal object will do it for you. Try `os.listdir("/sd")` after you make the PyPortal object.

tannewt
 
Posts: 2390
Joined: Thu Oct 06, 2016 8:48 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by Buddahaid on Thu Mar 11, 2021 8:35 pm

Yes that is working. Thank you.

Buddahaid
 
Posts: 10
Joined: Tue Aug 27, 2019 9:10 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by Buddahaid on Fri Mar 12, 2021 1:35 am

I think part of what was confusing me was expecting to see the SD card show as a file in the CIRCUITPY directory. Maybe that is some code I don't know that needs adding but I can store images on it and display them now which is what I was aiming for.

Buddahaid
 
Posts: 10
Joined: Tue Aug 27, 2019 9:10 pm

Re: PyPortal Pynt SD card "SCK in use" error.

by tannewt on Fri Mar 12, 2021 4:18 pm

Ah yes. Unfortunately, that's not how it works because the USB drive protocol operates below the filesystem layer. We don't currently make the SD card available over USB through CircuitPython (if we did, then it'd show as a second drive.)

tannewt
 
Posts: 2390
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.