Differences
This shows you the differences between two versions of the page.
hu:arduino:io_expand [2017/10/08 17:21] |
hu:arduino:io_expand [2022/04/21 15:02] () |
||
---|---|---|---|
1: | 1: | ||
+ | ====== IO bővítőmodulok ====== | ||
+ | ===== Kétirányú 16 bites I/O bővítő I²C / SPI soros interfész (MCP23017 IC-vel) ===== | ||
+ | {{ : | ||
+ | Kétirányú 16 bites I/O bővítő [[hu: | ||
+ | - //16 bites távoli kétirányú I/O port:// Az I/O csatlakozók alapértelmezés szerint bemenetek \\ | ||
+ | - // | ||
+ | - // | ||
+ | - // | ||
+ | - // | ||
+ | - //Üzemi feszültség:// | ||
+ | |||
+ | ==== MCP23017 IC lábkiosztás ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | **GPA0..GPA7: | ||
+ | **GPB0..GPB7: | ||
+ | **INT A:** Az IOCON.BANK-on keresztül továbbítható első nyolc bit \\ | ||
+ | **INT B:** Az IOCON.BANK-on keresztül továbbítható második nyolc bit \\ | ||
+ | **RESET:** LOW level RESET. Alapállapotban tápra kell kötni. \\ | ||
+ | **A0..A2:** konfigurálható I²C cím (leírása lent található)\\ | ||
+ | **V< | ||
+ | **V< | ||
+ | **SCL:** Kommunikációs port (órajel) \\ | ||
+ | **SDA:** Kommunikációs port (adatjel) \\ | ||
+ | |||
+ | ==== MCP23017 IC címzés ==== | ||
+ | |||
+ | Az IC címe SPI és I2C kommunikáció esetén is azonos és két részből áll össze: a fix rész: " | ||
+ | 0100 A2 A1 A0. | ||
+ | |||
+ | A cím így 32 és 39 között változtatható. A kommunikáció összekötése után érdemes az [[hu: | ||
+ | |||
+ | ==== MCP23017 IC direkt vezetékezése ==== | ||
+ | {{: | ||
+ | ==== MCP23017 ==== | ||
+ | Az MCP23017 IC adatlapja: {{ : | ||
+ | ==== Szoftver ==== | ||
+ | A modulhoz tartozó lib a Githubról tölthető le: https:// | ||
+ | |||
+ | További [[hu: | ||
+ | További [[hu: | ||
+ | |||
+ | |||
+ | {{ : | ||
+ | ===== SN74HC165N ===== | ||
+ | {{anchor: | ||
+ | |||
+ | Az SN74HC165N IC-nként 8 bit soros kommunikációjú bemenetet, és 8 párhuzamos kommunikációjú kimenetet tartalmazhat. Egyidejűleg több IC / bővítőmodul is csatlakoztatható egy Arduino-hoz. A "// | ||
+ | |||
+ | Az IC adatlapja: http:// | ||
+ | |||
+ | ==== Az IC lábkiosztása ==== | ||
+ | |||
+ | ^pin^jele^neve és funkciója| | ||
+ | |1|PL|funkcióválasztás: | ||
+ | |2|CP|órajel bemenet, felfutóél vezérelt| | ||
+ | |7|Q7|a léptetőregiszter aktuális kimenet negáltja a soros kimenetekhez| | ||
+ | |8|GND|grund, | ||
+ | |9|Q|a léptetőregiszter aktuális kimenet a soros kimenetekhez| | ||
+ | |10|Ds|soros adatbemenet| | ||
+ | |15|CE|órajel engedélyezése (LOW: aktív)| | ||
+ | |16|Vcc|táp| | ||
+ | |11, | ||
+ | |||
+ | ==== Példaprogram ==== | ||
+ | A példában 10 nyomógomb beolvasása szerepel a 165-ös IC-n keresztül. Ehhez 2 IC-t kell használni, és a nyomógombokat a soros porton keresztül egymás után, szekvenciálisan kell lekérdezni. A nem használt portokat a grundra le kell kötni. | ||
+ | |||
+ | === Vezetékezés a példaprogramhoz === | ||
+ | {{: | ||
+ | === Példaprogram === | ||
+ | < | ||
+ | /* | ||
+ | * SN74HC165N_shift_reg | ||
+ | * | ||
+ | * Program to shift in the bit values from a SN74HC165N 8-bit | ||
+ | * parallel-in/ | ||
+ | * | ||
+ | * This sketch demonstrates reading in 16 digital states from a | ||
+ | * pair of daisy-chained SN74HC165N shift registers while using | ||
+ | * only 4 digital pins on the Arduino. | ||
+ | * | ||
+ | * You can daisy-chain these chips by connecting the serial-out | ||
+ | * (Q7 pin) on one shift register to the serial-in (Ds pin) of | ||
+ | * the other. | ||
+ | | ||
+ | * Of course you can daisy chain as many as you like while still | ||
+ | * using only 4 Arduino pins (though you would have to process | ||
+ | * them 4 at a time into separate unsigned long variables). | ||
+ | | ||
+ | */ | ||
+ | |||
+ | /* How many shift register chips are daisy-chained. | ||
+ | */ | ||
+ | #define NUMBER_OF_SHIFT_CHIPS | ||
+ | |||
+ | /* Width of data (how many ext lines). | ||
+ | */ | ||
+ | #define DATA_WIDTH | ||
+ | |||
+ | /* Width of pulse to trigger the shift register to read and latch. | ||
+ | */ | ||
+ | #define PULSE_WIDTH_USEC | ||
+ | |||
+ | /* Optional delay between shift register reads. | ||
+ | */ | ||
+ | #define POLL_DELAY_MSEC | ||
+ | |||
+ | /* You will need to change the " | ||
+ | * NUMBER_OF_SHIFT_CHIPS is higher than 2. | ||
+ | */ | ||
+ | #define BYTES_VAL_T unsigned int | ||
+ | |||
+ | int ploadPin | ||
+ | int clockEnablePin | ||
+ | int dataPin | ||
+ | int clockPin | ||
+ | |||
+ | BYTES_VAL_T pinValues; | ||
+ | BYTES_VAL_T oldPinValues; | ||
+ | |||
+ | /* This function is essentially a " | ||
+ | * serial Data from the shift register chips and representing | ||
+ | * the state of those pins in an unsigned integer (or long). | ||
+ | */ | ||
+ | BYTES_VAL_T read_shift_regs() | ||
+ | { | ||
+ | long bitVal; | ||
+ | BYTES_VAL_T bytesVal = 0; | ||
+ | |||
+ | /* Trigger a parallel Load to latch the state of the data lines, | ||
+ | */ | ||
+ | digitalWrite(clockEnablePin, | ||
+ | digitalWrite(ploadPin, | ||
+ | delayMicroseconds(PULSE_WIDTH_USEC); | ||
+ | digitalWrite(ploadPin, | ||
+ | digitalWrite(clockEnablePin, | ||
+ | |||
+ | /* Loop to read each bit value from the serial out line | ||
+ | * of the SN74HC165N. | ||
+ | */ | ||
+ | for(int i = 0; i < DATA_WIDTH; i++) | ||
+ | { | ||
+ | bitVal = digitalRead(dataPin); | ||
+ | |||
+ | /* Set the corresponding bit in bytesVal. | ||
+ | */ | ||
+ | bytesVal |= (bitVal << ((DATA_WIDTH-1) - i)); | ||
+ | |||
+ | /* Pulse the Clock (rising edge shifts the next bit). | ||
+ | */ | ||
+ | digitalWrite(clockPin, | ||
+ | delayMicroseconds(PULSE_WIDTH_USEC); | ||
+ | digitalWrite(clockPin, | ||
+ | } | ||
+ | |||
+ | return(bytesVal); | ||
+ | } | ||
+ | |||
+ | /* Dump the list of zones along with their current status. | ||
+ | */ | ||
+ | void display_pin_values() | ||
+ | { | ||
+ | Serial.print(" | ||
+ | |||
+ | for(int i = 0; i < DATA_WIDTH; i++) | ||
+ | { | ||
+ | Serial.print(" | ||
+ | Serial.print(i); | ||
+ | Serial.print(": | ||
+ | |||
+ | if((pinValues >> i) & 1) | ||
+ | Serial.print(" | ||
+ | else | ||
+ | Serial.print(" | ||
+ | |||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | /* Initialize our digital pins... | ||
+ | */ | ||
+ | pinMode(ploadPin, | ||
+ | pinMode(clockEnablePin, | ||
+ | pinMode(clockPin, | ||
+ | pinMode(dataPin, | ||
+ | |||
+ | digitalWrite(clockPin, | ||
+ | digitalWrite(ploadPin, | ||
+ | |||
+ | /* Read in and display the pin states at startup. | ||
+ | */ | ||
+ | pinValues = read_shift_regs(); | ||
+ | display_pin_values(); | ||
+ | oldPinValues = pinValues; | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | /* Read the state of all zones. | ||
+ | */ | ||
+ | pinValues = read_shift_regs(); | ||
+ | |||
+ | /* If there was a chage in state, display which ones changed. | ||
+ | */ | ||
+ | if(pinValues != oldPinValues) | ||
+ | { | ||
+ | Serial.print(" | ||
+ | display_pin_values(); | ||
+ | oldPinValues = pinValues; | ||
+ | } | ||
+ | |||
+ | delay(POLL_DELAY_MSEC); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | A példaprogram forrása: https:// |