Compatible with stm32duino

Viewing 12 reply threads
  • Author
    Posts
    • #21780
      Grzegorz
      Participant

        Hi, is that library compatible with smt32duino?
        I try to use it in my project but I have many problems, for first example:
        In setup() I have this code:

        void setup()
        {
        Serial.begin(9600);
        Serial.print(“init relays “);
        Serial.println(expRelays.begin());
        expRelays.pinMode(SSR, OUTPUT);
        expRelays.digitalWrite(SSR, LOW);
        expRelays.pinMode(Swiatlo, OUTPUT);
        expRelays.digitalWrite(Swiatlo, LOW);
        expRelays.pinMode(kbLED, OUTPUT);
        expRelays.digitalWrite(kbLED, HIGH);
        expRelays.pinMode(relay_1, OUTPUT);
        expRelays.digitalWrite(relay_1, HIGH);
        expRelays.pinMode(relay_2, OUTPUT);
        expRelays.digitalWrite(relay_2, HIGH);
        expRelays.pinMode(relay_3, OUTPUT);
        expRelays.digitalWrite(relay_3, HIGH);
        expRelays.pinMode(relay_4, OUTPUT);
        expRelays.digitalWrite(relay_4, HIGH);
        }

        problem: relays change state after many of seconds, not immediatelly. Why?
        CPU is stm32f401CCU6 (Black pill from waveshare), platform = ststm32@^15.4.1, vscode, platformio.

        I use 3 expanders – one for buttons, second for relays and third for lcd 20×4.
        Sometimes after pushing button – program hangs – randomly.

        Have You tried this library with stm32 compatibility?

      • #21781
        Grzegorz
        Participant

          there is some function was run when RTC interrupt set’s a flag:
          On serial output i have message, but relays don’t change state.
          When I compile this code on Arduino nano – all code works perfect.

          void relayOff()
          {
          Serial.println(“relay off”);
          expRelays.digitalWrite(relay_1, HIGH);
          expRelays.digitalWrite(relay_2, HIGH);
          expRelays.digitalWrite(relay_3, HIGH);
          expRelays.digitalWrite(relay_4, HIGH);
          }

        • #21782
          Grzegorz
          Participant

            Or maybe change speed of i2c?
            It’s possible in library?

          • #21783
            Renzo Mischianti
            Keymaster

              Hi Gzegorz,
              you can find some examples and documentation here

              PCF8574 i2c digital I/O expander: Arduino, esp8266 and esp32, basic I/O and interrupt – Part 1

              Bye Renzo

              • #21888
                Grzegorz
                Participant

                  There is nothing about setting clock/speed on i2c bus.
                  But when I write clear code like this:

                  Wire.setClock(100000);
                  Wire.begin();
                  Wire.beginTransmission(PCF8574relAddr);
                  Serial.print(“init relays “);
                  Wire.write(0x00);
                  Wire.endTransmission();
                  delay(1000);
                  Wire.beginTransmission(PCF8574relAddr);
                  Wire.write(0xFF);
                  Wire.endTransmission();

                  Work’s great. But when I increase clock.. Not working.

                  So… where I can set clock/speed of i2c in Your library?
                  Thank’s.

              • #21891
                Renzo Mischianti
                Keymaster

                  Hi Grzegorz,
                  It’s strange in the framework the default frequency is already 100000
                  but I think It’s sufficient tu put

                  
                  Wire.setClock(100000);
                  

                  before the pcf8574.begin

                  Bye Renzo

                • #22196
                  Grzegorz
                  Participant

                    it’s strange but it’s not working. Perhaps there is a conflict with some library what I use.

                  • #22198
                    Renzo Mischianti
                    Keymaster

                      I recheck the code in the first topic, and I can’t understand where you initialize the pcf.
                      Please start from an existing example and modify It, then send me the complete code.

                      Bye Renzo

                    • #22201
                      Grzegorz
                      Participant

                        Here, in this function:

                        void beginRelays()
                        {
                        Wire.setClock(100000);
                        expRelays.begin();
                        expRelays.pinMode(SSR, OUTPUT); // gniazdo 230V
                        expRelays.digitalWrite(SSR, LOW);
                        expRelays.pinMode(Swiatlo, OUTPUT); // Oswietlenie
                        expRelays.digitalWrite(Swiatlo, LOW);
                        expRelays.pinMode(kbLED, OUTPUT); // klawiatura LED
                        expRelays.digitalWrite(kbLED, HIGH);
                        expRelays.pinMode(relay_1, OUTPUT); // przekaznik 1
                        expRelays.digitalWrite(relay_1, HIGH);
                        expRelays.pinMode(relay_2, OUTPUT); // przekaznik 2
                        expRelays.digitalWrite(relay_2, HIGH);
                        expRelays.pinMode(relay_3, OUTPUT); // przekaznik 3
                        expRelays.digitalWrite(relay_3, HIGH);
                        expRelays.pinMode(relay_4, OUTPUT); // przekaznik 4
                        expRelays.digitalWrite(relay_4, HIGH);
                        }

                        And second function for buttons:

                        void buttonsInit()
                        {
                        Serial.print(“init buttons “);
                        Wire.setClock(100000);
                        expButtons.begin();
                        expButtons.pinMode(kbPower, INPUT_PULLUP); // klawiatura Power
                        expButtons.pinMode(kbLeft, INPUT_PULLUP); // klawiatura Lewo
                        expButtons.pinMode(kbMenu, INPUT_PULLUP); // klawiatura Menu
                        expButtons.pinMode(kbAuto, INPUT_PULLUP); // klawiatura Auto
                        expButtons.pinMode(kbRight, INPUT_PULLUP); // klawiatura Prawo
                        expButtons.pinMode(btnLight, INPUT_PULLUP); // przycisk swiatla
                        expButtons.pinMode(P6, INPUT);
                        expButtons.digitalWrite(P6, LOW);
                        expButtons.pinMode(P7, INPUT);
                        expButtons.digitalWrite(P7, LOW);
                        pinMode(kbInterruptPin, INPUT_PULLUP);
                        attachInterrupt(digitalPinToInterrupt(kbInterruptPin), KbInterrupt, FALLING);
                        }

                        I’m using libraries:
                        #include <LiquidCrystal_I2C.h>
                        #include <LcdMenu.h> //https://forntoh.github.io/LcdMenu
                        #include <Adafruit_BME280.h>
                        #include <PCF8574.h>

                      • #22202
                        Grzegorz
                        Participant

                          My setup:

                          void setup(){
                          beginRelays();
                          delay(1000);
                          relayOff();
                          }

                          void relayOff()
                          {
                          Serial.println(“przekazniki off”);
                          expRelays.digitalWrite(relay_1, HIGH);
                          expRelays.digitalWrite(relay_2, HIGH);
                          expRelays.digitalWrite(relay_3, HIGH);
                          expRelays.digitalWrite(relay_4, HIGH);
                          }

                          relayOff turn off relays after 10 seconds.
                          But when I change code in relayOff() to manual Wire:
                          Wire.beginTransmission(PCF8574relAddr);
                          Wire.write(0xFF);
                          Wire.endTransmission();

                          It works right away, without any time delay.

                        • #22203
                          Grzegorz
                          Participant

                            But when relayOff() is executed by RTC alarm I see in console output this message: “przekazniki off” but nothing happens with relays – still ON..

                          • #22204
                            Grzegorz
                            Participant

                              VSCopde + platformio.

                              [env:blackpill_f401cc]
                              platform = ststm32@^15.4.1
                              board = blackpill_f401cc
                              framework = arduino
                              upload_protocol = dfu

                              lib_deps =
                              knolleary/PubSubClient@^2.8
                              paulstoffregen/OneWire@^2.3.7
                              milesburton/DallasTemperature@^3.10.0
                              adafruit/Adafruit BME280 Library@^2.1.2
                              marcoschwartz/LiquidCrystal_I2C@^1.1.4
                              xreef/PCF8574 library@^2.2.1
                              paulstoffregen/Time@^1.6
                              stm32duino/STM32duino RTC@^1.3.0
                              khoih-prog/NTPClient_Generic@^3.7.4
                              khoih-prog/Timezone_Generic@^1.7.2
                              luisllamasbinaburo/MedianFilterLib@^1.0.0
                              forntoh/LcdMenu@^2.1.0
                              khoih-prog/FlashStorage_STM32@^1.2.0
                              bblanchon/ArduinoJson@^6.19.4
                              jandrassy/EthernetENC@^2.0.2

                              LCD 4×20 with pcf8574, relays with optoisolators (chinesee board).

                            • #22209
                              Renzo Mischianti
                              Keymaster

                                Hi Grzegorz,
                                you do the begin before the pinMode declaration, that’s wrong.

                                You must do the pinMode of all pin, then begin then start the normal use.

                                Bye Renzo

                                • #22210
                                  Grzegorz
                                  Participant

                                    Yes, I know, I changed it on purpose. But it doesn’t matter – it not works for me.

                                • #22214
                                  Renzo Mischianti
                                  Keymaster

                                    Hi Grzegorz,
                                    sorry for the late response, I found the bug introduced in the latest version, for ESP32 I must force int cast of SDA SCL, but STM32 core need uint32_t so here is the mistake.
                                    You can find the fix in version 2.2.4.
                                    Thanks a lot for your support.
                                    Bye Renzo

                                Viewing 12 reply threads
                                • You must be logged in to reply to this topic.
                                Exit mobile version