Skip to content

Commit 6fe4c8f

Browse files
jd3096-mpyeggfly
authored andcommitted
add 04 5x5 led&readme
1 parent b209675 commit 6fe4c8f

File tree

4 files changed

+94
-13
lines changed

4 files changed

+94
-13
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,23 @@ control_board_v1.led_show_bytes_async(bytearray([9, 8, 0, 0, 0]))
3232
### Classes
3333
* control_board_v1.PlayRecordMission
3434

35-
# GPIO
36-
已知:
37-
button a ————— GPIO 10
38-
button b ————— GPIO 20
39-
button c ————— GPIO 21
40-
I2C(SC7A20国产三轴) ————— SDA 6 SCL 7
41-
UART (5x5 led)————— TX 8 RX 9 baudrate=460929
42-
未知:
43-
P1
44-
P2
45-
I2S???
46-
47-
35+
### Examples
36+
* 01 5X5 LED(OFFICAL METHODS)
37+
* 02 ACEL
38+
* 03 BUTTON
39+
* 04 5X5 LED(WITH SOURCE CODE)
40+
41+
42+
# GPIO对应
43+
已知:
44+
button a ————— GPIO 10
45+
button b ————— GPIO 20
46+
button c ————— GPIO 21
47+
I2C(SC7A20国产三轴) ————— SDA 6 SCL 7
48+
UART ————— TX 8 RX 9 baudrate=460800
49+
板子上还有个国产MUC,主要通过UART通信实现音频录制播放、5x5 led的功能
50+
未知:
51+
P1 ————— GPIO5
52+
P2 ————— GPIO4
53+
到此alphapi的硬件基本挖掘完毕,通过螺丝柱供电这种方式确实第一次见。
4854
TODO
File renamed without changes.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import machine
2+
import time
3+
from machine import SoftI2C, Pin
4+
5+
uart = machine.UART(1, 460966, tx = 8, rx = 9, timeout=200)
6+
i2c = SoftI2C(scl=Pin(7), sda=Pin(6), freq=400000)
7+
8+
number_map=[
9+
bytearray([0xf8,0x88,0x88,0x88,0xF8]),
10+
bytearray([0,0,0xf8,0,0]),
11+
bytearray([0xb8,0xa8,0xa8,0xa8,0xe8]),
12+
bytearray([0xa8,0xa8,0xa8,0xa8,0xf8]),
13+
bytearray([0xe0,0x20,0x20,0x20,0xf8]),
14+
bytearray([0xe8,0xa8,0xa8,0xa8,0xb8]),
15+
bytearray([0xf8,0xa8,0xa8,0xa8,0xb8]),
16+
bytearray([0x80,0x80,0x80,0x80,0xf8]),
17+
bytearray([0xf8,0xa8,0xa8,0xa8,0xf8]),
18+
bytearray([0xe0,0xa0,0xa0,0xa0,0xf8]),
19+
]
20+
letter_map=[]
21+
22+
def calc_checksum(data : bytearray):
23+
sum = 0
24+
for i in range(0,len(data)-1):
25+
sum+=data[i]
26+
return sum&0xff
27+
28+
def uart_write(addr, data:bytearray) -> num:
29+
#与国产MCU通信,格式为头帧0x90+地址+数据长度+数据+累加和校验值
30+
#如通信成功会返回3bytes数据b'\x91\x08\x05',有时通信会卡死,原因未知,连续写两次则必定成功,奇怪???
31+
if(len(data)==0):
32+
return False
33+
byteToWrite = bytearray([0x90])
34+
byteToWrite.append(addr)
35+
byteToWrite.append(len(data))
36+
byteToWrite.extend(data)
37+
byteToWrite.append(0)
38+
byteToWrite[len(byteToWrite)-1]=calc_checksum(byteToWrite)
39+
for i in range(0,2):
40+
uart.write(byteToWrite)
41+
ansbytes = uart.read(3)
42+
try:
43+
if len(ansbytes)==3:
44+
return ansbytes[2]
45+
else:
46+
print("write error: ", ansbytes)
47+
return False
48+
except:
49+
pass
50+
51+
def led_rect():
52+
databytes = bytearray([0xf8,0xf8,0xf8,0x88,0xF8])
53+
uart_write(0x08, databytes)
54+
return
55+
56+
def led_array_demo():
57+
databytes = bytearray([0xf8,0xf8,0xf8,0xf8,0xf8])
58+
for i in range(0,10):
59+
for j in range(0,5):
60+
databytes[j]=databytes[j]<<1
61+
if databytes[j] == 0:
62+
databytes[j] = 0x08
63+
uart_write(0x08, databytes)
64+
time.sleep_ms(100)
65+
return
66+
67+
def show_number(n):
68+
uart_write(0x08, number_map[n])
69+
70+
for i in range(0,10):
71+
show_number(i)
72+
time.sleep(0.5)
73+
74+
75+

0 commit comments

Comments
 (0)