forked from thokis/SimpleDFPlayerMini-for-MicroPython
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmachine.py
33 lines (27 loc) · 769 Bytes
/
machine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import time
import pigpio
class UART():
def __init__(self, tx_pin, baudrate) -> None:
self.tx_pin = tx_pin
self.baudrate = baudrate
self.pi = pigpio.pi()
while not self.pi.connected:
print("trying to connect..")
os.system("sudo pigpiod")
time.sleep(1)
self.pi = pigpio.pi()
pigpio.exceptions = False
self.pi.set_mode(self.tx_pin, pigpio.OUTPUT)
self.pi.serial_close(self.tx_pin)
pigpio.exceptions = True
def write(self, packet):
self.send_command(packet)
def send_command(self, packet):
self.pi.wave_clear()
self.pi.wave_add_serial(self.tx_pin, self.baudrate, packet, bb_bits=8)
wid = self.pi.wave_create()
self.pi.wave_send_once(wid)
while self.pi.wave_tx_busy():
pass
self.pi.wave_delete(wid)