start:arduino:mcp23017:dfrobot
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:mcp23017:dfrobot [2022/03/29 10:46] – [Exemple de code - interrogation d'interruption] gerardadmin | start:arduino:mcp23017:dfrobot [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| [[https:// | [[https:// | ||
| + | |||
| + | ==== Achat ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | [[https:// | ||
| {{ : | {{ : | ||
| Ligne 380: | Ligne 388: | ||
| {{ : | {{ : | ||
| + | ====Exemple de code 4- Interruption IO==== | ||
| + | Combinez les broches INTA et INTB de la carte d' | ||
| + | Pour les autres microcontrôleurs, | ||
| + | |||
| + | <code c interruption2.ino> | ||
| + | /*! | ||
| + | * @file ioInterrupt.ino | ||
| + | * @brief IO interrupt, set a pin of a port group(A or B) IO to interrupt mode. When an interrupt occurs on the related port group, pin INTA(group A) or INTB(group B) will output a High level. | ||
| + | * INTA and INTB are used to detect if an interrupt occurs on the pin of port eGPA and eGPB respectively; | ||
| + | * @n Experiment phenomenon: when the signal change of pin INTA or INTB is detected by main-board, the related interrupt service function will be executed to print out which pin was interrupted on serial port. | ||
| + | * | ||
| + | * @copyright | ||
| + | * @licence | ||
| + | * @author [Arya](xue.peng@dfrobot.com) | ||
| + | * @version | ||
| + | * @eGPAte | ||
| + | * @get from https:// | ||
| + | * @url https:// | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | DFRobot_MCP23017 mcp(Wire, /*addr =*/ | ||
| + | // | ||
| + | |||
| + | //Connect 2 buttons to IO expansion board, one to a pin of port eGPA(eg: eGPA0), the other to a pin of port eGPB(eg: eGPB0) | ||
| + | //Connect INTA to the external interrupt pin0 of UNO, INTB to external interrupt pin1 of UNO. | ||
| + | |||
| + | bool intFlagA = false;// | ||
| + | bool intFlagB = false;// | ||
| + | |||
| + | /*Interrupt service function, prototype void func(int index), index represents the pin which is interrupted*/ | ||
| + | void gpa0CB(int index){ | ||
| + | String description = mcp.pinDescription(index); | ||
| + | Serial.print(description); | ||
| + | } | ||
| + | |||
| + | void gpb7CB(int index){ | ||
| + | String description = mcp.pinDescription(index); | ||
| + | Serial.print(description); | ||
| + | } | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | #ifdef ARDUINO_ARCH_MPYTHON | ||
| + | pinMode(P0, INPUT);// | ||
| + | pinMode(P1, INPUT);// | ||
| + | #else | ||
| + | pinMode(2, INPUT);// | ||
| + | pinMode(3, INPUT);// | ||
| + | #endif | ||
| + | |||
| + | /*wait for the chip to be initialized completely, and then exit*/ | ||
| + | while(mcp.begin() != 0){ | ||
| + | Serial.println(" | ||
| + | delay(1000); | ||
| + | } | ||
| + | /*Parameter mode, the available parameter is shown below: | ||
| + | eLowLevel | ||
| + | Low-level interrupt | ||
| + | Parameter cb interrupt service function(with parameter) | ||
| + | Prototype void func(int) | ||
| + | */ | ||
| + | mcp.pinModeInterrupt(/ | ||
| + | mcp.pinModeInterrupt(/ | ||
| + | |||
| + | #ifdef ARDUINO_ARCH_MPYTHON // | ||
| + | /* mPython Interrupt Pin vs Interrupt NO | ||
| + | * ------------------------------------------------------------------------------------- | ||
| + | * | | DigitalPin | ||
| + | * | mPython | ||
| + | * | | Interrupt No | use digitalPinToInterrupt(Pn) to query interrupt number | ||
| + | * |-----------------------------------------------------------------------------------| | ||
| + | */ | ||
| + | attachInterrupt(digitalPinToInterrupt(P0)/ | ||
| + | attachInterrupt(digitalPinToInterrupt(P1)/ | ||
| + | #else | ||
| + | /* Main-board of AVR series | ||
| + | * --------------------------------------------------------------------------------------- | ||
| + | * | | DigitalPin | ||
| + | * | Uno, Nano, Mini, other 328-based | ||
| + | * | | Interrupt No | 0 | 1 | | | ||
| + | * |-------------------------------------------------------------------------------------| | ||
| + | * | | Pin | 2 | 3 | 21 | 20 | 19 | 18 | | ||
| + | * | | ||
| + | * | | Interrupt No | 0 | 1 | 2 | 3 | 4 | 5 | | ||
| + | * |-------------------------------------------------------------------------------------| | ||
| + | * | | Pin | 3 | 2 | 0 | 1 | 7 | | | ||
| + | * | Leonardo, other 32u4-based | ||
| + | * | | Interrupt No | 0 | 1 | 2 | 3 | 4 | | | ||
| + | * |-------------------------------------------------------------------------------------- | ||
| + | */ | ||
| + | /* microbit | ||
| + | * --------------------------------------------------------------------------------------------------------------- | ||
| + | * | | ||
| + | * | microbit | ||
| + | * |(when used as external interrupt, do not need to set it to input mode via pinMode) | ||
| + | * |-------------------------------------------------------------------------------------------------------------| | ||
| + | */ | ||
| + | attachInterrupt(/ | ||
| + | attachInterrupt(/ | ||
| + | #endif | ||
| + | } | ||
| + | /*Interrupt service function*/ | ||
| + | void notifyA(){ | ||
| + | intFlagA = true; | ||
| + | } | ||
| + | void notifyB(){ | ||
| + | intFlagB = true; | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | if(intFlagA){ | ||
| + | intFlagA = false; | ||
| + | / | ||
| + | parameter group, the available parameter is shown below: (default value: eGPIOALL): | ||
| + | | ||
| + | Port groupA | ||
| + | */ | ||
| + | mcp.pollInterrupts(/ | ||
| + | } | ||
| + | if(intFlagB){ | ||
| + | intFlagB = false; | ||
| + | mcp.pollInterrupts(/ | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | * **Résultats attendus** | ||
| + | |||
| + | Appuyez sur le bouton sur PAO ou PB7, le résultat suivant sera imprimé sur le port série. | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | ====Connexion en cascade==== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | ==== Schema du DFT0626 - MCP23017 DFROBOT ==== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ==== Doc technique MCP23017 ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | ===== Programme APC220 (Sans fil) et MCP23017 | ||
| + | |||
| + | <code c Emmision_ESP32_LED_BP_APC220_MCP23017.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | HardwareSerial Sender(2); | ||
| + | |||
| + | #define Sender_Txd_pin 17 | ||
| + | #define Sender_Rxd_pin 16 | ||
| + | |||
| + | int EtatLED = 0; | ||
| + | int EtatBP = 0; | ||
| + | int EtatPrecd = 0; | ||
| + | int EtatLEDPrecd =0; | ||
| + | bool Unefois = false; | ||
| + | |||
| + | |||
| + | DFRobot_MCP23017 mcp027(Wire, | ||
| + | |||
| + | //Prepare: connect the LED to a digital pin of IO expansion board(eg: | ||
| + | void setup(void) | ||
| + | { | ||
| + | | ||
| + | | ||
| + | |||
| + | while(mcp027.begin() != 0){ | ||
| + | Serial.println(" | ||
| + | | ||
| + | } | ||
| + | |||
| + | |||
| + | mcp027.pinMode(/ | ||
| + | mcp027.pinMode(/ | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop(void) | ||
| + | { | ||
| + | EtatPrecd = EtatBP ; | ||
| + | EtatBP = mcp027.digitalRead(/ | ||
| + | delay(100); | ||
| + | // | ||
| + | // | ||
| + | / | ||
| + | Serial.print(" | ||
| + | Serial.println(verrou); | ||
| + | |||
| + | | ||
| + | Serial.print(" | ||
| + | // | ||
| + | EtatLEDPrecd = EtatLED; | ||
| + | EtatLED = !EtatLED; | ||
| + | Serial.print(" | ||
| + | Serial.println(EtatLED); | ||
| + | } | ||
| + | if(EtatLED == 0 ){ | ||
| + | mcp027.digitalWrite(mcp027.eGPB0, | ||
| + | if ( Unefois == false ) { | ||
| + | Sender.print(" | ||
| + | Unefois = !Unefois ; | ||
| + | } | ||
| + | Serial.print(" | ||
| + | Serial.println(EtatLED ); | ||
| + | delay(100); | ||
| + | |||
| + | } | ||
| + | else if (( EtatLED ==1 ) && (EtatLEDPrecd == 0)) { | ||
| + | mcp027.digitalWrite(mcp027.eGPB0, | ||
| + | // | ||
| + | if ( Unefois == true) { | ||
| + | Sender.print(" | ||
| + | Unefois = !Unefois ; | ||
| + | } | ||
| + | Serial.print(" | ||
| + | Serial.println(EtatLED ); | ||
| + | delay(100); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/mcp23017/dfrobot.1648543581.txt.gz · Dernière modification : (modification externe)
