Cov txheej txheem:

Arduino thiab Python Serial Communication - Keypad Display: 4 Cov Kauj Ruam
Arduino thiab Python Serial Communication - Keypad Display: 4 Cov Kauj Ruam

Video: Arduino thiab Python Serial Communication - Keypad Display: 4 Cov Kauj Ruam

Video: Arduino thiab Python Serial Communication - Keypad Display: 4 Cov Kauj Ruam
Video: Computer Vision with Python! Resizing Images 2024, Kaum ib hlis
Anonim
Arduino thiab Python Serial Communication - Keypad Display
Arduino thiab Python Serial Communication - Keypad Display

Txoj Haujlwm no tau ua rau cov neeg siv mac tab sis nws kuj tseem tuaj yeem siv rau Linux thiab Windows, tsuas yog cov kauj ruam uas yuav tsum sib txawv yog kev teeb tsa.

Kauj Ruam 1: Kev Txhim Kho Software

Kev Txhim Kho Software
Kev Txhim Kho Software
  1. Rub tawm thiab Nruab Arduino ->
  2. Rub tawm thiab Nruab Python 2.7 ->
  3. Rub tawm lub tsev qiv ntawv Python "pyserial -2.7.tar.gz" ->
  4. Rub tawm pyserial-2.7.tar.gz
  5. Qhib Terminal thiab ntaus:

cd /users/"Your-User-Account"/Downloads/pyserial-2.7

sudo python setup.py nruab

Kev teeb tsa software npaj txhij!

Kauj ruam 2: Kev thaiv kab

Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
  1. Arduino Ib
  2. Sparkfun 12 Button keypad

Cov xov hluav taws xob tau ua tiav yam tsis muaj tus tiv thaiv sab nraud, hloov kuv siv sab hauv Rub-Resistors ntawm lub microcontroller (sab hauv Pullup-Resistors ntawm Arduino muaj tus nqi 20K-Ohm txog 50K-Ohm)

Txhawm rau qhib sab hauv Rub-Resistors teeb tsa INPUT-Pins HIGH hauv cov cai

Yog tias koj siv lwm tus Keypad saib ntawm cov ntaub ntawv rau txoj cai thaiv, txwv tsis pub nws tuaj yeem ua rau koj lub microcontroller puas

Kauj Ruam 3: Arduino Code

Arduino Txoj Cai
Arduino Txoj Cai
  • Ua ntej peb txhais lub cim-Matrix rau Cov Yuam Sij
  • Cov keypad siv cov hloov pauv ib txwm uas tau teeb tsa hauv 4 kab (Pins 7, 2, 3 thiab 5) thiab 3 kab (Pins 6, 8 thiab 4), tau txhais ua Arrays rowPins thiab colPins
  • Kev teeb tsa () muaj nuj nqi

    • Qhib lub qhov rooj txuas nrog Serial.begin ();
    • Teeb kab ua OUTPUT-Pins HIGH
    • Qhib cov Pullup-Resistors, los ua cov kab no ua INPUT-Pins HIGH;
  • Getkey () muaj nuj nqi

    • Teem txhua kab LOW thiab ntsuas yog tias ib ntawm kab yog LOW. Vim tias Pullup-Resistors yog txhua kab HIGH kom txog thaum tus yuam sij raug thawb. Tus yuam sij thawb tsim LOW-Signal ntawm INPUT-Pin. Qhov LOW no qhia tus yuam sij hauv kab no thiab kab lus
    • Tos kom txog thaum tus yuam sij raug tso tawm thiab xa rov qab tus lej ntawm tus keymap-Array lossis 0 yog tias tsis muaj tus yuam sij raug thawb
    • Siv ncua sijhawm (debounceTime) los tswj lub teeb liab

Kauj Ruam 4: Python_2.7 Code

Nab hab sej_2.7 Code
Nab hab sej_2.7 Code
  • Ntshuam Serial Library
  • Txhais qhov sib txawv sib txawv = FALSE, tom qab yog qhov sib txawv no siv los ntsuas yog tias muaj kev txuas txuas lossis tsis muaj
  • Qhib Serial Port nrog serial. Serial ("Lub npe ntawm koj li Serial Port", baud)

    • Txhawm rau kom tau lub npe ntawm koj qhov chaw nres nkoj nyem nyem -> Cov Cuab Yeej/Serial Port hauv Arduino IDLE
    • baud yuav tsum zoo ib yam li hauv Arduino Code
  • Hauv lub sijhawm ntsuas lub voj yog tias muaj qhov txuas lossis tsis tau nyeem lub teeb liab thiab teeb tsa qhov sib txawv sib txuas = TRUE, nws loops kom txog thaum nws tau txais kev txuas txuas
  • Tom qab kev sib txuas tau nyeem cov ntawv xov xwm nyob rau hauv ib pliag lub voj thiab muab cov lus nkag rau hauv qhov hloov pauv tshiab "var"
  • kaw qhov chaw nres nkoj nrog ser.close ()

Pom zoo: