Home › Forums › The libraries hosted on the site › PCF8574 i2c digital I/O expander › Compatible with stm32duino
- This topic has 14 replies, 2 voices, and was last updated 2 years, 9 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
7 July 2022 at 12:33 #21780
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?
-
7 July 2022 at 12:39 #21781
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);
} -
7 July 2022 at 13:11 #21782
Or maybe change speed of i2c?
It’s possible in library? -
7 July 2022 at 15:19 #21783
Hi Gzegorz,
you can find some examples and documentation herePCF8574 i2c digital I/O expander: Arduino, esp8266 and esp32, basic I/O and interrupt – Part 1
Bye Renzo
-
17 July 2022 at 13:53 #21888
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.
-
-
18 July 2022 at 08:42 #21891
Hi Grzegorz,
It’s strange in the framework the default frequency is already 100000
but I think It’s sufficient tu putWire.setClock(100000);
before the pcf8574.begin
Bye Renzo
-
6 August 2022 at 23:09 #22196
it’s strange but it’s not working. Perhaps there is a conflict with some library what I use.
-
8 August 2022 at 08:05 #22198
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
-
8 August 2022 at 10:15 #22201
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> -
8 August 2022 at 10:44 #22202
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.
-
8 August 2022 at 10:48 #22203
But when relayOff() is executed by RTC alarm I see in console output this message: “przekazniki off” but nothing happens with relays – still ON..
-
8 August 2022 at 10:55 #22204
VSCopde + platformio.
[env:blackpill_f401cc]
platform = ststm32@^15.4.1
board = blackpill_f401cc
framework = arduino
upload_protocol = dfulib_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.2LCD 4×20 with pcf8574, relays with optoisolators (chinesee board).
Attachments:
You must be logged in to view attached files. -
8 August 2022 at 11:03 #22209
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
-
8 August 2022 at 11:52 #22210
Yes, I know, I changed it on purpose. But it doesn’t matter – it not works for me.
-
-
10 August 2022 at 10:22 #22214
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.