Components and supplies
Capacitor 10 µF
Arduino UNO
Stepper Motor, Bipolar
Jumper wires (generic)
Stepper motor driver board A4988
shatf coupler flexible
Tools and machines
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Mastech MS8217 Autorange Digital Multimeter
Project description
Code
Arduino Code
arduino
Receive from Python the solution and run the moves
1 2/* 3 * by hernando Bolaños 4 * 5 * Piece of code from, Matt2Yu, VER instructables 6*/ 7 8 9 10////////////////////////////////////////////////////////////////////////////////////////////////////// 11////WARNING: PROTOTYPE BASED ON CUBESPINNER //// 12///////////////////////////////////////////////////////////////////////////////////////////////////// 13 14 15#define STEP_L 4 // pin STEP de A4988 a pin 4 PWM- manejando la cara down del cubo 16#define DIR_L 5 // pin DIR de A4988 a pin 5 PWM-manejandola cara down del cubo 17#define STEP_R 6 // pin STEP de A4988 a pin 4 PWM-manejando la cara right del cubo 18#define DIR_R 7 // pin DIR de A4988 a pin 5 PWM-manejando la cara righ delcubo 19 20#define STEP_F 8 // pin STEP de A4988 a pin 4- manejando la cara "up" del cubo 21#define DIR_F 9 // pin DIR de A4988 a pin 5 -manejandola cara "up" del cubo 22 23 24 25 26int pasos = 200/4; // LATERALES pasos 90 grados con motor Hanpose 17HS3430 : 1.8 grados por paso en condicion Full step- Se probo comportamiento en otras configuraciones de pasos 27int Fpasos1=274/4; //FRENTE Pasos para angulo de front avanzar la cara 28int Fpasos2=74/4; //FRENTE Pasos para angulo de front quedar en posicion esperando nuevo movimiento 29int Fpasos3=268/4; //FRENTE Pasos para angulo de front inv quedar en posicion esperando nuevo movimiento-front inv 30int Fpasos4=70/4; //FRENTE Pasos para angulo de front inv quedar en posicion esperando nuevo movimiento-front inv 31int pasosr=3*pasos; 32String kociemba_sol = ""; 33 34 35int tiempo_step= 600; //microseconds -segun DS minimo tiempo permitido del step de motores 1 microsegundo 36int tiempo_stepF= 1400; //microseconds- tiempo para usar en el frente con los demas andando en tiempo_step 37 38int espera=200; //tiempo de espera despues de un movimiento 39 40int esperaT=50; 41 42void setup() 43{ 44 45 pinMode(STEP_L, OUTPUT); // pin 4 como salida 46 pinMode(DIR_L, OUTPUT); // pin 5 como salida 47 48 49 pinMode(STEP_R, OUTPUT); // pin 6 como salida 50 pinMode(DIR_R, OUTPUT); // pin 7 como salida 51 52 53 pinMode(STEP_F, OUTPUT); // pin 8 como salida 54 pinMode(DIR_F, OUTPUT); // pin 9 como salida 55 56delay(7000); 57 58 59 Serial.begin(9600); 60 61 62 while (! Serial); // Wait untilSerial is ready 63 //assign_to_current(yellow_side); 64 //print_cube(current_side); 65 66} 67 68void loop() 69{ 70 71//recibir la solucion de kociemba por puerto serial 72 73//accept_string(); 74 75 //calentando 5 segundos 76 77Serial.println("Calentando para fotos: volvera a la posicion inicial"); 78 79 80//right(); 81//right_inv(); 82//front(); 83//front_inv(); 84//left(); 85//left_inv(); 86 87delay(2000); 88 89 90Serial.println("Arduino dice:Inicia a correr la solucion:"); 91 92 93 run_kociemba(); //corre el string recibido 94 95 Serial.println("Arduino dice: Finaliza tiempo solucion"); 96 97//mostrar el cubo resuelto 98 99show_off_cube(); 100 101 102 Serial.println("Arduino dice:Finalizado enviar nueva solucion de Kociemba"); 103 104 while(true){} 105} 106 107 108void accept_string() ////Se comunica el Arduino con el PC le confirma que esta listo para recibir la solucion en un STRING-la recibe///// 109{ 110 char ready_signal = 'ready'; 111 char received_signal = 'received'; 112 113 for (int piece_num = 0; piece_num <5; piece_num++) 114 { 115 // send ready signal 116 Serial.println(ready_signal); 117 delay(100); 118 } 119 // receive string 120 while(kociemba_sol == "") 121 { 122 char character; 123 while(Serial.available()) 124 { 125 character = Serial.read(); 126 kociemba_sol.concat(character); 127 } 128 } 129 delay(10); 130 Serial.print("String Aceptado: "); 131 Serial.print(kociemba_sol); 132 133 // Se envia confirmacion de recibido al PC con el STRING para reconfirmar 134 Serial.println("arduino dice:"); 135 Serial.println(received_signal); 136 Serial.println(kociemba_sol); 137 delay(10); 138} 139 140 141 142//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 143////Aqui se recibe de python la solucion de kociemba y se convierte en movimientos de los stepper motors"/////// 144//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 145 146void run_kociemba(){ 147 148//steppers en posicion inicial- home 149 150 151 152 153kociemba_sol="U B U' RR D L' D F' L U F LL U LL BB U' BB U' FF RR LL"; 154 155//Solved from Python for test 156 157//"U B U' RR D L' D F' L U F LL U LL BB U' BB U' FF RR LL"; 158 159//"L' U B' DD L DD F' R D R L' UU FF LL BB RR U RR LL FF D"; 160 161//"RR FF U' L UU BB D B' D R' F U RR U FF U' LL BB RR LL"; 162 163//"R F' B' L' U D' BB R' DD R' F' BB LL FF DD BB U BB RR U DD"; 164 165//"FF B' UU RR UU B D' R' F' L' U' BB UU LL D' FF U' FF BB D'"; 166 167 168 169//"D R FF BB U RR LL B' R D F LL BB LL DD FF D FF BB LL D"; 170//"R D' LL BB U F BB U F U RR U LL FF U' FF UU D' RR": 171 172//" FFFFBRRRRRRRR'R'R' RRRRLLLLLLLL'L'"; 173 174//kociemba_sol= "F'F'F'F'F'FFFFFFFFFFFFFF"; 175 176//kociemba_sol="U L' U DD B DD FF B' L' U' B' U' LL U LL U' RR UU RR BB U'"; 177 178//"RR U RR B' U F' D BB U' B L' DD RR UU D FF D LL U' FF BB"; 179 180 181//"U BB L U' F' L' B UU R' D' B' D RR U DD BB RR D LL FF D"; 182 183//"U F' BB U' F UU F R' U' LL F' L U RR U FF RR UU RR BB DD RR"; 184 185//"U R BB DD F' U' F' R F' B' U B DD RR FF U' RR U' BB DD RR FF"; 186 187 188//"FF UU F LL D BB U' RR F' R' U D BB D FF LL D' RR UU LL"; 189 190//"UU D' BB DD F' R L F' BB U' L' D' BB U BB LL U FF LL BB UU"; 191 192//"U R UU B U' F' U FF BB RR U L U DD LL UU RR D' FF RR D LL"; 193 194//"D' RR DD B' RR L' FF D' FF R' D FF RR FF LL BB DD BB D BB"; 195 196//"R' D' R' D' F U R BB D' FF R' D FF RR FF LL BB DD BB D BB"; 197 198//"F R F L B' RR F' LL D' F L FF UU LL D' LL BB UU FF"; 199 200//"B' D' L' U F RR LL F L' F' U' RR U' FF RR LL FF DD FF U'"; 201 202//"F' RR U L' U F' D' RR U' DD F' U' BB RR FF U LL U' BB LL"; 203//"RRRRR'RFBLlU'RLFD'F L BB U RR FF UU LL BB RR DD RR"; 204 205 206// Length (with one extra character for the null terminator) 207 208int str_len = kociemba_sol.length() + 1; 209 210 211Serial.println("Arduino dice: Caracteres:"); 212Serial.println((str_len-1)); 213 214for(int i = 0; i <= (str_len-1); i++){ //recorre 215 216//Serial.print(i); 217 218 219if ((kociemba_sol.charAt(i)) =='R'){ 220 221 222if ((kociemba_sol.charAt(i+1)) == '2') { 223 right(); 224 right();} 225 226 227if ((kociemba_sol.charAt(i+1)) == '\\'') { 228 right_inv();} 229 230if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 231 right();} 232 233} 234 235else { //NO HACER NADA 236 237} 238 239 240 241if ((kociemba_sol.charAt(i)) =='L'){ 242 243 244if ((kociemba_sol.charAt(i+1)) == '2') { 245 left(); 246 left();} 247 248 249if ((kociemba_sol.charAt(i+1)) == '\\'') { 250 left_inv();} 251 252if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 253 left();} 254 255} 256 257else { //NO HACER NADA 258 259} 260 261 262 263if ((kociemba_sol.charAt(i)) =='U'){ 264 265 266if ((kociemba_sol.charAt(i+1)) == '2') { 267 up(); 268 up();} 269 270 271if ((kociemba_sol.charAt(i+1)) == '\\'') { 272 up_inv();} 273 274if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 275 up();} 276 277} 278 279else { //NO HACER NADA 280 281} 282 283 284 285if ((kociemba_sol.charAt(i)) =='D'){ 286 287 288if ((kociemba_sol.charAt(i+1)) == '2') { 289 down(); 290 down();} 291 292 293if ((kociemba_sol.charAt(i+1)) == '\\'') { 294 down_inv();} 295 296if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 297 down();} 298 299} 300 301else { //NO HACER NADA 302 303} 304 305 306 307 308 309if ((kociemba_sol.charAt(i)) == 'F'){ 310 311 312if ((kociemba_sol.charAt(i+1)) == '2') { 313 front(); 314 front();} 315 316 317if ((kociemba_sol.charAt(i+1)) == '\\'') { 318 front_inv();} 319 320if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 321 front();} 322 323} 324 325else { //NO HACER NADA 326 327} 328 329 330 331 332if ((kociemba_sol.charAt(i)) =='B'){ 333 334 335if ((kociemba_sol.charAt(i+1)) == '2') { 336 back(); 337 back();} 338 339 340if ((kociemba_sol.charAt(i+1)) == '\\'') { 341 back_inv();} 342 343if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 344 back();} 345 346} 347 348else { //NO HACER NADA 349 350} 351 352} 353 354 355 356} 357//////////////////////////////////////////////////////////////////////////// 358/////Rutinas del Cubo- se puede usar asi : YELLOW at FRONT -BLUE at UP////// 359/////////////////////////////////////////////////////////////////////////// 360 361 362 363void right_inv()// movimiento RIGHT inverso del Cubo 364{ 365 366 367 368Serial.println("R',"); 369 370 371 372digitalWrite(DIR_R, LOW); // 373 for(int i = 0; i < pasosr; i++){ //Mueve 3x90 grados 374 digitalWrite(STEP_R, HIGH); // nivel alto 375 delayMicroseconds(tiempo_step); 376 delayMicroseconds(tiempo_step);// por x ms segun 377 digitalWrite(STEP_R, LOW); // nivel bajo variable tiempo_step 378 delayMicroseconds(tiempo_step); // por x ms segun variable tiempo_step 379 delayMicroseconds(tiempo_step); 380 } 381 delay(espera); 382 383} 384 385 386 387void right()// mueve el cubo Right 388{ 389 390 391Serial.println("R,"); 392 393 394digitalWrite(DIR_R, LOW); // 395 for(int i = 0; i < pasos; i++){ // 396 digitalWrite(STEP_R, HIGH); 397 delayMicroseconds(tiempo_step); 398 delayMicroseconds(tiempo_step); 399 digitalWrite(STEP_R, LOW); 400 delayMicroseconds(tiempo_step); 401 delayMicroseconds(tiempo_step); 402 } 403 delay(espera); // demora de x segundos 404 405 406} 407 408 409 410void up()// mueve el cubo UP 411{ 412 413 414Serial.println("U,"); 415 416 417rinv_l(); 418delay(100); 419front(); 420delay(100); 421rinv_l(); 422rinv_l(); 423rinv_l(); 424delay(espera); 425} 426 427 428 429void up_inv()// mueve el cubo UP INV 430{ 431 432 433Serial.println("U',"); 434 435 436rinv_l(); 437delay(100); 438front_inv(); 439delay(100); 440rinv_l(); 441rinv_l(); 442rinv_l(); 443delay(espera); 444 445 } 446 447 448 449 450 451void down()// mueve el cubo UP 452{ 453 454 455Serial.println("D,"); 456 457 458rinv_l(); 459rinv_l(); 460rinv_l(); 461delay(100); 462front(); 463delay(100); 464rinv_l(); 465delay(espera); 466 467 468 469 470} 471 472void down_inv()// mueve el cubo Down_INV 473{ 474 475 476 477Serial.println("D',"); 478 479 480rinv_l(); 481rinv_l(); 482rinv_l(); 483delay(100); 484front_inv(); 485delay(100); 486rinv_l(); 487delay(espera); 488 489} 490 491 492void left()// mueve el cubo LEFT 493 494{ 495 496Serial.println("L,"); 497 498digitalWrite(DIR_L, LOW); // giro en sentido 499 for(int i = 0; i < pasosr; i++){ // 500 digitalWrite(STEP_L, HIGH); // nivel alto 501 delayMicroseconds(tiempo_step); // por x mseg 502 delayMicroseconds(tiempo_step); 503 digitalWrite(STEP_L, LOW); // nivel bajo 504 delayMicroseconds(tiempo_step); // por x mseg 505 delayMicroseconds(tiempo_step); 506 } 507 delay(espera); 508 509 510 511} 512 513 514void left_inv()// mueve el cubo LEFT INV 515{ 516 517 518Serial.println("L',"); 519 520digitalWrite(DIR_L, LOW); // giro en sentido NCW 521 for(int i = 0; i < pasos; i++){ //90 grados= xx pasos para motor de yy grados de angulo de paso 522 digitalWrite(STEP_L, HIGH); 523 delayMicroseconds(tiempo_step); 524 delayMicroseconds(tiempo_step); 525 digitalWrite(STEP_L, LOW); 526 delayMicroseconds(tiempo_step); 527 delayMicroseconds(tiempo_step); 528 529 530 } 531 532 533 delay(espera); // demora de 2 segundos 534} 535 536 537 538void front_inv()// mueve el cubo front_inv 539{ 540Serial.println("F',"); 541 542digitalWrite(DIR_F, HIGH); // giro en sentido CW 543 for(int i = 0; i < Fpasos3; i++){ //135 grados= xx pasos para motor de yy grados de angulo de paso 544 digitalWrite(STEP_F, HIGH); // nivel alto 545 delayMicroseconds(tiempo_stepF); // por 10 mseg 546 digitalWrite(STEP_F, LOW); // nivel bajo 547 delayMicroseconds(tiempo_stepF); // por 10 mseg 548 } 549 550delay(100); 551 552digitalWrite(DIR_F, LOW); 553 for(int i = 0; i < Fpasos4; i++){ //45 grados= 25x16 pasos para motor de 1.8 grados de angulo de paso 554 digitalWrite(STEP_F, HIGH); // nivel alto 555 delayMicroseconds(tiempo_stepF); // por 10 mseg 556 digitalWrite(STEP_F, LOW); // nivel bajo 557 delayMicroseconds(tiempo_stepF); // por 10 mseg 558 } 559 delay(espera); 560 561 562} 563 564 565 566void front()// mueve el cubo front 567{ 568 569Serial.println("F,"); 570 571digitalWrite(DIR_F, LOW); // 572 for(int i = 0; i < Fpasos1; i++){ //135 grados= 70x16 pasos para motor de 1.8 grados de angulo de paso 573 digitalWrite(STEP_F, HIGH); 574 delayMicroseconds(tiempo_stepF); 575 digitalWrite(STEP_F, LOW); 576 delayMicroseconds(tiempo_stepF); 577 } 578 579delay(100); 580digitalWrite(DIR_F, HIGH); // 581 for(int i = 0; i < Fpasos2; i++){ //45 grados= 25x16 pasos para motor de 1.8 grados de angulo de paso 582 digitalWrite(STEP_F, HIGH); 583 delayMicroseconds(tiempo_stepF); 584 digitalWrite(STEP_F, LOW); 585 delayMicroseconds(tiempo_stepF); 586 } 587 588 589 590 delay(espera); // demora de 2 segundos 591 592} 593 594 595void back()// mueve el cubo back 596 597{ 598Serial.println("B,"); 599 600 601 602rinv_l(); 603rinv_l(); 604delay(100); 605front(); 606delay(100); 607rinv_l(); 608rinv_l(); 609delay(espera); 610 611} 612 613 614 615void back_inv()// mueve el cubo back Inv 616{ 617 618 619Serial.println("B',"); 620 621 622rinv_l(); 623rinv_l(); 624delay(100); 625front_inv(); 626delay(100); 627rinv_l(); 628rinv_l(); 629delay(espera); 630 631 632} 633 634 635 636////////PSEUDO L & R PARA MOVIMIENTOS EN TANDEM /// 637 638 639 640void rinv_l()// mueve el cubo RIGHT 641{ 642 643 644Serial.println("R'+L,"); 645 646 647 648digitalWrite(DIR_R, HIGH); 649digitalWrite(DIR_L,HIGH); 650// giro en sentido CW 651 for(int i = 0; i < pasos; i++){ //90 grados= 12 pasos para motor de 7.5 grados de angulo de paso 652 digitalWrite(STEP_R, HIGH); // nivel alto 653 digitalWrite(STEP_L,HIGH); 654 delayMicroseconds(tiempo_step); 655 delayMicroseconds(tiempo_step);// por 1 mseg 656 digitalWrite(STEP_R, LOW); 657 digitalWrite(STEP_L,LOW);// nivel bajo 658 delayMicroseconds(tiempo_step); // por 1 mseg 659 delayMicroseconds(tiempo_step); 660 } 661 delay(esperaT); 662 663} 664 665 666 667void r_linv()// mueve el cubo Right 668{ 669 670 671Serial.println("R+L',"); 672 673 674digitalWrite(DIR_R, LOW); 675digitalWrite(DIR_L,LOW); 676// giro en sentido NCW 677 for(int i = 0; i < pasos; i++){ //90 grados= xx pasos para motor de 7yy grados de angulo de paso 678 digitalWrite(STEP_R, HIGH); 679 digitalWrite(STEP_L,HIGH); 680 delayMicroseconds(tiempo_step); 681 delayMicroseconds(tiempo_step); 682 digitalWrite(STEP_R, LOW); 683 digitalWrite(STEP_L,LOW); 684 delayMicroseconds(tiempo_step); 685 delayMicroseconds(tiempo_step); 686 } 687 delay(esperaT); // demora de x segundos 688 689 690} 691 692 693////////////MOVIMIENTO FINAL DEL CUBO YA RESUELTO////////// 694 695void show_off_cube()//muestra todo el cubo al terminar de resolverlo 696{ 697 Serial.println("Cubo resuelto hemos finalizado");}
Arduino Code
arduino
Receive from Python the solution and run the moves
1 2/* 3 * by hernando Bolaños 4 * 5 * Piece of code from, Matt2Yu, VER instructables 6*/ 7 8 9 10////////////////////////////////////////////////////////////////////////////////////////////////////// 11////WARNING: PROTOTYPE BASED ON CUBESPINNER //// 12///////////////////////////////////////////////////////////////////////////////////////////////////// 13 14 15#define STEP_L 4 // pin STEP de A4988 a pin 4 PWM- manejando la cara down del cubo 16#define DIR_L 5 // pin DIR de A4988 a pin 5 PWM-manejandola cara down del cubo 17#define STEP_R 6 // pin STEP de A4988 a pin 4 PWM-manejando la cara right del cubo 18#define DIR_R 7 // pin DIR de A4988 a pin 5 PWM-manejando la cara righ delcubo 19 20#define STEP_F 8 // pin STEP de A4988 a pin 4- manejando la cara "up" del cubo 21#define DIR_F 9 // pin DIR de A4988 a pin 5 -manejandola cara "up" del cubo 22 23 24 25 26int pasos = 200/4; // LATERALES pasos 90 grados con motor Hanpose 17HS3430 : 1.8 grados por paso en condicion Full step- Se probo comportamiento en otras configuraciones de pasos 27int Fpasos1=274/4; //FRENTE Pasos para angulo de front avanzar la cara 28int Fpasos2=74/4; //FRENTE Pasos para angulo de front quedar en posicion esperando nuevo movimiento 29int Fpasos3=268/4; //FRENTE Pasos para angulo de front inv quedar en posicion esperando nuevo movimiento-front inv 30int Fpasos4=70/4; //FRENTE Pasos para angulo de front inv quedar en posicion esperando nuevo movimiento-front inv 31int pasosr=3*pasos; 32String kociemba_sol = ""; 33 34 35int tiempo_step= 600; //microseconds -segun DS minimo tiempo permitido del step de motores 1 microsegundo 36int tiempo_stepF= 1400; //microseconds- tiempo para usar en el frente con los demas andando en tiempo_step 37 38int espera=200; //tiempo de espera despues de un movimiento 39 40int esperaT=50; 41 42void setup() 43{ 44 45 pinMode(STEP_L, OUTPUT); // pin 4 como salida 46 pinMode(DIR_L, OUTPUT); // pin 5 como salida 47 48 49 pinMode(STEP_R, OUTPUT); // pin 6 como salida 50 pinMode(DIR_R, OUTPUT); // pin 7 como salida 51 52 53 pinMode(STEP_F, OUTPUT); // pin 8 como salida 54 pinMode(DIR_F, OUTPUT); // pin 9 como salida 55 56delay(7000); 57 58 59 Serial.begin(9600); 60 61 62 while (! Serial); // Wait untilSerial is ready 63 //assign_to_current(yellow_side); 64 //print_cube(current_side); 65 66} 67 68void loop() 69{ 70 71//recibir la solucion de kociemba por puerto serial 72 73//accept_string(); 74 75 //calentando 5 segundos 76 77Serial.println("Calentando para fotos: volvera a la posicion inicial"); 78 79 80//right(); 81//right_inv(); 82//front(); 83//front_inv(); 84//left(); 85//left_inv(); 86 87delay(2000); 88 89 90Serial.println("Arduino dice:Inicia a correr la solucion:"); 91 92 93 run_kociemba(); //corre el string recibido 94 95 Serial.println("Arduino dice: Finaliza tiempo solucion"); 96 97//mostrar el cubo resuelto 98 99show_off_cube(); 100 101 102 Serial.println("Arduino dice:Finalizado enviar nueva solucion de Kociemba"); 103 104 while(true){} 105} 106 107 108void accept_string() ////Se comunica el Arduino con el PC le confirma que esta listo para recibir la solucion en un STRING-la recibe///// 109{ 110 char ready_signal = 'ready'; 111 char received_signal = 'received'; 112 113 for (int piece_num = 0; piece_num <5; piece_num++) 114 { 115 // send ready signal 116 Serial.println(ready_signal); 117 delay(100); 118 } 119 // receive string 120 while(kociemba_sol == "") 121 { 122 char character; 123 while(Serial.available()) 124 { 125 character = Serial.read(); 126 kociemba_sol.concat(character); 127 } 128 } 129 delay(10); 130 Serial.print("String Aceptado: "); 131 Serial.print(kociemba_sol); 132 133 // Se envia confirmacion de recibido al PC con el STRING para reconfirmar 134 Serial.println("arduino dice:"); 135 Serial.println(received_signal); 136 Serial.println(kociemba_sol); 137 delay(10); 138} 139 140 141 142//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 143////Aqui se recibe de python la solucion de kociemba y se convierte en movimientos de los stepper motors"/////// 144//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 145 146void run_kociemba(){ 147 148//steppers en posicion inicial- home 149 150 151 152 153kociemba_sol="U B U' RR D L' D F' L U F LL U LL BB U' BB U' FF RR LL"; 154 155//Solved from Python for test 156 157//"U B U' RR D L' D F' L U F LL U LL BB U' BB U' FF RR LL"; 158 159//"L' U B' DD L DD F' R D R L' UU FF LL BB RR U RR LL FF D"; 160 161//"RR FF U' L UU BB D B' D R' F U RR U FF U' LL BB RR LL"; 162 163//"R F' B' L' U D' BB R' DD R' F' BB LL FF DD BB U BB RR U DD"; 164 165//"FF B' UU RR UU B D' R' F' L' U' BB UU LL D' FF U' FF BB D'"; 166 167 168 169//"D R FF BB U RR LL B' R D F LL BB LL DD FF D FF BB LL D"; 170//"R D' LL BB U F BB U F U RR U LL FF U' FF UU D' RR": 171 172//" FFFFBRRRRRRRR'R'R' RRRRLLLLLLLL'L'"; 173 174//kociemba_sol= "F'F'F'F'F'FFFFFFFFFFFFFF"; 175 176//kociemba_sol="U L' U DD B DD FF B' L' U' B' U' LL U LL U' RR UU RR BB U'"; 177 178//"RR U RR B' U F' D BB U' B L' DD RR UU D FF D LL U' FF BB"; 179 180 181//"U BB L U' F' L' B UU R' D' B' D RR U DD BB RR D LL FF D"; 182 183//"U F' BB U' F UU F R' U' LL F' L U RR U FF RR UU RR BB DD RR"; 184 185//"U R BB DD F' U' F' R F' B' U B DD RR FF U' RR U' BB DD RR FF"; 186 187 188//"FF UU F LL D BB U' RR F' R' U D BB D FF LL D' RR UU LL"; 189 190//"UU D' BB DD F' R L F' BB U' L' D' BB U BB LL U FF LL BB UU"; 191 192//"U R UU B U' F' U FF BB RR U L U DD LL UU RR D' FF RR D LL"; 193 194//"D' RR DD B' RR L' FF D' FF R' D FF RR FF LL BB DD BB D BB"; 195 196//"R' D' R' D' F U R BB D' FF R' D FF RR FF LL BB DD BB D BB"; 197 198//"F R F L B' RR F' LL D' F L FF UU LL D' LL BB UU FF"; 199 200//"B' D' L' U F RR LL F L' F' U' RR U' FF RR LL FF DD FF U'"; 201 202//"F' RR U L' U F' D' RR U' DD F' U' BB RR FF U LL U' BB LL"; 203//"RRRRR'RFBLlU'RLFD'F L BB U RR FF UU LL BB RR DD RR"; 204 205 206// Length (with one extra character for the null terminator) 207 208int str_len = kociemba_sol.length() + 1; 209 210 211Serial.println("Arduino dice: Caracteres:"); 212Serial.println((str_len-1)); 213 214for(int i = 0; i <= (str_len-1); i++){ //recorre 215 216//Serial.print(i); 217 218 219if ((kociemba_sol.charAt(i)) =='R'){ 220 221 222if ((kociemba_sol.charAt(i+1)) == '2') { 223 right(); 224 right();} 225 226 227if ((kociemba_sol.charAt(i+1)) == '\\'') { 228 right_inv();} 229 230if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 231 right();} 232 233} 234 235else { //NO HACER NADA 236 237} 238 239 240 241if ((kociemba_sol.charAt(i)) =='L'){ 242 243 244if ((kociemba_sol.charAt(i+1)) == '2') { 245 left(); 246 left();} 247 248 249if ((kociemba_sol.charAt(i+1)) == '\\'') { 250 left_inv();} 251 252if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 253 left();} 254 255} 256 257else { //NO HACER NADA 258 259} 260 261 262 263if ((kociemba_sol.charAt(i)) =='U'){ 264 265 266if ((kociemba_sol.charAt(i+1)) == '2') { 267 up(); 268 up();} 269 270 271if ((kociemba_sol.charAt(i+1)) == '\\'') { 272 up_inv();} 273 274if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 275 up();} 276 277} 278 279else { //NO HACER NADA 280 281} 282 283 284 285if ((kociemba_sol.charAt(i)) =='D'){ 286 287 288if ((kociemba_sol.charAt(i+1)) == '2') { 289 down(); 290 down();} 291 292 293if ((kociemba_sol.charAt(i+1)) == '\\'') { 294 down_inv();} 295 296if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 297 down();} 298 299} 300 301else { //NO HACER NADA 302 303} 304 305 306 307 308 309if ((kociemba_sol.charAt(i)) == 'F'){ 310 311 312if ((kociemba_sol.charAt(i+1)) == '2') { 313 front(); 314 front();} 315 316 317if ((kociemba_sol.charAt(i+1)) == '\\'') { 318 front_inv();} 319 320if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 321 front();} 322 323} 324 325else { //NO HACER NADA 326 327} 328 329 330 331 332if ((kociemba_sol.charAt(i)) =='B'){ 333 334 335if ((kociemba_sol.charAt(i+1)) == '2') { 336 back(); 337 back();} 338 339 340if ((kociemba_sol.charAt(i+1)) == '\\'') { 341 back_inv();} 342 343if (((kociemba_sol.charAt(i+1))!= '2') and((kociemba_sol.charAt(i+1)) != '\\'')) { 344 back();} 345 346} 347 348else { //NO HACER NADA 349 350} 351 352} 353 354 355 356} 357//////////////////////////////////////////////////////////////////////////// 358/////Rutinas del Cubo- se puede usar asi : YELLOW at FRONT -BLUE at UP////// 359/////////////////////////////////////////////////////////////////////////// 360 361 362 363void right_inv()// movimiento RIGHT inverso del Cubo 364{ 365 366 367 368Serial.println("R',"); 369 370 371 372digitalWrite(DIR_R, LOW); // 373 for(int i = 0; i < pasosr; i++){ //Mueve 3x90 grados 374 digitalWrite(STEP_R, HIGH); // nivel alto 375 delayMicroseconds(tiempo_step); 376 delayMicroseconds(tiempo_step);// por x ms segun 377 digitalWrite(STEP_R, LOW); // nivel bajo variable tiempo_step 378 delayMicroseconds(tiempo_step); // por x ms segun variable tiempo_step 379 delayMicroseconds(tiempo_step); 380 } 381 delay(espera); 382 383} 384 385 386 387void right()// mueve el cubo Right 388{ 389 390 391Serial.println("R,"); 392 393 394digitalWrite(DIR_R, LOW); // 395 for(int i = 0; i < pasos; i++){ // 396 digitalWrite(STEP_R, HIGH); 397 delayMicroseconds(tiempo_step); 398 delayMicroseconds(tiempo_step); 399 digitalWrite(STEP_R, LOW); 400 delayMicroseconds(tiempo_step); 401 delayMicroseconds(tiempo_step); 402 } 403 delay(espera); // demora de x segundos 404 405 406} 407 408 409 410void up()// mueve el cubo UP 411{ 412 413 414Serial.println("U,"); 415 416 417rinv_l(); 418delay(100); 419front(); 420delay(100); 421rinv_l(); 422rinv_l(); 423rinv_l(); 424delay(espera); 425} 426 427 428 429void up_inv()// mueve el cubo UP INV 430{ 431 432 433Serial.println("U',"); 434 435 436rinv_l(); 437delay(100); 438front_inv(); 439delay(100); 440rinv_l(); 441rinv_l(); 442rinv_l(); 443delay(espera); 444 445 } 446 447 448 449 450 451void down()// mueve el cubo UP 452{ 453 454 455Serial.println("D,"); 456 457 458rinv_l(); 459rinv_l(); 460rinv_l(); 461delay(100); 462front(); 463delay(100); 464rinv_l(); 465delay(espera); 466 467 468 469 470} 471 472void down_inv()// mueve el cubo Down_INV 473{ 474 475 476 477Serial.println("D',"); 478 479 480rinv_l(); 481rinv_l(); 482rinv_l(); 483delay(100); 484front_inv(); 485delay(100); 486rinv_l(); 487delay(espera); 488 489} 490 491 492void left()// mueve el cubo LEFT 493 494{ 495 496Serial.println("L,"); 497 498digitalWrite(DIR_L, LOW); // giro en sentido 499 for(int i = 0; i < pasosr; i++){ // 500 digitalWrite(STEP_L, HIGH); // nivel alto 501 delayMicroseconds(tiempo_step); // por x mseg 502 delayMicroseconds(tiempo_step); 503 digitalWrite(STEP_L, LOW); // nivel bajo 504 delayMicroseconds(tiempo_step); // por x mseg 505 delayMicroseconds(tiempo_step); 506 } 507 delay(espera); 508 509 510 511} 512 513 514void left_inv()// mueve el cubo LEFT INV 515{ 516 517 518Serial.println("L',"); 519 520digitalWrite(DIR_L, LOW); // giro en sentido NCW 521 for(int i = 0; i < pasos; i++){ //90 grados= xx pasos para motor de yy grados de angulo de paso 522 digitalWrite(STEP_L, HIGH); 523 delayMicroseconds(tiempo_step); 524 delayMicroseconds(tiempo_step); 525 digitalWrite(STEP_L, LOW); 526 delayMicroseconds(tiempo_step); 527 delayMicroseconds(tiempo_step); 528 529 530 } 531 532 533 delay(espera); // demora de 2 segundos 534} 535 536 537 538void front_inv()// mueve el cubo front_inv 539{ 540Serial.println("F',"); 541 542digitalWrite(DIR_F, HIGH); // giro en sentido CW 543 for(int i = 0; i < Fpasos3; i++){ //135 grados= xx pasos para motor de yy grados de angulo de paso 544 digitalWrite(STEP_F, HIGH); // nivel alto 545 delayMicroseconds(tiempo_stepF); // por 10 mseg 546 digitalWrite(STEP_F, LOW); // nivel bajo 547 delayMicroseconds(tiempo_stepF); // por 10 mseg 548 } 549 550delay(100); 551 552digitalWrite(DIR_F, LOW); 553 for(int i = 0; i < Fpasos4; i++){ //45 grados= 25x16 pasos para motor de 1.8 grados de angulo de paso 554 digitalWrite(STEP_F, HIGH); // nivel alto 555 delayMicroseconds(tiempo_stepF); // por 10 mseg 556 digitalWrite(STEP_F, LOW); // nivel bajo 557 delayMicroseconds(tiempo_stepF); // por 10 mseg 558 } 559 delay(espera); 560 561 562} 563 564 565 566void front()// mueve el cubo front 567{ 568 569Serial.println("F,"); 570 571digitalWrite(DIR_F, LOW); // 572 for(int i = 0; i < Fpasos1; i++){ //135 grados= 70x16 pasos para motor de 1.8 grados de angulo de paso 573 digitalWrite(STEP_F, HIGH); 574 delayMicroseconds(tiempo_stepF); 575 digitalWrite(STEP_F, LOW); 576 delayMicroseconds(tiempo_stepF); 577 } 578 579delay(100); 580digitalWrite(DIR_F, HIGH); // 581 for(int i = 0; i < Fpasos2; i++){ //45 grados= 25x16 pasos para motor de 1.8 grados de angulo de paso 582 digitalWrite(STEP_F, HIGH); 583 delayMicroseconds(tiempo_stepF); 584 digitalWrite(STEP_F, LOW); 585 delayMicroseconds(tiempo_stepF); 586 } 587 588 589 590 delay(espera); // demora de 2 segundos 591 592} 593 594 595void back()// mueve el cubo back 596 597{ 598Serial.println("B,"); 599 600 601 602rinv_l(); 603rinv_l(); 604delay(100); 605front(); 606delay(100); 607rinv_l(); 608rinv_l(); 609delay(espera); 610 611} 612 613 614 615void back_inv()// mueve el cubo back Inv 616{ 617 618 619Serial.println("B',"); 620 621 622rinv_l(); 623rinv_l(); 624delay(100); 625front_inv(); 626delay(100); 627rinv_l(); 628rinv_l(); 629delay(espera); 630 631 632} 633 634 635 636////////PSEUDO L & R PARA MOVIMIENTOS EN TANDEM /// 637 638 639 640void rinv_l()// mueve el cubo RIGHT 641{ 642 643 644Serial.println("R'+L,"); 645 646 647 648digitalWrite(DIR_R, HIGH); 649digitalWrite(DIR_L,HIGH); 650// giro en sentido CW 651 for(int i = 0; i < pasos; i++){ //90 grados= 12 pasos para motor de 7.5 grados de angulo de paso 652 digitalWrite(STEP_R, HIGH); // nivel alto 653 digitalWrite(STEP_L,HIGH); 654 delayMicroseconds(tiempo_step); 655 delayMicroseconds(tiempo_step);// por 1 mseg 656 digitalWrite(STEP_R, LOW); 657 digitalWrite(STEP_L,LOW);// nivel bajo 658 delayMicroseconds(tiempo_step); // por 1 mseg 659 delayMicroseconds(tiempo_step); 660 } 661 delay(esperaT); 662 663} 664 665 666 667void r_linv()// mueve el cubo Right 668{ 669 670 671Serial.println("R+L',"); 672 673 674digitalWrite(DIR_R, LOW); 675digitalWrite(DIR_L,LOW); 676// giro en sentido NCW 677 for(int i = 0; i < pasos; i++){ //90 grados= xx pasos para motor de 7yy grados de angulo de paso 678 digitalWrite(STEP_R, HIGH); 679 digitalWrite(STEP_L,HIGH); 680 delayMicroseconds(tiempo_step); 681 delayMicroseconds(tiempo_step); 682 digitalWrite(STEP_R, LOW); 683 digitalWrite(STEP_L,LOW); 684 delayMicroseconds(tiempo_step); 685 delayMicroseconds(tiempo_step); 686 } 687 delay(esperaT); // demora de x segundos 688 689 690} 691 692 693////////////MOVIMIENTO FINAL DEL CUBO YA RESUELTO////////// 694 695void show_off_cube()//muestra todo el cubo al terminar de resolverlo 696{ 697 Serial.println("Cubo resuelto hemos finalizado");}
Downloadable files
skecth_79AeZAyw6s.jpg
Circuit Diagram
skecth_79AeZAyw6s.jpg
Comments
Only logged in users can leave comments
hbolanos2001
0 Followers
•0 Projects
Table of contents
Intro
8
0