Home › Forums › The libraries hosted on the site › PCF8574 i2c digital I/O expander › ‘class PCF8574’ has no member named ‘analogWrite’ problem
Tagged: analogWrite, pcf8574, PWM
- This topic has 3 replies, 1 voice, and was last updated 4 years, 3 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
10 February 2021 at 17:58 #9800
Pedja Grbic
Hello everybody, I am trying to connect (communicate) NodeMCU and PCF8574 Extender.
No matter what I change in my code, always getting same error:
‘class PCF8574’ has no member named ‘analogWrite’Last part (analogWrite) change when I change code order, but problem with a class is constant.
Here is complete code:
// Mower #define BLYNK_PRINT Serial #include
#include #include "PCF8574.h" PCF8574 pcf8574(0x20); //#define motor1IN1 D2 //4 #define motor1IN1 P1 #define motor1IN2 D5 //14 #define motor2IN1 D6 //12 #define motor2IN2 D8 //15 #define EN1 D0 //16 //#define EN2 D1 //5 #define EN2 P0 //#define ENL D11 //9 //#define ENR D12 //10 //#define mowerPWML D3 //0 //#define mowerPWMR D4 //2 char auth[] = "token"; //Blynk Authentication Token char ssid[] = "wifi name"; //WIFI Name char pass[] = "wifi pass"; //WIFI Password char command[8]; int pinValue; int power; int mowerPower; void setup() { Serial.begin(9600); Blynk.begin(auth, ssid, pass); analogWriteFreq(16000); pinMode(EN1, OUTPUT); pcf8574.pinMode(EN2, OUTPUT); pcf8574.pinMode(motor1IN1, OUTPUT); pinMode(motor1IN2, OUTPUT); pinMode(motor2IN1, OUTPUT); pinMode(motor2IN2, OUTPUT); // pinMode(ENL, OUTPUT); // pinMode(ENR, OUTPUT); // pinMode(mowerPWML, OUTPUT); // pinMode(mowerPWMR, OUTPUT); pcf8574.begin(); } void moveControl(char command[], int value, int power = 0) { if (value != 0) { if (strcmp(command, "forward") == 0) { digitalWrite(EN1, HIGH); pcf8574.digitalWrite(EN2, HIGH); pcf8574.digitalWrite(motor1IN1, LOW); analogWrite(motor1IN2, power); digitalWrite(motor2IN1, LOW); analogWrite(motor2IN2, power); } else if (strcmp(command, "back") == 0) { digitalWrite(EN1, HIGH); pcf8574.digitalWrite(EN2, HIGH); pcf8574.analogWrite(motor1IN1, power); digitalWrite(motor1IN2, LOW); analogWrite(motor2IN1, power); digitalWrite(motor2IN2, LOW); } else if (strcmp(command, "left") == 0) { digitalWrite(EN1, HIGH); pcf8574.digitalWrite(EN2, HIGH); pcf8574.analogWrite(motor1IN1, power); digitalWrite(motor1IN2, LOW); digitalWrite(motor2IN1, LOW); analogWrite(motor2IN2, power); } else if (strcmp(command, "right") == 0) { digitalWrite(EN1, HIGH); pcf8574.digitalWrite(EN2, HIGH); pcf8574.digitalWrite(motor1IN1, LOW); analogWrite(motor1IN2, power); analogWrite(motor2IN1, power); digitalWrite(motor2IN2, LOW); } else { digitalWrite(EN1, LOW); pcf8574.digitalWrite(EN2, LOW); } } else { digitalWrite(EN1, LOW); pcf8574.digitalWrite(EN2, LOW); } } void controlMower(int mowerPower) { // if(mowerPower != 0) { // digitalWrite(ENL, HIGH); // digitalWrite(ENR, HIGH); // digitalWrite(mowerPWML, LOW); // analogWrite(mowerPWMR, mowerPower); // } // else { // digitalWrite(ENL, LOW); // digitalWrite(ENR, LOW); // } } void loop() { Blynk.run(); } BLYNK_WRITE(V2) { int pinValue = param.asInt(); char command[] = "forward"; moveControl(command, pinValue, power); } BLYNK_WRITE(V3) { int pinValue = param.asInt(); char command[] = "back"; moveControl(command, pinValue, power); } BLYNK_WRITE(V4) { int pinValue = param.asInt(); char command[] = "left"; moveControl(command, pinValue, power); } BLYNK_WRITE(V5) { int pinValue = param.asInt(); char command[] = "right"; moveControl(command, pinValue, power); } BLYNK_WRITE(V6) { power = param.asInt(); } BLYNK_WRITE(V7) { mowerPower = param.asInt(); controlMower (mowerPower); } Thanks in advance, I am here for any further info.
-
10 February 2021 at 18:09 #9804
Hi Pedja,
pcf8574 is a digital I/O expander, analogWrite work only for analog expander or PWM pin, so can’t work with pcf8574.
Bye Renzo
-
10 February 2021 at 21:20 #9808
Pedja Grbic
Yes, you are right, my bad.
So, I am looking for just one more analog pin (for PWM) and by connecting extender I am loosing two Dx pins, is there a way to connect extender to Rx and Tx pins of NodeMCU, or to SD2 and SD3 or something like that?
-
10 February 2021 at 21:51 #9809
Hi Pedja,
You can use a pcf8591 that have 4 analog input and one analog output (256 position).PCF8591 i2c Analog I/O Expander
You can connect the IC to the same i2c pin with a different address.
I think it’s sufficient to do the work.
Bye Renzo
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.