Skip to content

Commit 212af2e

Browse files
committed
Adding Where's my PDMIn code
1 parent 4642ea6 commit 212af2e

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

PDM_Microphone/Wheres_my_PDMIn.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import board
2+
import audiobusio
3+
from microcontroller import Pin
4+
5+
6+
def is_hardware_PDM(clock, data):
7+
try:
8+
p = audiobusio.PDMIn(clock, data)
9+
p.deinit()
10+
return True
11+
except ValueError:
12+
return False
13+
except RuntimeError:
14+
return True
15+
16+
17+
def get_unique_pins():
18+
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
19+
pins = [pin for pin in [
20+
getattr(board, p) for p in dir(board) if p not in exclude]
21+
if isinstance(pin, Pin)]
22+
unique = []
23+
for p in pins:
24+
if p not in unique:
25+
unique.append(p)
26+
return unique
27+
28+
29+
for clock_pin in get_unique_pins():
30+
for data_pin in get_unique_pins():
31+
if clock_pin is data_pin:
32+
continue
33+
else:
34+
if is_hardware_PDM(clock_pin, data_pin):
35+
print("Clock pin:", clock_pin, "\t Data pin:", data_pin)
36+
else:
37+
pass

0 commit comments

Comments
 (0)