En este proyecto intentaremos unificar dos firmware de Cura y GRBL en una misma placa si hay posibilidad de hacerlo, de no funcionar lo haremos en dos placas independientes, lo primero que tenemos que hacer es estudiar los pines de donde van conectados los driver del motor PAP bipolar.
In this project we will try to unify two firmware Cura and GRBL on one plate if doing so, we will not run on two separate boards, the first thing you have to do is study the pins are connected where the engine driver PAP bipolar.
Aquí tenemos la placa de la fresadora como van conectados los pines con el drivers de los motores:
Here is the router board and the pins are connected to the motor drivers:
Si abrimos el el archivo "config.h" del firmware GRBL que se puede descargar a través del enlace de abajo por medio de un editor de texto o el mismo compilador PICC vemos la asignación de los pines al cual corresponde a la imagen de la placa.
If we open the "config.h" GRBL firmware file that can be downloaded via the link below using a text editor or the same compiler PICC see the pin assignment which corresponds to the image of the board .
Como el firmware se puede compilar tanto Arduino UNO como Arduino Mega sirve para las dos placas, en la prueba que hice la utilicé con Arduino UNO sin ningún problema, la cual vamos a estudiar la distribución de los pines para el Software CURA que se utilizará con Arduino Mega.
Because the firmware can be compiled both Arduino UNO and Arduino Mega is for the two boards in the test I did with Arduino UNO used it without any problems, which will study the pinouts for the CURA Software to be used with Arduino Mega.
Para ellos abrimos el archivo "pins.h" del Firmware Sprinter de la impresora 3D la que manejará el software CURA a través del compilador Arduino 1.0.5-r2 e iremos buscando que tipo de motherboard que es 33 que corresponde al Arduino Mega que tiene el micro atmega 2560:
For them we opened the "pins.h" Sprinter firmware file 3D printer that will handle the software through CURA Arduino 1.0.5-r2 compiler and we go looking for that type of motherboard is 33 which corresponds to the Arduino Mega has the micro atmega 2560:
Viendo la distribución de los pines del firmware "Sprinter" la podemos modificar a la de GRBL y así podrá compartir los dos firmware para una misma placa de Arduino Mega.
Pero me di cuenta que en el esquema del circuito no coincide el número de patillaje así que me puse manos a la obra.
Al compilar el firmware de "Sprinter" sale una serie de errores la cual fue subsanada a través de una página web como dice aquí:
Viewing pinouts firmware "Sprinter" we can change that of GRBL and so both can share the same firmware for Arduino Mega board.
But I realized that in the circuit diagram does not match the number of pinout so I set to work.
When you compile the firmware "Sprinter" comes a series of errors which were corrected through a web page as it says here:
En la pestaña sd2card.cpp, dice asi:
"HIGH" was not declared in this scope
y me ilumina la siguiente linea:
digitalWrite(chipSelectPin_, HIGH);
Este es el codigo completo del intento de compilación:
Sd2Card.cpp:20:22: error: WProgram.h: No such file or directory
Sd2Card.cpp: In member function 'void Sd2Card::chipSelectHigh()':
Sd2Card.cpp:145: error: 'HIGH' was not declared in this scope
Sd2Card.cpp:145: error: 'digitalWrite' was not declared in this scope
Sd2Card.cpp: In member function 'void Sd2Card::chipSelectLow()':
Sd2Card.cpp:149: error: 'LOW' was not declared in this scope
Sd2Card.cpp:149: error: 'digitalWrite' was not declared in this scope
Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t)':
Sd2Card.cpp:216: error: 'millis' was not declared in this scope
Sd2Card.cpp:220: error: 'OUTPUT' was not declared in this scope
Sd2Card.cpp:220: error: 'pinMode' was not declared in this scope
Sd2Card.cpp:222: error: 'INPUT' was not declared in this scope
Sd2Card.cpp: In member function 'uint8_t Sd2Card::waitNotBusy(uint16_t)':
Sd2Card.cpp:471: error: 'millis' was not declared in this scope
Sd2Card.cpp: In member function 'uint8_t Sd2Card::waitStartBlock()':
Sd2Card.cpp:481: error: 'millis' was not declared in this scope
Estos son los cambios que debe efectuarse:
-En la pestaña Sd2Card.cpp:
donde pone #include < WProgram.h > poner esto --> #include < Arduino.h >
-En la pestaña SdFat.h:donde pone void write(uint8_t b); poner esto --> size_t write(uint8_t b);
-En la pestaña SdFile.cpp:donde pone #include < WProgram.h > poner esto --> #include < Arduino.h >
y donde pone void SdFile::write(uint8_t b) { poner esto --> size_t SdFile::write(uint8_t b) {
-En la pestaña Sprinter.h: donde pone #include < WProgram.h > poner esto --> #include < Arduino.h >
Una vez corregido, la compilación no daba ningún error y proseguimos para hacer una propuesta que me salió de mi cabeza:
Consiste en incorporar un microinterruptor en el cabezal que detecta si es impresora 3D o fresadora que se conectara en en unos de los pines libres del Arduino Mega como se ve en la imagen siguiente:
Once corrected, the compilation does not fail and proceeded to make a proposal that came out of my head:
Is to incorporate a microswitch on the head that detects if 3D printer or router was connected to a pin on the Arduino Mega free as seen in the picture below:
Esto es la propuesta que voy a hacer, y espero que todo funcionará.
This is the proposal that I do, and I hope that everything will work.
CREACIÓN DE UNA LIBRERÍA DE ARDUINO CON Y SIN RETORNO DE VALOR.
CREATING AN ARDUINO LIBRARY WITH AND WITHOUT RETURN VALUE.
Aquí vemos unos ejemplos de encender 3 leds llamando a tres funciones diferentes uno llamado función "ON" que se le asigna un parámetro de tiempo de duración que permanecerá el LED encendido, otra la función "OFF" con su respectivo parámetro del tiempo que permanecerá el LED apagado, y por último la función "VALUE" que contiene dos parámetro, uno el valor de intensidad que va del nivel 0 hasta 255 y otro tiempo de duración.
Here we see some examples of turn 3 leds calling three different functions, one called "ON" function is assigned a duration parameter will remain the LED, the other the "OFF" function with their respective time parameter will remain the LED off, and finally the "VALUE" parameter function containing two, one intensity value ranging from 0 to 255 level and one duration.

En este programa, lo mas importante se le incluye la librería de funciones "·#include <LED.h" que lo vamos a diseñar, que será llamado para que se encienda o se apague los LEDS junto al "#include Arduino", los siguientes código "#define Pinled 13" es para asignar los pines que vamos a utilizar en el arduino en nuestro caso los pines 13, 12, 10; luego crearemos el nombre de la función de cada led nombrando a cada uno con un nombre diferente y el parámetro que le asignaremos el número de pin que trabajaremos el arduino, y por último escribimos el código dentro del bucle infinito"void loop()" las funciones de los tres leds "led2", "led2" y "led 3" que se encenderá y apagará un cierto tiempo:
In this program, the most important is the function library includes " # include <LED.h" who will design, which will be called to turn on or turn off the LED next to the "# include Arduino", the following code "# define Pinled 13" is to assign the pins that we use in our case arduino pins 13, 12, 10; then create the name of the function of each LED naming each one with a different name and the parameter that will assign the number of the arduino pin will work, and finally write the code inside the infinite loop "void loop ()" the functions of the three lEDs "led2", "led2" and "led 3" flashing at a certain time:
En la librería "LED.h" contiene, normalmente, una declaración directa de clases, subrutinas, variables, u otros identificadores que decleraremos las variables como privada o pública, por si unas de las variables trabajará dentro de la función sin que influya en los demás.
In the library "LED.h" normally contains a direct declaration of classes, subroutines, variables, and other identifiers that decleraremos variables as private or public, for if one of the variables work inside or outside the function without influencing in others.
En esta librería "LED.cpp" contiene los códigos donde están las funciones que serán llamado desde el programa principal "LED.ino", a la asignaremos los parámetros de números de pines, duración de encendido y apagado y la intensidad de iluminación, si nos fijamos que los leds esta controlados por el comando "analogWrite()" y no digitalWrite()", que es una salida analógica que variará la intensidad de led desde 0 hasta 255.
In this library "LED.cpp" contains the code where the functions that will be called from the main program "LED.ino" parameters to assign pin numbers, on and off duration and intensity of lighting are, if we notice that the LED is controlled by the "analogWrite ()" no digitalWrite () "command, which is an analog output which varies the intensity of LEDs from 0-255.
Por último aquí vemos una librería que se utiliza el arduino para que se resalte los colores los texto del nombre de las funciones.
Finally here we see the arduino library that is used to color the text of the name of the functions are highlighted.
Ahora probamos a programar una librería que devuelva un valor desde el programa principal como una calculadora, pero de dos formas diferente; a través del Return y otro a través del puntero.
Now try to program a library that returns a value from the main program as a calculator, but two different ways; Return through and another through the pointer.
El programa principal es muy similar a la que hemos hecho antes, salvo que devuelve el valor calculado después de la llamada de la función "mate.suma" "mate.resta" etc..., la tercera función difiere de los demás porque devuelve los valores a través del puntero que, es una variable que contiene la dirección de memoria de un dato o de otra variable que contiene al dato. Para que los parametros sea puntero se le añade "ampersand" a las variables que devolverá el resultado de una función.
The main program is very similar to what we did before, except that the calculated returns after the call of "mate.suma" "mate.resta" etc ... function value, the third function differs from the others because it returns values through the pointer is a variable that contains the memory address of a data element or a variable that contains the data. For the parameters pointer is added "ampersand" variables that will return the result of a function.
Aquí también es parecida al anterior, solo que tiene asterisco en los punteros que devolverá los resultados.
This is also similar to the previous, only has starred in the pointers that return results.
Aquí tenemos el código principal de la librería "calculadora.cpp" si observamos que la función cambia"void" por "int", lo de "void" significa que no devuelve valor mientras "Int" le dice que va a devolver un valor entero después de la operación matemática a través del código "return" y lo transfiere al programa principal calculadora.ino de arduino. Lo del puntero solo hay que añadir un asterisco en la variable que va a devolver el valor después de la operación.
Here is the main code of the library "calculadora.cpp" if we observe that the function changes "void" to "int", what the "void" means that no return value as "Int" says it will return an integer value after the operation through mathematical code "return" and transfers it to the main program calculadora.ino arduino. The pointer just add an asterisk to the variable to return the value after the operation.
Aquí no hace falta entrar el comentario...
There is no need to enter the comment ...
PROBANDO PARA INCORPORAR LAS LIBRERÍA DE LA FRESADORA "GBRL" AL CÓDIGO PRINCIPAL DEL "SPRINTER".
TESTING TO INCLUDE THE LIBRARIES OF THE MILLING "GBRL" TO MAIN CODE "SPRINTER".
Ahora vamos a probar para incorporar la librería de la fresadora al código del la impresora 3D para ver si admiten las funciones ...
Now we will try to incorporate the library of the router to the 3D printer code to see if they support the functions ...
Abrimos el código del firmware "Sprinter" de la impresora 3D...
Open the firmware code "Sprinter" 3D printer ...
Añadimos la librería del firmware de la fresadora "gbr main.h", la compilamos...
Add the library milling "main.h gbr" the firmware, compile ...

!!!ERROR¡¡¡, Vaya por Dios...Ahora que demonios será esta vez, después de comprobar, revisar y consultando con el profesor, nos dimos cuenta que los dos firmware utiliza las dos librerías diferentes de comunicación serial, la del Gbrl que utiliza de la misma librería del compilador del arduino que se llama "HardwareSerial.ccp" y otra que es "serial.cpp" que viene incluido en la librería del "Sprinter" la cual produce múltiple definición, o sea, que hay duplicidades de funciones pero de diferente librería y viendo que los dos son totalmente diferente, la cual no es posible modificar por su kilométricos códigos.
!!! ERROR¡¡¡, Oh dear ... Now who the hell is this time, after checking, review and consultation with the teacher, we realized that the two firmware uses two different libraries of serial communication, the gbrl using the same compiler arduino library called "HardwareSerial.ccp" and another is "serial.cpp" which is included in the library of "Sprinter" which produces multiple definition, that is, there is duplication of functions but different library and seeing that the two are completely different, which can not be changed by their kilometer codes.
A veces es una desesperación...
Sometimes it's a desperation ...
Busqué otra opción recordando en mis tiempo de programador de Visual Basic 6.0, que actualmente es reemplazado por Visual Basic .NET que es una plataforma diferente a la que se programa por clase y es bastante complicado y tedioso que la anterior, consiste solamente en pulsar un botón de cada firmware y se carga automáticamente y al mismo tiempo se abre el programa de cada máquina como se ve la imagen de abajo.
I looked for another option remembering my time programmer Visual Basic 6.0, which is currently replaced by Visual Basic NET is a different platform which is programmed by class and is quite complicated and tedious than the last, consists only of pressing a button on each firmware and loaded automatically while the program opens each machine as the image below looks.
Aquí vemos el código que es bastante simple, que solo se llama un programa "avrdude.exe" que viene incorporado en el Arduino que se carga en la placa a través del comando de MS-DOS "SHELL", que al mismo tiempo este comando también ejecuta todos los programa del sistema operativo WINDOWS.
Here we see the code is pretty simple, only a program called "avrdude.exe" which is built on the Arduino that is loaded into the board through the MS-DOS command "SHELL", at the same time this command program also runs all the WINDOWS operating system .
Aquí vemos cargando el fichero "GBRL to Arduino.hex" a la placa Arduino Mega a través del puerto USB.
Here we see loading the file "GBRLtoArduino.hex" to the Arduino Mega via the USB port.
Aquí vemos también cargando el firmware "Sprinter.hex" a la placa Arduino Mega.
Here we see also loading the firmware "Sprinter.hex" to the Arduino Mega.
Aquí tenemos la imagen en pleno funcionamiento el proceso de carga del programa firmware a la placa Arduino Mega.
Here we have a fully functioning image processing firmware load program to the Arduino Mega.
Ya que hemos solucionado proseguiremos con nuestro trabajo para ver como podemos conectar nuestro Visual basic con un dispositivo que detecte la posición del cabezal, nosotros hemos pensado en incorporar un pequeño microcontrolador Attiny85, que es lo mismo que lleva los Arduino pero que solo tiene 8 patillas, una de las familia enana de los microcontroladores.
As we continue our work solved to see how we can connect our Visual Basic with a device which detects the position of the head, we have thought to incorporate a small microcontroller ATtiny85, which is the same as carrying the Arduino but it only has 8 pins , one of the dwarf family of microcontrollers.
Este es el famoso microcontrolador ATTINY85 de la misma familia que se utiliza los Arduinos, trabaja hasta 20 Mhz , con memoria de 8K, pero como vamos a instalar Bootloader, lo vamos a quitar alrededor de 2K de memoria para poder cargar automáticamente desde la IDE Arduino.
This is the famous ATtiny85 microcontroller of the same family as the Arduino is used, working up to 20 MHz, 8K memory, but as we will install Bootloader, we will remove about 2K of memory to automatically load from the Arduino IDE .
Para cargar el bootloader necesitamos instalar el firmware de precarga "Micronucleus" a través del programador PiCKIT2, si como habéis leído, pensáis que solo sirve para programar los microcontroladores PIC, pero también sirve para la familia AVR-ATMEL, en la imagen de arriba tenéis el esquema de conexionado desde el programador PICKIT 2.
To load the bootloader need to install the firmware preload "Micronucleus" through the developer PICKit2 if, as you read, you think that only serves to program PIC microcontrollers, but also serves the AVR-ATMEL family in the picture above you have the wiring diagram from the PICkit 2 programmer.
En este esquema se conecta para otro tipo de microcontrolador, la enumeración de las patillas son las misma para todos, pero que cambia el orden de patillaje como el microcontrolador attyny2313 de 20 patillas.
In this scheme is connected to other microcontroller, the enumeration of the pins are the same for everyone, but it changes the order of pinout as the attyny2313 20 pin microcontroller.
Ya montado el microcontrolador como se ve en la imagen, mi programador lo hice de manera casera, la cual mas adelante os mandaré el esquema y listado de componentes si os animáis a hacerlo vosotros mismo, me funcionó a la primera sin problemas, lo vamos a cargar con el programa que se puede descargar gratuitamente "AVRDUDESS".
Already mounted the microcontroller as seen in the picture, my programmer I did way home, which later schema and list of components you send if you urge to do you the same, I it worked the first no problems,, we will loaded with the program that can be downloaded free "AVRDUDESS"
Este es el programa que se cargará nuestro firmware, vemos en la persiana de lista de programador "MicroChip´s PICkit2 Programmer", seleccionando tipo de microcontrolador, y una cosa importante es configurar los "fuses", para que pueda trabajar con 4 pines como el reset, para que trabaje cono entrada salida.
This is the program our firmware to be loaded, see the list rollout programmer "MicroChip's PICkit2 Programmer", selecting type of microcontroller, and one important thing is to set the "fuses", so you can work with 4 pins as reset, cone input to work out.
También hay otro procedimiento para programar a través de la placa de Arduino, lo cual necesita descargar un archivo para poder programar para este tipo de microcontrolador, aquí vemos el esquema de diseño, que se colocará directamente a la placa.
There is also another procedure to program through the Arduino board, which need to download a file to program for this type of microcontroller, here we see the outline design, which will be placed directly onto the board.
-
Aquí tenemos el conexionado, lo cual es muy importante colocar el condensador entre reset y masa para poder programar sin problemas.
Here we have the connection, which is very important to place the capacitor between reset and ground to program smoothly.
Y aquí el diseño para poder conectarlo directamente en la placa del Arduino.
And here the design to connect directly to the Arduino board.
Este es resultado del montaje tipo casero listo para programarlo, lo he incluido tiras de pines hembras para poder conectar cables para poder probar su funcionamiento.
This is a result of homemade type assemble ready to program, I have included female pin strips to connect wires to test operation.
Ya programado el firmware "Micronucleus", podemos programar los códigos de Arduino y cargarlos a través de IDE de Arduino especial para el Attiny85, que también hay que montarlo en otra placa para poder conectarlo y programar a través del puerto USB como hace los demás Arduino UNO.
Already programmed firmware "Micronucleus" we can program the codes for Arduino and load through IDE Arduino special for the ATtiny85, which also mount it on another board to connect and programmed through the USB port and does other Arduino UNO.
Estos son los esquemas para el diseño de la placa de prueba a través de USB, que también suministra alimentación y comunicación por USB, fijando los dos diodos ZENER, sirve para limitar la tensión alrededor de 6,8 voltios para evitar el daño de los circuitos, los mismo que resistencia para limitar corrientes.
These are schemes for the design of the test board via USB, which also supplies power and USB communication, setting the two ZENER diode serves to limit the voltage about 6.8 volts to avoid damage circuits , the same resistor to limit current.
Aquí tenemos el resultado del circuito preparado para conectarlo directamente del puerto USB, poniendo también una tira de pines para conectarlo en la protoboard a través de los cable y posteriór comprobación.
En el vídeo de abajo vemos la demostración del funcionamiento de un diodo RGB que se enciende alternativamente.
Here is the result of the circuit prepared to connect directly from the USB port, also putting a strip of pins to plug into the breadboard via cable and subsequent verification.
In the video below we see the demonstration of an RGB LED that lights alternately.
VIDEO OF THE FUNCTIONING WITH LED RGB ATtiny85