# Ajuda para alteração de código

**URL:** <https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067>\
**Category:** Arduino\
**Created:** [Janeiro 30, 2020, 9:46pm UTC](https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067 "2020-01-30T21:46:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![evilome](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilome](https://forum.fazedores.com/u/evilome)\
**Post date:** [Janeiro 30, 2020, 9:46pm UTC](https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067/1 "2020-01-30T21:46:20Z")

</div>

Olá á todos!  
Terminei de montar uma máquina de dobrar arames através dum projeto publicado na internet do tipo “DIY”- [https://www.instructables.com/id/DIWire-Bender/](https://www.instructables.com/id/DIWire-Bender/)  
O fato é que sou leigo em eletrônica : sou tecnólogo na área de Qualidade e técnico em Mecânica aposentado.  
Após muitas pesquisas e leituras consegui fazê-la funcionar, mas não tão bem como desejava, visto que o projeto limitou o ângulo de dobra e comprimento de avanço em 124° e 124 mm, respectivamente e eu queria 155° e 155 mm.  
Já que tenho conhecimento de mecânica alterei o projeto para atender minha necessidade, porém agora preciso de auxílio eletrônico no sketch arduino uma vez que as dobras executadas não correspondem mais às coordenadas do arquivo “wiretest.txt” carregados no Processing  
O processo de dobra antes se dava por duas engrenagens: a menor de 12 dentes recebendo força diretamente do motor de passo acoplada numa de 36 dentes - relação 3:1 (dentes retos módulo 1,5)  
Na alteração mecânica tive que aumentar distância entre-eixos onde ficou: engrenagem menor 30 dentes recebendo força direta do motor acoplada numa de 60 dentes - relação 2:1 (dentes retos módulo 1,5).  
OBS: as engrenagens originais de 12 e 36 dentes são do padrão americano; substituí pelo módulo 1,5 e não houve problema.  
Substitui os motores de passo PK264A2A-SG10 que eram de 0,18° e drivers e também funcionaram corretamente.  
O arquivo “3D-Processing.txt” é carregado no software Processing.  
Observe no sketch que o range angular está dividido em 3 estágios: 1° à 90°; 91° à 120° e 121° à 180°.  
Creio que se faz necessário alterar o sketch arduino ajustando as formulas ao novo conjunto de engrenagens.  
Não tenho a mínima idéia de onde surgiram estas fórmulas… já entrei em contato com o autor do projeto, o qual não pôde me atender.  
Entenda-se “AJUDA” como “PRESTAÇÃO DE SERVIÇO REMUNERADO”.  
Se houver alguém disponível, me comunique para maiores esclarecimentos.  
Meu wattsapp (19)991987820

Eis o código:

- Feed Motor 1 - drives wire
- z Bend Motor - performs 3D bends by rotating entire assembly
- bend Motor - performs 2D bends by bending wire over
- benderPin - solenoid  
_/  
// pin assignments  
// Motor pulse and solenoid pins  
const int bendMotorPls = 9;  
const int zMotorPls = 10;  
const int feedMotorPls = 11;  
const int benderPin = 12;  
// AWO pins to allow motor shaft to free spin  
const int bendMotorAWO = 3;  
const int zMotorAWO = 4;  
const int feedMotorAWO = 5;  
// Direction pins to select drive direction  
const int bendMotorDir = 6;  
const int zMotorDir = 7;  
const int feedMotorDir = 8;  
//misc program constants  
const int pulseWidth = 20;  
const int pulseDelay = 700;  
// Drive directions in english  
boolean ccw = true; // counter-clockwise drive direction  
boolean cw = false; // clockwise drive direction  
boolean curDir = cw; // resets direction before next angle command  
int lastbend = 0;  
int fieldindex=0;  
int values[300]; //creates array  
void setup() {  
Serial.begin (9600); //com port communication  
pinMode (bendMotorPls, OUTPUT); //Declaring motor pins as out  
pinMode (zMotorPls, OUTPUT);  
pinMode (feedMotorPls, OUTPUT);  
pinMode (bendMotorAWO, OUTPUT);  
pinMode (zMotorAWO, OUTPUT);  
pinMode (feedMotorAWO, OUTPUT);  
pinMode (bendMotorDir, OUTPUT);  
pinMode (zMotorDir, OUTPUT);  
pinMode (feedMotorDir, OUTPUT);  
pinMode (benderPin, OUTPUT);  
digitalWrite (bendMotorPls, LOW); //starts with everything off  
digitalWrite (zMotorPls, LOW);  
digitalWrite (feedMotorPls, LOW);  
digitalWrite (benderPin, LOW);  
digitalWrite (zMotorAWO, HIGH);  
digitalWrite (feedMotorAWO, HIGH);  
digitalWrite (bendMotorAWO, HIGH);  
}  
void bend (float angle) { //bender pin movement  
if (angle!=0){ //sets direction of bend based on + or - angle  
Serial.println(“bending”);  
Serial.println(angle);  
boolean dir=cw;  
boolean back=ccw;  
if (angle\<0){  
dir = ccw;  
back = cw;  
}  
float rotations = 0;  
angle = abs(angle);  
 **if (angle \<= 90){**  
\*\* angle = -.0012_angle_angle+.5959_angle+.2452\*\*; //converts angle into calibrated motor steps  
angle = 6000 \* (angle/360)+220;  
}  
else if (91 \<= angle \<= 120){  
angle = .0044_angle_angle-.5481_angle+57.981; //converts angle into calibrated motor steps  
angle = 5960 \* (angle/360)+220;  
}  
else if (121\<=angle\<=180){  
angle = angle-63.26; //converts angle into calibrated motor steps  
angle = 5960 \* (angle/360)+220;  
} //calibration will differ depending on set up  
rotations = angle;  
// Serial.println (angle);  
digitalWrite (bendMotorDir, dir);  
for (int i=0; i \<=rotations ; i++){ //moves bender bin the desired angle  
digitalWrite(bendMotorPls, HIGH);  
delayMicroseconds (pulseWidth);  
digitalWrite(bendMotorPls, LOW);  
delayMicroseconds (pulseDelay);  
}  
delay (100);  
digitalWrite (bendMotorDir, back); //moves bender pin back to home position ready for next feed  
for (int i=0; i \<=rotations ; i++){  
digitalWrite(bendMotorPls, HIGH);  
delayMicroseconds (pulseWidth);  
digitalWrite(bendMotorPls, LOW);  
delayMicroseconds (pulseDelay);  
}  
}  
}  
void rotatePin (boolean dir, float angle) { //moves bender pin during duck. direction specified from duck subroutine  
float rotations = 0;  
angle = 6000 \* (angle/360); //converts angle to steps  
rotations = angle;  
Serial.println (dir);  
digitalWrite (bendMotorDir, dir);  
for (int i=0; i \<=rotations ; i++){ //rotates bender motor appropriate number of steps  
digitalWrite(bendMotorPls, HIGH);  
delayMicroseconds (pulseWidth);  
digitalWrite(bendMotorPls, LOW);  
delayMicroseconds (pulseDelay);  
}  
}  
void zbend (float angle) { //rotates z motor  
if (angle!=0){  
Serial.println(“Z bending”);  
Serial.println(angle);  
boolean dir=cw;  
if (angle\<0){ //+ angle is clockwise - angle is counter clockwise  
dir = ccw;  
}  
float rotations = 0;  
angle = abs(angle);  
angle = (2000 \* angle)/360; //converts angle to motor steps  
rotations = angle;  
digitalWrite (zMotorDir, dir); //sets motor direction  
for (int i=0; i \<=rotations ; i++){ //rotates z motor appropriate number of steps  
digitalWrite(zMotorPls, HIGH);  
delayMicroseconds (pulseWidth);  
digitalWrite(zMotorPls, LOW);  
delayMicroseconds (2000);  
}  
}  
}  
void feed (float dist) { //feeds wire  
if (dist != 0){  
Serial.println(“feeding”);  
Serial.println(dist);  
float rotations = 0;  
float feedCalib = 25.4_PI; //feed mm per revolution of motor  
dist = 2000 \* dist/feedCalib; //dist converted from mm to steps  
rotations = dist;  
digitalWrite (feedMotorDir, 1); //feed motor only moves forward  
for (int i=0; i \<=rotations ; i++){ //rotate feed motor appropriate number of steps  
digitalWrite(feedMotorPls, HIGH);  
delayMicroseconds (pulseWidth);  
digitalWrite(feedMotorPls, LOW);  
delayMicroseconds (pulseDelay);  
}  
}  
}  
void duck (){ //ducks bender pin under wire  
digitalWrite (benderPin, HIGH);  
delay (100);  
rotatePin (curDir, 45);  
digitalWrite (benderPin, LOW); //pin down move under wire  
curDir = !curDir; //direction reversed for next duck  
}  
void loop() {  
int copies = 0;  
while (Serial.available ()){ //starts once serial entry made  
digitalWrite (bendMotorAWO, LOW);  
digitalWrite (zMotorAWO, LOW);  
digitalWrite (feedMotorAWO, LOW);  
int in = Serial.read();  
byte incoming = in+128; //converts bytes from processing  
if (incoming != 255){ //255 signifies end of incoming array  
Serial.println (Serial.read());  
values[fieldindex] = values[fieldindex]\*10+incoming; //fills array fieldindex from incoming processing  
fieldindex++;  
}  
else{  
Serial.println(“END”); //if array end marker inputs from processing end  
for (int i=0; i\<=fieldindex;i++){  
Serial.println(values[i]-128);  
}  
copies=copies+1;  
}  
}  
if (copies==1){ //once bend is complete eject shape  
delay (1000);  
motorrun();  
feed(50); //eject  
copies=copies+1;  
}  
}  
void motorrun(){  
int lastbend=0;  
for (int i=0; i\<= fieldindex;i++){  
delay (100);  
if ((values[i]-128)==126){ //convert bytes from processing and look for feed motor marker  
feed (values[i+1]-128); //if feed motor marker detected next value in array is a feed length  
}  
else if ((values[i]-128)==125){ //convert bytes from processing and look for bend motor marker  
int bendAng = (values[i+1]-128); //if bend motor marker detected next value in array is a bend angle  
if ((bendAng\<0&&curDir==cw) || (bendAng\>0 && curDir ==ccw)){ //if incoming bend angle is opposite direction from previous angle duck pin  
duck ();  
delay (100);  
}  
bend (bendAng);  
lastbend = bendAng;  
}  
else if ((values[i]-128)==124){ //convert bytes from processing and look for z motor marker  
zbend (values[i+1]-128); //if z motor marker detected next value in array is z bend angle  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![evilome](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilome](https://forum.fazedores.com/u/evilome)\
**Post date:** [Março 10, 2021, 10:59am UTC](https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067/2 "2021-03-10T10:59:58Z")

</div>

Pessoal, depois de bastante trabalho, finalmente minha dobradeira de arames está funcionando corretamente.  
Agradeço demais ao @Igor_Paiva, cuja participação e suporte foram fundamentais.  
Até a próxima.

---

<div class="post-metadata">

**Author:** ![evilome](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilome](https://forum.fazedores.com/u/evilome)\
**Post date:** [Março 10, 2021, 12:48pm UTC](https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067/3 "2021-03-10T12:48:20Z")

</div>

![VIDEO-2021-02-20-13-10-57](https://us1.discourse-cdn.com/flex016/uploads/fazedores/original/2X/8/8f9da327a75040620b6183ee45df539bbc55b6e5.webp)  
Este é um exemplo de arte criada com dobras executadas na dobradeira 3d.  
Tenho plano de criar uma coleção de clássivos Volksvagen - iniciei pela Variant

---

<div class="post-metadata">

**Author:** ![Celio\_Santos](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.fazedores.com/celio_santos/32/2934_2.png) [@Celio\_Santos](https://forum.fazedores.com/u/Celio_Santos)\
**Post date:** [Setembro 11, 2022, 3:36pm UTC](https://forum.fazedores.com/t/ajuda-para-alteracao-de-codigo/7067/4 "2022-09-11T15:36:55Z")

</div>

Fantastico!!! Precisamos te encomendar umas centenas de peças dobradas em arame como faço?
