shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

esp-idf 一些tips #60

Open shownb opened 4 years ago

shownb commented 4 years ago

更新esp-idf 直接删除$HOME/esp/esp-idf 再 git clone --recursive https://github.com/espressif/esp-idf.git

cd ~/esp/esp-idf
./install.sh

修改 $HOME/.profile 来改变环境变量

alias get_idf='. $HOME/esp/esp-idf/export.sh'

menuconfig make menuconfig Serial flasher config 可以设置Flash size Partition Table (Custom partition table CSV) 设置app的分区大点 Component config --> Common ESP-related --->可以关掉看门狗 [ ] Interrupt watchdog [ ] Initialize Task Watchdog Timer on startup Component config --> Bluetooth --->一些蓝牙的设置,可以让include的文件回来。

from machine import Pin

cols = [4,0]
rows = [2,15]

def m_setup():
    for c in cols:
        Pin(c, mode=Pin.IN, pull=Pin.PULL_UP)
    for r in rows:
        Pin(r,mode=Pin.OUT)
        Pin(r).value(0)

def loop():
    for r in rows:
        Pin(r).value(0)
        for c in cols:
            if Pin(c).value()==0:
                print("r:%s ,c:%s",r,c)
        Pin(r).value(1)

if __name__ == '__main__':
    m_setup()
    while 1:
        loop()
void scan_matrix(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        gpio_set_level(MATRIX_ROWS_PINS[row], 0);
        for (uint8_t col = 0; col < MATRIX_COLS; col++) {
            curState = gpio_get_level(MATRIX_COLS_PINS[col]);
            if (PREV_MATRIX_STATE[row][col] != curState) {
                DEBOUNCE_MATRIX[row][col] = millis();
            }
            PREV_MATRIX_STATE[row][col] = curState;
            if ((millis() - DEBOUNCE_MATRIX[row][col]) > DEBOUNCE) {
                if (MATRIX_STATE[row][col] != curState) {
                    MATRIX_STATE[row][col] = curState;
                }
            }
        }
        gpio_set_level(MATRIX_ROWS_PINS[row], 1);

    }

esp32引脚

GPIO Input Output Notes
0 pulled up OK outputs PWM signal at boot
1 TX pin OK debug output at boot
2 OK OK connected to on-board LED
3 OK RX pin HIGH at boot
4 OK OK  
5 OK OK outputs PWM signal at boot
6 x x connected to the integrated SPI flash
7 x x connected to the integrated SPI flash
8 x x connected to the integrated SPI flash
9 x x connected to the integrated SPI flash
10 x x connected to the integrated SPI flash
11 x x connected to the integrated SPI flash
12 OK OK boot fail if pulled high
13 OK OK  
14 OK OK outputs PWM signal at boot
15 OK OK outputs PWM signal at boot
16 OK OK  
17 OK OK  
18 OK OK  
19 OK OK  
21 OK OK  
22 OK OK  
23 OK OK  
25 OK OK  
26 OK OK  
27 OK OK  
32 OK OK  
33 OK OK  
34 OK   input only
35 OK   input only
36 OK   input only
39 OK   input only

有些io会在启动和reset的时候输出pwm,用这些io输出的时候要注意 GPIO 1 GPIO 3 GPIO 5 GPIO 14 GPIO 15

参考连接方式 cols 12 33 25 26 27 14 32 rows 19 23 18 2 16