I have a problem concerning the writing of the pins. I want to put them to 1 to drive a Multiplexers (MUXO & MUXI in the code below) but when i try to control MUXI, i have the error code in the Serial terminal "E (X) gpio: gpio_set_level(226): GPIO output gpio_num error" and i don't know why there is this problem neither how to fix it.
- #include "MUX.h"
- //Define Utilisateur
- #define DEBUG 1
- #define i 16
- #define j 16
- //Define connection pins on ESP32
- #define S0_MUXO 2
- #define S1_MUXO 15
- #define S2_MUXO 14
- #define S3_MUXO 18
- #define SIG_MUXO 33
- #define EN_MUXO 27
- #define S0_MUXI 35
- #define S1_MUXI 34
- #define S2_MUXI 3
- #define S3_MUXI 1
- #define SIG_MUXI 32
- #define EN_MUXI 21
- int a = 0;
- int b = 0;
- int c = 0;
- MUX muxi = MUX(S0_MUXI, S1_MUXI, S2_MUXI, S3_MUXI, SIG_MUXI, EN_MUXI, MUXI);
- MUX muxo = MUX(S0_MUXO, S1_MUXO, S2_MUXO, S3_MUXO, SIG_MUXO, EN_MUXO, MUXO);
- void setup() {
- Serial.begin(115200);
- muxo.enable();
- muxi.enable();
- }
- void loop() {
- //CODE PRINCIPALE
- while (a < j) {
- muxi.choix_channel(a);
- muxi.ON();
- while (b < i) {
- muxo.choix_channel(b);
- c = a + b;
- b++;
- }
- b = 0;
- a++;
- }
- a = 0;
- if (DEBUG) {
- Serial.println("End loop");
- }
- }
- #include "esp32-hal-gpio.h"
- #include "MUX.h"
- MUX::MUX(int S0, int S1, int S2, int S3, int SIG, int EN, TYPE _type) {
- pin_S0 = S0;
- pin_S1 = S1;
- pin_S2 = S2;
- pin_S3 = S3;
- pin_EN = EN;
- pin_SIG = SIG;
- type = _type;
- pinMode(pin_EN, OUTPUT);
- digitalWrite(pin_EN, LOW);
- pinMode(pin_S0, OUTPUT);
- pinMode(pin_S1, OUTPUT);
- pinMode(pin_S2, OUTPUT);
- pinMode(pin_S3, OUTPUT);
- digitalWrite(pin_S0, LOW);
- digitalWrite(pin_S1, LOW);
- digitalWrite(pin_S2, LOW);
- digitalWrite(pin_S3, LOW);
- if (type == MUXO) {
- pinMode(pin_SIG, INPUT_PULLDOWN);
- }
- if (type == MUXI) {
- pinMode(pin_SIG, OUTPUT);
- }
- }
- void MUX::disable() {
- digitalWrite(pin_EN, HIGH);
- }
- void MUX::enable() {
- digitalWrite(pin_EN, LOW);
- }
- void MUX::ON() {
- if (type == MUXI) {
- digitalWrite(pin_SIG, HIGH);
- }
- }
- void MUX::OFF() {
- if (type == MUXI) {
- digitalWrite(pin_SIG, LOW);
- }
- }
- void MUX::choix_channel(int ch) {
- digitalWrite(pin_S0, LOW);
- digitalWrite(pin_S1, LOW);
- digitalWrite(pin_S2, LOW);
- digitalWrite(pin_S3, LOW);
- if (ch & 0b0001) {
- digitalWrite(pin_S0, HIGH);
- }
- if (ch & 0b0010) {
- digitalWrite(pin_S1, HIGH);
- }
- if (ch & 0b0100) {
- digitalWrite(pin_S2, HIGH);
- }
- if (ch & 0b1000) {
- digitalWrite(pin_S3, HIGH);
- }
- }
- MUX::~MUX() {
- true == true;
- };
- #pragma once
- #ifndef MUX_h
- #define MUX_h
- #include "Arduino.h"
- enum TYPE { MUXO, MUXI };
- class MUX {
- public:
- int pin_S0;
- int pin_S1;
- int pin_S2;
- int pin_S3;
- int pin_EN;
- int pin_SIG;
- TYPE type;
- MUX(int S0, int S1, int S2, int S3, int EN, int SIG, TYPE _type);
- ~MUX();
- void choix_channel(int ch);
- void enable();
- void disable();
- void ON();
- void OFF();
- };
- #endif
Thanks for your help