BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Motor Control with Raspberry on Blynk App

Hi All,

I am new, I would like to make two motor work on the Raspberry PiB+ and control on Blynk app but nothing working. Please someone help me and le me know what wrong with this code?

Thanks, to all your time and input
MinhP

  • edited - Mod

You need to edt your post(s) to format your code correctly.

Pete.

Hi Peter,

Please let me know more detail about edit code?

Thanks,
MP

When you created your post, it contained information about the type of information you should include, and how to format your code so that it displays correctly. You appear to have deleted that information without taking the information onboard.

This is how you format your code correctly…

Blynk - FTFC

Pete.

1 Like

The directions are in the Welcome topic and were in the post text you deleted when entering your own issue :stuck_out_tongue_winking_eye:

Blynk - FTFC

1 Like

Oops… duplicate responses again :stuck_out_tongue: I need to look up at the screen instead of down at the KB more often :rofl:

Sorry, I am new. I have not seen as you said about correct format code.

That is why there is a WELCOME topic (try clicking on the link I posted above) :wink: All forums have something similar for new users to learn the ropes.

You still don’t appear to have formatted the code correctly, and you seem to be missing a large piece of code.

Pete.


#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>



#include <wiringPi.h>

#include <softPwm.h>



BLYNK_WRITE(V1)

{

//FOREWORD LEFT SWING TURN

  int pinValue = param.asInt(); // assigning incoming value from pin V1 (left button)to a variable



  // STOP left motor

softPwmWrite (6, 100); //PWMA on GPIO. 6

digitalWrite (4, LOW); //AIN1 on GPIO. 4

digitalWrite (5, LOW); //AIN2 on GPIO. 5



// TURN ON CW right motor

softPwmWrite (29, 100); //PWMB on GPIO. 29

digitalWrite (27, HIGH); //BIN1 on GPIO. 27

digitalWrite (28, LOW); //BIN2 on GPIO. 28



}



BLYNK_WRITE(V2)

{

//FOREWORD RIGHT SWING TURN

  int pinValue = param.asInt(); // assigning incoming value from pin V2 (right button) to a variable



//TURN ON CW left motor

softPwmWrite (6, 100); //PWMA on GPIO. 6

digitalWrite (4, HIGH); //AIN1 on GPIO. 4

digitalWrite (5, LOW); //AIN2 on GPIO. 5



//STOP right motor

softPwmWrite (29, 100); //PWMB on GPIO. 29

digitalWrite (27, LOW); //BIN1 on GPIO. 27

digitalWrite (28, LOW); //BIN2 on GPIO. 28



}



BLYNK_WRITE(V0)

{

//FOREWORD 

  int pinValue = param.asInt(); // assigning incoming value from pin V0 (forward button) to a variable



  // TURN ON CW left motor

softPwmWrite (6, 100); //PWMA on GPIO. 6

digitalWrite (4, HIGH); //AIN1 on GPIO. 4

digitalWrite (5, LOW); //AIN2 on GPIO. 5



// TURN ON CW right motor

softPwmWrite (29, 100); //PWMB on GPIO. 29

digitalWrite (27, HIGH); //BIN1 on GPIO. 27

digitalWrite (28, LOW); //BIN2 on GPIO. 28



}



BLYNK_WRITE(V3)

{

//BACKWARD

  int pinValue = param.asInt(); // assigning incoming value from pin V3 (backward button) to a variable



  // TURN ON CW left motor

softPwmWrite (6, 100); //PWMA on GPIO. 6

digitalWrite (4, LOW); //AIN1 on GPIO. 4

digitalWrite (5, HIGH); //AIN2 on GPIO. 5



// TURN ON CW right motor

softPwmWrite (29, 100); //PWMB on GPIO. 29

digitalWrite (27, LOW); //BIN1 on GPIO. 27

digitalWrite (28, HIGH); //BIN2 on GPIO. 28



}





void setup()

{

softPwmCreate (6, 100, 100);

softPwmCreate (29, 100, 100);



}



void loop()

{

Blynk.run();

}



int main(int argc, char* argv[])

{

  const char *auth, *serv;

  uint16_t port;

  parse_options(argc, argv, auth, serv, port);



  Blynk.begin(auth, serv, port);



setup();

  while(true) {

loop();

  }



  return 0;

}

Here is the code, please let me know what wrong why not work with control on Blynk?
Thanks,
MP

Hi Peter and Gunner,

Finally, I can post my code correct format. Please review and let me know why not work on Blynk control?

Thanks, for your time
MP

OK, now that you seem to have the code formatting for forum posting done, i cleaned up this topic for a bit of clarity.

Now as for your code…

Is you project connected OK?

What to these commands actually control? (AKA a motor controller of some sort?) and are you sure they work? (AKA tried them without Blynk).

Hi Gunner,

My project is connect now but not working at all

Please advise.

Thanks,
MP

Hi Gunner,

I have this code working without Blynk. Please let me know how to connect to the Blynk to control on the iPhone. If previous code too complicate, please ignore. Please show me how onnect on this code, I test it working without Blynk

Thanks,
MP

cpp


import RPi.GPIO as GPIO
from time import sleep
 
GPIO.setmode(GPIO.BOARD)
 
Motor1A = 16
Motor1B = 18
Motor1E = 22
 
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
 
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Going backwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Now stop"
GPIO.output(Motor1E,GPIO.LOW)
 
GPIO.cleanup()

Well Blynk is basically just a user interface… you still use whatever code works without Blynk…

If this works, then use it instead of …

//FOREWORD 
// TURN ON CW left motor
softPwmWrite (6, 100); //PWMA on GPIO. 6
digitalWrite (4, HIGH); //AIN1 on GPIO. 4
digitalWrite (5, LOW); //AIN2 on GPIO. 5

// TURN ON CW right motor
softPwmWrite (29, 100); //PWMB on GPIO. 29
digitalWrite (27, HIGH); //BIN1 on GPIO. 27
digitalWrite (28, LOW); //BIN2 on GPIO. 28

Hi Gunner,

The new code work without Blynk. Please let me know how to connect to the Blynk with new code?

print “Going forwards”
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)

change to

print “Going forwards”
digitalWrite(Motor1A,GPIO.HIGH)
digitalWrite(Motor1B,GPIO.LOW)
analogWrite(Motor1E,GPIO.HIGH)

Will this ok?

I can’t tell you how to do it since I do not have the same setup to test… I am saying that it you have a way that works in a normal sketch, then the same commands should work within a BLYNK_WRITE(vPin) function.

Thanks, Gunner. It work well without Blynk. I do not know how to add to Blynk to control on iPhone.

MP

I can’t write your code for you.

The “good” code you show appears to be in Python? So either use Blynk’s Python library or figure out the proper way to control your motors with C++… THEN add in the Blynk interface.

NOTE Blynk Python is still in Alpha