de:arduino:io_expand

Differences

This shows you the differences between two versions of the page.

de:arduino:io_expand [2020/05/14 16:59]
de:arduino:io_expand [2022/04/21 15:00] ()
 1:  1:
 +====== E / A-Erweiterungsmodule ======
 +===== Bidirektionale serielle 16-Bit E/A-Erweiterungs I²C/SPI-Schnittstelle (mit MCP23017-IC) =====
 +{{ :wiki:arduino:mcp23017_1.png?150|Bidirektionale serielle 16-Bit E/A-Erweiterungs I²C/SPI-Schnittstelle}}
 +Bidirektionale serielle 16-Bit E/A-Erweiterungs [[de:comm:bus_i2c|I²C]] / [[de:comm:bus_spi|SPI]] Schnittstelle (mit MCP23017-IC).
  
 +- // 16-Bit-bidirektionaler Remote-E / A-Port: // E / A-Anschlüsse sind standardmäßig Eingaben \\
 +- // Hochgeschwindigkeitsschnittstelle [[de:comm:bus_i2c|I²C]] (MCP23017): // 100 kHz / 400 kHz / 1,7 MHz \\
 +- // Hochgeschwindigkeitsschnittstelle [[de:comm:bus_spi|SPI]] (MCP23S17): // 10 MHz (maximal) \\
 +- // Adressierung: // Die Adresse der Einheiten kann mit drei Pins eingestellt werden, sodass 8 Geräte gleichzeitig am Bus sein können. \\
 +- // Standby-Strom: // 1 μA (max.) \\
 +- // Betriebsspannung: // 1,8 V .. 4,5 V \\
 +
 +==== MCP23017 IC-Pinbelegung ====
 +
 +{{:wiki:arduino:mcp23017_ic_pins.png?300|MCP23017 IC-Pinbelegung}}
 +
 +**GPA0..GPA7:** erste 8 PINs (Standardeingaben) \\
 +**GPB0..GPB7:** zweite 8 PINs (Standardeingaben) \\
 +**INT A:** Die ersten acht Bits können über die IOCON.BANK übertragen werden \\
 +**INT B:** Die zweiten acht Bits können über die IOCON.BANK übertragen werden \\
 +**RESET:** LOW level RESET. Es muss im Grundzustand an die Stromversorgung angeschlossen werden. \\
 +**A0..A2:** konfigurierbare I²C-Adresse (unten beschrieben) \\
 +**V<sub>dd</sub>:** Stromversorgung 5V DC (1,8V..5,5V) \\
 +**V<sub>ss</sub>:** Grund \\
 +**SCL:** Kommunikationsanschluss (Zeitsignal) \\
 +**SDA:** Kommunikationsanschluss (Datasignal) \\
 +
 +==== MCP23017 IC-Adressierung ====
 +
 +Die IC-Adresse ist für die SPI- und I2C-Kommunikation gleich und besteht aus zwei Teilen: dem festen Teil: "0100", der konfigurierbare Teil folgt irgendwie so:
 +0100 A2 A1 A0. 
 +
 +Die Adresse kann somit zwischen 32 und 39 geändert werden. Nach dem Anschließen der Kommunikation lohnt es sich, das Vorhandensein des Moduls mit dem Arduino I²C-Scannerprogramm zu testen.
 +
 +==== MCP23017 IC-Direktverdrahtung ====
 +{{:wiki:arduino:mcp23017_wire.png?500|MCP23017 IC-Direktverdrahtung}}
 +==== MCP23017 ====
 +MCP23017 IC-Datenblatt: {{ :wiki:downloads:mcp23017.pdf |MCP23017 Datenblatt}}
 +==== Softver ====
 +Die Bibliothek für das Modul kann von Github heruntergeladen werden: https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
 +
 +További [[hu:arduino:comm_example#arduino_i_c_kommunikacio|Arduino I²C kommunikációs megoldások]] \\
 +További [[hu:arduino:comm_example#arduino_spi_kommunikacio|Arduino SPI kommunikációs megoldások]] \\
 +
 +
 +{{ :wiki:arduino:ic74hc165d.png?200|CJMCU-165 74HC165D}}
 +===== SN74HC165N =====
 +{{anchor:sn74hc165n}}
 +
 +Der SN74HC165N kann 8 Bits serieller Kommunikationseingänge pro IC und 8 Ausgänge paralleler Kommunikation enthalten. Es können mehrere IC / Erweiterungsmodule gleichzeitig an ein Arduino angeschlossen werden. Das Erweiterungsmodul "// CJMCU-165 74HC165D //" enthält nur den IC, sodass es praktisch genauso funktioniert wie ein "nackter" IC.
 +
 +IC-Datenblatt: http://html.alldatasheet.com/html-pdf/15551/PHILIPS/74HC165D/247/1/74HC165D.html
 +
 +==== IC-Pinbelegung ====
 +
 +^Pin^Schield^Name und Funktion|
 +|1|PL|Funktionsauswahl: \\ LOW (aktiv): Asynchronen Paralleleingang aktivieren \\ HIGH: Seriellen Ausgang aktivieren|
 +|2|CP|Takteingang, steigende Flanke gesteuert|
 +|7|Q7|Der Stromausgang des Schrittregisters wird für die seriellen Ausgänge negiert|
 +|8|GND|grund, 0V|
 +|9|Q|Das Schieberegister ist der Stromausgang für serielle Ausgänge|
 +|10|Ds|serielle Dateneingang|
 +|15|CE|Zeitsignal aktivieren (LOW: aktiv)|
 +|16|Vcc|Stromversorgung|
 +|11,12,13,14,3,4,5,6|D0-D7|parallele Eingangsbits|
 +
 +==== Beispielprogramm ====
 +Im Beispiel werden 10 Drucktasten über IC 165 gelesen. Dazu müssen 2 ICs verwendet werden und die Drucktasten müssen nacheinander über die serielle Schnittstelle abgefragt werden. Nicht verwendete Ports müssen mit Masse verbunden werden.
 +
 +=== Verdrahtung zum Beispielprogramm ===
 +{{:wiki:arduino:example74hc165d.png|Verdrahtung zum Beispielprogramm SN74HC165N}}
 +
 +=== Beispielprogramm ===
 +<code c>
 +/*
 + * SN74HC165N_shift_reg
 + *
 + * Program to shift in the bit values from a SN74HC165N 8-bit
 + * parallel-in/serial-out shift register.
 + *
 + * 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   2
 +
 +/* Width of data (how many ext lines).
 +*/
 +#define DATA_WIDTH   NUMBER_OF_SHIFT_CHIPS * 8
 +
 +/* Width of pulse to trigger the shift register to read and latch.
 +*/
 +#define PULSE_WIDTH_USEC   5
 +
 +/* Optional delay between shift register reads.
 +*/
 +#define POLL_DELAY_MSEC   1
 +
 +/* You will need to change the "int" to "long" If the
 + * NUMBER_OF_SHIFT_CHIPS is higher than 2.
 +*/
 +#define BYTES_VAL_T unsigned int
 +
 +int ploadPin        = 8;  // Connects to Parallel load pin the 165
 +int clockEnablePin  = 9;  // Connects to Clock Enable pin the 165
 +int dataPin         = 11; // Connects to the Q7 pin the 165
 +int clockPin        = 12; // Connects to the Clock pin the 165
 +
 +BYTES_VAL_T pinValues;
 +BYTES_VAL_T oldPinValues;
 +
 +/* This function is essentially a "shift-in" routine reading the
 + * 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, HIGH);
 +    digitalWrite(ploadPin, LOW);
 +    delayMicroseconds(PULSE_WIDTH_USEC);
 +    digitalWrite(ploadPin, HIGH);
 +    digitalWrite(clockEnablePin, LOW);
 +
 +    /* 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, HIGH);
 +        delayMicroseconds(PULSE_WIDTH_USEC);
 +        digitalWrite(clockPin, LOW);
 +    }
 +
 +    return(bytesVal);
 +}
 +
 +/* Dump the list of zones along with their current status.
 +*/
 +void display_pin_values()
 +{
 +    Serial.print("Pin States:\r\n");
 +
 +    for(int i = 0; i < DATA_WIDTH; i++)
 +    {
 +        Serial.print("  Pin-");
 +        Serial.print(i);
 +        Serial.print(": ");
 +
 +        if((pinValues >> i) & 1)
 +            Serial.print("HIGH");
 +        else
 +            Serial.print("LOW");
 +
 +        Serial.print("\r\n");
 +    }
 +
 +    Serial.print("\r\n");
 +}
 +
 +void setup()
 +{
 +    Serial.begin(9600);
 +
 +    /* Initialize our digital pins...
 +    */
 +    pinMode(ploadPin, OUTPUT);
 +    pinMode(clockEnablePin, OUTPUT);
 +    pinMode(clockPin, OUTPUT);
 +    pinMode(dataPin, INPUT);
 +
 +    digitalWrite(clockPin, LOW);
 +    digitalWrite(ploadPin, HIGH);
 +
 +    /* 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("*Pin value change detected*\r\n");
 +        display_pin_values();
 +        oldPinValues = pinValues;
 +    }
 +
 +    delay(POLL_DELAY_MSEC);
 +}
 +
 +</code>
 +
 +Quelle: https://playground.arduino.cc/Code/ShiftRegSN74HC165N