Firmware

The firmware was written in the Arduino IDE. The firmware receives messages from the software and controls the five stepper motors, five stepper drivers, four limit switches, and the solenoid valve.

When the firmware receives a message, it is usually in this format:

  • G#
  • M#

The parser reads the number after the letter ‘G’ or ‘M’ in order to determine which function to run. The functions were written in a switch-case format, where the case number is synonymous with the number for the GCode command, which is the number right after the letter ‘G’ or ‘M’.

The GCode that is sent is in terms of millimeters, which we convert to degrees based on our calibration of the stepper motors. We also edited the Stepper Driver library to run five stepper motors simultaneously since it could only run three at the same time previously.

Since our GCode commands are in terms of absolute coordinates, we created global variables to keep track of the motors’ positions. The GCode contains basic functions that enable and disable motors, move motors, set motor speeds, and switch the solenoid on and off.

G-Code commands

G-Code Description Python Command Arduino Command
G1 X_Y_Z_T_ Move to a given position on the global axis system with X,Y,Z set in mm and tilt set in degrees. move_controller(xpos, ypos, zpos, angle) move_motors(X,Y,Z,T);
G27 "Zero" and recalibrate each axis by moving all the motors to hit the limit switches go_home() go_home();
G28 Move to the center of the coffee cup go_cup_orgin() cup_origin();
M6 S_ Pause the machine for a given amount of time in milliseconds delay(ms) wait(S);
M10 Enable Z axis motor enable_Z() enable_Z();
M11 Disable Z axis motor disable_Z() disable_Z();
M12 Enable tilt motor enable_T() enable_T();
M13 Disable tilt motor disable_T() disable_T();
M14 Enable X axis motor enable_X() enable_X();
M15 Disable X axis motor disable_X() disable_X();
M16 Enable Y axis motors enable_Y() enable_Y();
M17 Disable Y axis motors disable_Y() disable_Y();
M220 S_ Change speed of X and Y axis motors set_speed(speed) set_speed(S);;
M221 S_ Change speed of tilt motor set_speed_T(speed) set_speed_T(S);
M222 S_ Change speed of z axis motor set_speed_Z(speed) set_speed_Z(S);
M380 Enable the solenoid(valve) enabling liquid flow enable_solenoid() enable_solenoid();
M81 Disable the solenoid(valve) disabling liquid flow disable_solenoid() disable_solenoid();
M100 A list of G-Code commands printed in the serial terminal when the program starts up help();

Dependencies

The firmware requires Arduino IDE to be downloaded as well as the StepperDriver library including modifications.

Files Changed

  • MultiDriver.cpp
  • MultiDriver.h
  • SyncDriver.cpp
  • SyncDriver.h

The files should be changed in the following file system within the Arduino libraries as shown below

Moreover, the firmware is deeply dependent on the electrical components and setups found in the electrical section. The firmware also communicates with the software through G-Code found in the table above which is further explained in the software section.