dev255
Published © GPL3+

Arduino CNC Mill Control Using ODrive Brushless DC Motors

CNC milling machine conversion using an Arduino Mega 2560 to control brushless DC motors powered by the ODrive motor controller.

AdvancedWork in progress6,138
Arduino CNC Mill Control Using ODrive Brushless DC Motors

Things used in this project

Hardware components

ODrive Brushless DC Motor Controller
×1
Arduino Mega 2560
Arduino Mega 2560
×1
ODrive Brushless DC Dual Shaft Motor - D5065 270KV
×1
AMT102-V 8192 CPR Rotary Encoder
×1
Displaytech 204A - 4 x 20 Line Blue & White LCD Display
×1
Adafruit Mini 8x8 LED Matrix w/I2C Backpack - Ultra Bright White
×1
Keypad, 3x4 Plastic - MCAK304NBWB
×1
AD-13 Advanced Solderless Breadboard
×1

Software apps and online services

Fusion
Autodesk Fusion
Alibre Design Professional

Hand tools and fabrication machines

Axminter Sieg X1 Milling Machine

Story

Read more

Schematics

Simple Cirduit Diagram

This diagram shows the joypad and Arduino Mega 2560 connections in their simplest form.

Code

Simple Arduino Joypad test Sketch

C/C++
Please take a look at my video here for in-depth details: https://youtu.be/yI8ZIQ0cC4I
/*
Neil Devonshire - Dev255
YouTube Dev255
www.dev255.co.uk

Joypad test sketch to ensure all the contols work across all range of motion
comments added to help describe the funcion of each statement (if requied)


    Copyright (C) <2020>  <Neil Devonshire>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
*/

int topPotPin = A0;                         // The Joypads top variable resistor (Potentiometer(Pot for short)) is connected to Arduino pin A0
int topPotVal = 0;                          // This sets the value asociated with the name 'topPotVal' to 0
int xAxisPin = A1;                          // The Joypads X-Axis Pot is connected to Arduino pin A1
int xAxisVal = 0;
int yAxisPin = A2;
int yAxisVal = 0;
int zAxisPin = A3;
int zAxisVal = 0;
int topSwtchPin = 46;                       // The Joypads top switch is connected to Arduino pin 46
int topSwtchVal = 0;
int redLedPin = 50;                         // The Joypads Red LED is connected to Arduino pin 50
int yellowLedPin = 48;                      // The Joypads Red LED is connected to Arduino pin 48

void setup(void) {                          // Setup will only run once, you don't have to include 'void' in the (), I just include it for completeness
  pinMode(topSwtchPin, INPUT);              // Sets 'topSwitchPin' (connection 46 on Arduino board) to a Digital Input
  pinMode(topSwtchPin, INPUT_PULLUP);       //  Turns on the pull-up resistor for pin 46 (keeps the pin near Vcc(5V)when nothing is connected or switch is off)
  pinMode(redLedPin, OUTPUT);               // Sets 'redLedPin' (connection 50 on Arduino board) to a Digital Output
  pinMode(yellowLedPin, OUTPUT);            // Sets 'yellowLedPin' (connection 50 on Arduino board) to a Digital Output

  Serial.begin(115200);                     //  Starts serial communication at 115200bps (ensure serial monitor is at 115200 or ou will get garbled characters)
  while (!Serial) ;                         //  Waits until the serial port is communicating (while !(not) Serial)
}

void loop(void){                            // Runs continually in a loop, you don't have to include 'void' in the (), I just include it for completeness

  topPotVal = analogRead(topPotPin);        //  Take the current position of the top potentiometer and stick it in 'topPotVal'
  xAxisVal = analogRead(xAxisPin);          //  Take the current position of the x-Axis pot and stick it in 'xAxisVal'
  yAxisVal = analogRead(yAxisPin);          //  Take the current position of the y-Axis pot and stick it in 'yAxisVal'
  zAxisVal = analogRead(zAxisPin);          //  Take the current position of the z-Axis pot and stick it in 'zAxisVal'
  topSwtchVal = digitalRead(topSwtchPin);   //  Take the On/Off state of the top switch and stick it in 'topSwtchVal'

  Serial.print("X-Val = ");                 // Send "X-Val = " to display on the serial monitor
  Serial.print(xAxisVal);                   // Send the value of 'xAxisVal' to display on the serial monitor (i.e. 1024 if 5v on pin A1)
  Serial.print("  Y-Val = ");               // Send "Y-Val = " to display on the serial monitor
  Serial.print(yAxisVal);                   // Send the value of 'yAxisVal' to display on the serial monitor (i.e. 512 if 2.5v on pin A2)
  Serial.print("  Z-Val = ");               // Send "Z-Val = " to display on the serial monitor
  Serial.print(zAxisVal);                   // Send the value of 'zAxisVal' to display on the serial monitor (i.e. 256 if 1.75v on pin A3)
  Serial.print("  Top Val = ");             // Send "Top Val = " to display on the serial monitor
  Serial.println(topPotVal);                // Send the value of 'topPotVal' to display on the serial monitor (i.e. 0 if 0v on pin A0)

  if (topSwtchVal == 0){                    // If the 'topSwtchVal' value is a 0 (notice == and not =), then flash the Joypads LEDs
    
    digitalWrite(yellowLedPin, HIGH);       // Turn the Yellow LED on (pin 48 goes High or 5v). Note: a series resistor of around 470ohms should be used with standard LED
    digitalWrite(redLedPin, LOW);           // Turn the Red LED off (pin 50 goes Low or 0v).
    delay(500);                             //  Pause the program for 0.5 seconds (500ms)
    digitalWrite(redLedPin, HIGH);          // Turn the Red LED on (pin 50 goes High or 5v).
    delay(500);                             //  Pause the program for 0.5 seconds (500ms)
    digitalWrite(yellowLedPin, LOW);        // Turn the Yellow LED off (pin 48 goes Low or 0v).
    digitalWrite(redLedPin, LOW);           // Turn the Red LED off (pin 50 goes Low or 0v).
    delay(500);                             //  Pause the program for 0.5 seconds (500ms)
    digitalWrite(yellowLedPin, HIGH);       // Turn the Yellow LED on (pin 48 goes High or 5v).
    digitalWrite(redLedPin, HIGH);          // Turn the Red LED on (pin 50 goes High or 5v).
    delay(500);                             //  Pause the program for 0.5 seconds (500ms)
    
  }                                         //  End of IF block of code
  
}                                           //  End of Loop (this is where it returns to the begining of the Loop to repeat)

Credits

dev255
0 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.