Wooden curtain pole automation. Arduino/Blynk config

Hi Can the joystick be set up to be off (0) at centre and then 1023 left to right? i want 3 buttons and a joystick on the interface.

button 1 is turn on/off the power (sleep pin on A4988 controller
Button 2 close curtains, set the motor in ccw direction until limit switch reached.
Button 3 open curtains, set the motor in cw direction until limit switch reached.
And the joystick to jog ccw/cw with spring return to stationary in the middle (subject to limit switches!)

Before i start pasting code (its nowhere near complete, just wondered if this layout of the GUI would work like i want it to? so far ive not managed it!


void loop()

No, the centre position is always half way between the lower and higher values that you select.
If you select 0 to 1023 then the centre will be 512.
You could select -1023 to 1023, the centre would then be 0.

However, it doesn’t really matter. It’s a simple task to process the values in your sketch to give the functionality you want.

Pete.

Hi Pete, thanks for getting back to me, i tried setting the vals at 1023-1023 yesterday and the stick values stay at 1023 where ever you move it to, i guess ill have to find out how to address the programming side.

Unfortunately im new and that will take time. ill have a pop at it and pop back with any problems, thanks.

But that’s not what I suggested is it?

1023 to 1023 will obviously give an output of 1023 in every position.

However minus 1023 to plus 1023 will give a centre value of zero.

Pete.

DOH! Thanks Pete. im sorry im dyslexic, and i miss read a LOT of things but as an engineer the logic should have come to me without asking!

Is it possible to restrict the stick across the y axis so that any vertical movement doesnt effect the output?

Setting it to 0-0 will do that, but you really ought to be processing (or ignoring as the case may be) the x & y values in your sketch.

Pete.

Hi Pete/All

Bashing my head against the wall now, and the peeps over at arduino just dont seem to get blynk at all.

Ive got the bones of a sketch that works until i try to put limit switches in and then it just stops working. Ive included the code below and ignoring the joystick whim, at the moment it works with 5 buttons.
ON/OFF (switch)
OPEN (switch)
CLOSE (switch)
JOG OPEN (button)
JOG CLOSE Button)

i want to put limits in for fully open and closed so that the motor doesnt over run. ideally i want to make open/closed buttons as well, so that once pressed the motor will essentially home. ive tried while conditions, (you can see one // out) but the program just stops working and the app connects/disconnects all the time.

For the jog buttons i tried if statements and also && but to no avail. i just dont understand why it wont work if anyone can help id be extremely grateful

// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

byte limitCW = D0;
byte limitCCW = D1;
byte directionPin = D2;
byte stepPin = D3;
byte buttonOnOffpin = D4;
byte buttonCWpin = D5;
byte buttonCCWpin = D6;
byte buttonJogCWpin = D7;
byte buttonJogCCWpin = D8;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
boolean buttonJogCWpressed = false;
boolean buttonJogCCWpressed = false;
boolean buttonOnOffpressed = false;


unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 1; // milliseconds

void setup()
{
// Debug console
Serial.begin(9600);
Serial.println("Starting Stepper Demo with millis()");

pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(buttonOnOffpin, OUTPUT);

pinMode(limitCW, INPUT);
pinMode(limitCCW, INPUT);
pinMode(buttonCWpin, INPUT);
pinMode(buttonCCWpin, INPUT);
pinMode(buttonJogCWpin, INPUT);
pinMode(buttonJogCCWpin, INPUT);

Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();

curMillis = millis();
readButtons();
actOnButtons();

}

void readButtons() {

buttonCCWpressed = false;
buttonCWpressed = false;
buttonJogCCWpressed = false;
buttonJogCWpressed = false;
buttonOnOffpressed = false;

if (digitalRead(buttonCWpin) == HIGH) {
  buttonCWpressed = true;
}
if (digitalRead(buttonCCWpin) == HIGH) {
  buttonCCWpressed = true;
}
if (digitalRead(buttonJogCWpin) == HIGH) {
  buttonCWpressed = true;
}
if (digitalRead(buttonJogCCWpin) == HIGH) {
  buttonCCWpressed = true;
}
if (digitalRead(buttonOnOffpin) == HIGH) {
  buttonOnOffpressed = true;
}
}

void actOnButtons() {
if (buttonCWpressed == true) {
  while (limitCW = HIGH)
  digitalWrite(directionPin, LOW);
  singleStep();
}
if (buttonCCWpressed == true) {
  digitalWrite(directionPin, HIGH);
  singleStep();
}
if (buttonJogCWpressed == true) {
  digitalWrite(directionPin, LOW);
  singleStep();
}
if (buttonJogCCWpressed == true) {
  digitalWrite(directionPin, HIGH);
  singleStep();
}
if (buttonOnOffpressed == true) {
digitalWrite(buttonOnOffpin, HIGH);
}
}

void singleStep() {
if (curMillis - prevStepMillis >= millisBetweenSteps) {
  // next 2 lines changed 28 Nov 2018
  //prevStepMillis += millisBetweenSteps;
  prevStepMillis = curMillis;
  digitalWrite(stepPin, HIGH);
  digitalWrite(stepPin, LOW);
}
}```

@markvk please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Done, assumed it was the same as ardino forum where you use </> sorry

So you have your joystick attached to digital pins?
Are your other buttons widget buttons or physical buttons?

Pete.

the joystick isnt connected at the moment. I thought id tackle that once id got it working.

there are no actual physical buttons on the bread board, if thats what you asking. I have never had any intention of using physical buttons that can be pressed.

in the blynk app at the moment i have the following:

switch 1 ON/OFF assigned to D4, this makes the sleep pin high on the A4988 and supplies power to the motor. I hope to do this with batteries and so i dont want the stepper constantly drawing current.

Switch 2 assigned to D5. at the moment it configured as a switch but it needs to be a button once ive got the sketch sorted. the idea that it sends a momentary signal which send the motor home (close curtains)

Switch 3 assigned to D6. at the moment it configured as a switch but it needs to be a button once ive got the sketch sorted. the idea that it sends a momentary signal which send the motor home (open curtains)

push button 4 assigned D7 allows independent movement of curtains (subject to limit switch) for partial open/close (this is where the joystick will hopefully come in, it would look far more funky :rofl:

push button 5 assigned D8 allows independent movement of curtains (subject to limit switch) for partial open/close

Okay, in that case, I’d suggest that you scrap the use of digital pins and move to virtual pins instead.

That’s probably not going to work. Whatever board that it is that you’re using to control the motor diver will draw more power than batteries can reasonably supply.

Pete.

oh gawd more code! actually it might be a good idea to keep the digital pins, i can make a plugin optional controller (internet failure)

maybe/maybe not its all about design evolution, the motor driver does draw 0.5ahr yes, which is why i want it to switch off when not in use, the d1 mini draws only draws 0.05 ahr. A fixed supply is something that is an option but a small solar panel mounted in the window should cope with that. One thing ive learned about power is that you can do all the maths in the world, real life never works out that way!

You can still use physical pins alongside digital pins.
Trust me, using digital pins for your widget with a project like this is going to result in a world of pain!

I’m not sure where you get these numbers from, but trust me, You’ll need quite a large solar panel and battery to make this a battery powered project.
Don’t forget, you can’t use deep sleep if you want the device to be responsive to Blynk commands.

Another thing, your current void loop won’t work well with Blynk. You should read this…
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

and, your code is missing the Blynk libraries at the moment.

Pete.

Fair enough virtual it is, the way the blynk blurb reads its simplicity itself to use digital pins and no extra code is required.

My bench power supply tells me what current is being drawn at any one time and i confirmed it with a Fluke multimeter.

According to the maths it should work but like i said earlier real life isnt maths! the proof of the pudding will be in the eating… swopping out a battery supply for a fixed one is not a problem.

on the d1 mini no thats true but it only draws 0.05 Ahr, the greedy one which its the A4988 motor controller can be put to sleep that draws about.0.5 Ahr i have this working with switch1, making the sleep pin on the A4988 high puts the board to sleep leaving just the mini awake for blynk at 0.05 Ahr

Thanks for that ill read it.

My Bad just didnt copy that bit over.

  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "GdXuPDTYzFyO0qXSZHOSr6VYOltp1xQ_";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Mark & Kims Place HD";
char pass[] = "SmellyEllie8";

byte limitCW = D0;
byte limitCCW = D1;
byte directionPin = D2;
byte stepPin = D3;
byte buttonOnOffpin = D4;
byte buttonCWpin = D5;
byte buttonCCWpin = D6;
byte buttonJogCWpin = D7;
byte buttonJogCCWpin = D8;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
boolean buttonJogCWpressed = false;
boolean buttonJogCCWpressed = false;
boolean buttonOnOffpressed = false;


unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 1; // milliseconds

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(buttonOnOffpin, OUTPUT);

  pinMode(limitCW, INPUT);
  pinMode(limitCCW, INPUT);
  pinMode(buttonCWpin, INPUT);
  pinMode(buttonCCWpin, INPUT);
  pinMode(buttonJogCWpin, INPUT);
  pinMode(buttonJogCCWpin, INPUT);

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();

  curMillis = millis();
  readButtons();
  actOnButtons();

}

void readButtons() {

  buttonCCWpressed = false;
  buttonCWpressed = false;
  buttonJogCCWpressed = false;
  buttonJogCWpressed = false;
  buttonOnOffpressed = false;

  if (digitalRead(buttonCWpin) == HIGH) {
    buttonCWpressed = true;
  }
  if (digitalRead(buttonCCWpin) == HIGH) {
    buttonCCWpressed = true;
  }
  if (digitalRead(buttonJogCWpin) == HIGH) {
    buttonCWpressed = true;
  }
  if (digitalRead(buttonJogCCWpin) == HIGH) {
    buttonCCWpressed = true;
  }
  if (digitalRead(buttonOnOffpin) == HIGH) {
    buttonOnOffpressed = true;
  }
}

void actOnButtons() {
  if (buttonCWpressed == true) {
    //while (limitCW = HIGH)
    digitalWrite(directionPin, LOW);
    singleStep();
  }
  if (buttonCCWpressed == true) {
    digitalWrite(directionPin, HIGH);
    singleStep();
  }
  if (buttonJogCWpressed == true) {
    digitalWrite(directionPin, LOW);
    singleStep();
  }
  if (buttonJogCCWpressed == true) {
    digitalWrite(directionPin, HIGH);
    singleStep();
  }
  if (buttonOnOffpressed == true) {
  digitalWrite(buttonOnOffpin, HIGH);
  }
}

void singleStep() {
  if (curMillis - prevStepMillis >= millisBetweenSteps) {
    // next 2 lines changed 28 Nov 2018
    //prevStepMillis += millisBetweenSteps;
    prevStepMillis = curMillis;
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);
  }
}```.

That’s true. However, you’re attempting to scan the values of the digital pins that you’re manipulating in the Blynk app, and that’s not really how they are intended to be used.

Virtual pins actually make the coding easier, once you’ve figured-out how they work.
If you have a button widget attached to pin V0 then every time the value of that pin changes it triggers a special BLYNK_WRITE(V0) callback in the code.

You can then work-out what the value of the virtual pin is now, by using the param.asInt() command. The value will normally be a 0 or a 1 for a straightforward button widget, but could be a value like 1023 from a joystick widget.
This means that you don’t need to constantly scan the GPIO pins that the digital widgets are connected to to be able to use your limit switches. You only read the limit switch pin status within the BYNK_WRITE(vPin) function and then only command the motor to move if the limit hasn’t been reached.

I think you’re confusing amps with amp-hours, but as you say, the proof of the pudding…

Pete.

just reading about it all now.

correct! 3Ahr its not going to work.

Hi Peter.

Thanks for your time so far, im having a re think regarding the design of this project and am looking into switching out the stepper for a normal DC motor.

i think that the code will be much simpler and the power consumption more manageable. ive had a tes rig running on the D1 mini now for 3 days running off 2x8v lion batteries in series charging off a small12v solar panel, and so far its holding up well.

1 Like