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

Armbot - Delay Problem

#1

Hello!
I am trying to do a project of an armbot that gets the positions of 5 servos from the user, stores on 5 arrays and after uses to repeat a sequence. For that I’m just using a Nano version of Arduino and 5 servos. The fact is that after I get the position points for the sequence I try to execute and it cannot do each step… I’ve already try to put a delay after any of the movements but then I get an error…I’m just a newbie and I’ve tried to google any solution without any success so my alternatives just gone away… Here is my code (the sequence is executed when press V8 button / comments and terminal writes are in portuguese but they are not important):

//Define comunicação serial do Blynk com o USB
#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX 
#include <BlynkSimpleStream.h>

//Inclui biblioteca do servo
#include <Servo.h>

// Token de autenticação do Blynk (para cada projeto)
char auth[] = "cb6b4e5873e149a48e32fd774a6efaec";

// Definição dos nomes dos servos
Servo garra;
Servo pulso;
Servo cotovelo;
Servo ombro;
Servo tronco;

// Configurando terminal
WidgetTerminal terminal(V0);

// Definição das variáveis de posição dos servos e das auxiliares para sequência
int garraPOS[10];
int garraINST;
int pulsoPOS[10];
int pulsoINST;
int cotoveloPOS[10];
int cotoveloINST;
int ombroPOS[10];
int ombroINST;
int troncoPOS[10];
int troncoINST;

int i;
int j;

// Movimentação dos servos pelos sliders
BLYNK_WRITE(V1)
{
  garra.write(param.asInt());
  if (garraINST != param.asInt()){
    garraINST = param.asInt();
  }
}

BLYNK_WRITE(V2)
{
  pulso.write(param.asInt());
  if (pulsoINST != param.asInt()){
    pulsoINST = param.asInt();
  }
}

BLYNK_WRITE(V3)
{
  cotovelo.write(param.asInt());
  if (cotoveloINST != param.asInt()){
    cotoveloINST = param.asInt();
  }
}

BLYNK_WRITE(V4)
{
  ombro.write(param.asInt());
  if (ombroINST != param.asInt()){
    ombroINST = param.asInt();
  }
}

BLYNK_WRITE(V5)
{
  tronco.write(param.asInt());
  if (troncoINST != param.asInt()){
    troncoINST = param.asInt();
  }
}

// Gravar pontos
BLYNK_WRITE(V6)
{
  if (param.asInt() == 1){
    i = j;

    garraPOS[i] = garraINST;
    pulsoPOS[i] = pulsoINST;
    cotoveloPOS[i] = cotoveloINST;
    ombroPOS[i] = ombroINST;
    troncoPOS[i] = troncoINST;
    terminal.flush();
    Blynk.virtualWrite(V0,"* Gravado ponto: ");
    Blynk.virtualWrite(V0,i);
    i++;
    j++;    
  }
}

// Limpar pontos
BLYNK_WRITE(V7)
{
  terminal.flush();
  Blynk.virtualWrite(V0,"*** Limpando pontos.");
  for (i=0; i <= j; i++){
    garraPOS[i] = 0;
    pulsoPOS[i] = 0;
    cotoveloPOS[i] = 0;
    ombroPOS[i] = 0;
    troncoPOS[i] = 0;
  }
  i = 0;
  j = 0;
}

// Realizar sequência
BLYNK_WRITE(V8)
{
  if (param.asInt() == 1){
     terminal.flush();
     Blynk.virtualWrite(V0,"Iniciada sequência de posições. ");
     Blynk.virtualWrite(V0,"Total de ");
     Blynk.virtualWrite(V0,i);
     Blynk.virtualWrite(V0," pontos para executar.");
     for(i=0; i<= j; i++){
      garra.write(garraPOS[i]);
      pulso.write(pulsoPOS[i]);
      cotovelo.write(cotoveloPOS[i]);
      ombro.write(ombroPOS[i]);
      tronco.write(troncoPOS[i]);
      Blynk.virtualWrite(V0,"** Ponto: ");
      Blynk.virtualWrite(V0,i);
     }
     i = j;
  }
}

void setup() {
// Debug console
  SwSerial.begin(9600);

// Blynk funcionará pelo serial, deve-se abrir no Arduino IDE: Ferramentas -> Blynk:Run USB Script
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

// Define os pinos para os servomotores
  garra.attach(5);
  pulso.attach(6);
  cotovelo.attach(9);
  ombro.attach(10);
  tronco.attach(11);

// Calibração de posição incial dos servomotores e limpando variáveis
  for (0; i <= j; i++){
    garraPOS[i] = 0;
    pulsoPOS[i] = 0;
    cotoveloPOS[i] = 0;
    ombroPOS[i] = 0;
    troncoPOS[i] = 0;
  }
  i = 0;
  j = 0;
  
//  garra.write(70);
//  pulso.write(90);
//  cotovelo.write(130);

  terminal.clear();
  terminal.flush();
  Blynk.virtualWrite(V0,"Olá! Calibração concluída e servos em posição inicial.\n");
}

void loop() {
  Blynk.run();
}
0 Likes

#2

Please properly format all posted code… as per the Welcome topic. I fixed your last post.

0 Likes

#3

Thank you. I already read that I need to format but I didn’t know how to do that… Next time I will try again.

0 Likes