C++ and Raspberry PI PWM

Hi

I’m struggling to get a PWM to work on a Raspberry Pi. I’m coding in C++ - as a novice.

My first question is related to WiringPi versus BlynkApiWiringPi:

I followed the example and this installs BlynkApiWiringPi - does this work the same as WiringPi itself? the first difference is that I seem to have to use the GPIO pin numbering and not the Wpi numbering pins. I am able to read inputs but with the GPIO numbering. am I correct in saying that BlynkApiWiringPi uses different pin numbering to WiringPi?

Related to this - to get PWM to work do I use the WiringPi notation like this:

pinMode(pin, PWM_OUTPUT);
pwmWrite(pin, 1024);

or the Blynk notation:

pinMode(pin, OUTPUT);
analogWrite(pin, 800);

I may have a physical wiring problem as well come to think of it - this is the first time I’m doing this. But I am still unsure about the relationship between BlynkApiWiringPi and WiringPi itself.

My current code that is not working is:

#define BLYNK_PRINT stdout
#ifdef RASPBERRY
 #include <BlynkApiWiringPi.h>
#else
 #include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);

#include <BlynkWidgets.h>


#define motorAfwdpin 13
#define motorAbackwdpin 19

unsigned int uptime;      		// 1 second intervals
unsigned int pinStatus;   		// status of BCM 17
unsigned int lastpinStatus = 0; // to toggle

void myTimerEvent()       		// button widget on V0 or direct access gp17 button
{
  
  uptime = (millis() / 1000);
  Blynk.virtualWrite(V1, uptime);
  pinStatus = digitalRead(17);
  if(pinStatus != lastpinStatus){
	lastpinStatus = pinStatus;
	printf("GP17 pin status: %i\n", pinStatus);
	if(pinStatus == 1){    // this is to synchronise V1 button if gp17 button is pressed
		Blynk.virtualWrite(V0, 1);
		printf("forward \n");
		pwmWrite(motorAfwdpin, 800);
		pwmWrite(motorAbackwdpin, 0);
		delay(1000);
		pwmWrite(motorAfwdpin, 0);
		printf("stopped \n");
	}
	else{
		Blynk.virtualWrite(V0, 0);
		printf("backward \n");
		pwmWrite(motorAbackwdpin, 1024);
		pwmWrite(motorAfwdpin, 0);
		delay(1000);
		pwmWrite(motorAbackwdpin, 0);
		printf("stopped \n");
	}
  }
 

}

void setup()
{
  
}



void loop()
{
  Blynk.run();
  if(millis() >= uptime + 1){  // 1 second intervals
	myTimerEvent();
  }
}

int main(int argc, char* argv[])
{
   
	pinMode(motorAfwdpin, PWM_OUTPUT);
	pinMode(motorAbackwdpin, PWM_OUTPUT);	
	
	
	
	const char *auth, *serv;
    uint16_t port;
    parse_options(argc, argv, auth, serv, port);
    Blynk.begin(auth, serv, port);
	
    while(true) {
		loop();
    }
    return 0;
  
}

There’s no Blynk WiringPi or ordinary WiringPi.
Blynk just may run on top of wiringPi on Linux (but may also run without it).
In your case, you should use virtual pins to perform your actions, without digging into what Blynk does for direct pin control.

Having same problem here, if anyone knows please help!

@LafarCodeer, has now created a new thread about his specific issue, all replies relating to that should be posted here:

Pete.