-
11Machine Firmware
The printer controller (Arduino MEGA 2560) is running Marlin Firmware which needs only the configuration for your machine and one change in the Configuration_adv.h to be able to send I2c data via gcode:
#define EXPERIMENTAL_I2CBUS
-
12Arduino Sketch
Here is the sketch for the Arduino Nano for receiving i2c data and switching the piezo discs:
//define variables #include <Wire.h> #define tool_0 5 #define tool_1 4 #define tool_2 3 #define tool_3 2 boolean shoot_0 = false; boolean shoot_1 = false; boolean shoot_2 = false; boolean shoot_3 = false; boolean auto_shoot_0 = false; boolean auto_shoot_1 = false; boolean auto_shoot_2 = false; boolean auto_shoot_3 = false; enum Auto_Drop {on_0, off_0}; Auto_Drop auto_drop; enum Drop_On_Demand {idle_1, on_1, off_1}; Drop_On_Demand drop_on_demand; unsigned long saved_time_0; unsigned long saved_time_1; byte i2c_message; //start serial, start i2c, set Arduino pins to output void setup() { Serial.begin(9600); Wire.begin(9); Wire.onReceive(receiveEvent); pinMode(tool_0, OUTPUT); pinMode(tool_1, OUTPUT); pinMode(tool_2, OUTPUT); pinMode(tool_3, OUTPUT); } //read i2c message //check which tool bit is set void receiveEvent() { while (Wire.available()) { i2c_message = Wire.read(); } if (bitRead(i2c_message, 0) == 1 ) { drop_on_demand = on_1; shoot_0 = true; } if (bitRead(i2c_message, 1) == 1 ) { drop_on_demand = on_1; shoot_1 = true; } if (bitRead(i2c_message, 2) == 1 ) { drop_on_demand = on_1; shoot_2 = true; } if (bitRead(i2c_message, 3) == 1 ) { drop_on_demand = on_1; shoot_3 = true; } if (bitRead(i2c_message, 4) == 1 ) { auto_shoot_0 = true; } if (bitRead(i2c_message, 5) == 1 ) { auto_shoot_1 = true; } if (bitRead(i2c_message, 6) == 1 ) { auto_shoot_2 = true; } if (bitRead(i2c_message, 7) == 1 ) { auto_shoot_3 = true; } if (bitRead(i2c_message, 4) == 0 ) { auto_shoot_0 = false; } if (bitRead(i2c_message, 5) == 0 ) { auto_shoot_1 = false; } if (bitRead(i2c_message, 6) == 0 ) { auto_shoot_2 = false; } if (bitRead(i2c_message, 7) == 0 ) { auto_shoot_3 = false; } } void loop() { //eject drops at set frequency switch (auto_drop) { case on_0: if (millis() - saved_time_0 < 50) { if (auto_shoot_0 == true) { digitalWrite(tool_0, HIGH); } if (auto_shoot_1 == true) { digitalWrite(tool_1, HIGH); } if (auto_shoot_2 == true) { digitalWrite(tool_2, HIGH); } if (auto_shoot_3 == true) { digitalWrite(tool_3, HIGH); } } else { auto_drop = off_0; } break; case off_0: if (millis() - saved_time_0 < 100) { if (auto_shoot_0 == true) { digitalWrite(tool_0, LOW); } if (auto_shoot_1 == true) { digitalWrite(tool_1, LOW); } if (auto_shoot_2 == true) { digitalWrite(tool_2, LOW); } if (auto_shoot_3 == true) { digitalWrite(tool_3, LOW); } } else { auto_drop = on_0; saved_time_0 = millis(); } break; } // eject drop on demand switch (drop_on_demand) { case idle_1: saved_time_1 = millis(); shoot_0 = false; shoot_1 = false; shoot_2 = false; shoot_3 = false; break; case on_1: if (millis() - saved_time_1 < 5) { if (shoot_0 == true) { digitalWrite(tool_0, HIGH); } if (shoot_1 == true) { digitalWrite(tool_1, HIGH); } if (shoot_2 == true) { digitalWrite(tool_2, HIGH); } if (shoot_3 == true) { digitalWrite(tool_3, HIGH); } } else { drop_on_demand = off_1; } break; case off_1: if (millis() - saved_time_1 < 50) { if (shoot_0 == true) { digitalWrite(tool_0, LOW); } if (shoot_1 == true) { digitalWrite(tool_1, LOW); } if (shoot_2 == true) { digitalWrite(tool_2, LOW); } if (shoot_3 == true) { digitalWrite(tool_3, LOW); } } else { drop_on_demand = idle_1; } break; } }
-
13Startup
After you have done all these steps the machine should be ready to use. Fill ink (I used water mixed with cheap ink) into the ink containers and flush the tubes by using a syringe and drawing the ink to the printhead.
Make sure everything is seal, because if ink leaks on the backside of the piezo discs it will short out and damage them. If everything is OK you can turn on the printer and connect the printer controller over USB with your PC.
Start your favorite GCODE sender or Slicer Software and connect to your printer.
-
14GCODE Commands
The printer can be controlled by sending values via i2c.
Each set bit represents a printer command like:
0 - everything off 1 - single drop printhead 1 2 - single drop printhead 2 4 - single drop printhead 3 8 - single drop printhead 4 16 - drops at fixed frequency printhead 1 32 - drops at fixed frequency printhead 2 64 - drops at fixed frequency printhead 3 128 - drops at fixed frequency printhead 4 You can change the frequency in the Arduino Sketch
The values can also be added to each other to eject drops from multiple printheads at once like if you send value 15 printhead 1, 2, 3 and 4 eject a drop.
For sending the values you can use the M260 command like:
M260 A9 M260 B1 M260 S1 or M260 A9 M260 B16 M260 S1 or M260 A9 M260 B0 M260 S1
If you are using a CAM software for printing along paths you can set the following command for start ejecting drops:
M260 A9 M260 B16 M260 S1
And set the following command for stop ejecting drops:
M260 A9 M260 B0 M260 S1
With that, I think everything about the project is said. If you have any questions you can ask me. Thank you very much for the interest in my project :)
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.