TinyG2 – make from source for the Arduino Due

We’re going to build TinyG2 Core on a Ubuntu machine. First of all install:

sudo apt-get install git git-core make bossa-cli
sudo apt-get install libstdc++6:i386

Clone the EDGE branch of the repository on Github. Modifier recursive is added because we load sub modules:

git clone -b edge https://github.com/synthetos/g2.git --recursive

If you want to use more than four motors / stepper drivers, following changes are needed. First navigate to g2/g2core/board/ArduinoDue and modify the file board_stepper.cpp. You see that I uncommented motor_5 and added motor_5 to the Motors array. So depending on how many motors you want to use… uncomment the lines and add them to the array:

StepDirStepper<
    Motate::kSocket5_StepPinNumber,
    Motate::kSocket5_DirPinNumber,
    Motate::kSocket5_EnablePinNumber,
    Motate::kSocket5_Microstep_0PinNumber,
    Motate::kSocket5_Microstep_1PinNumber,
    Motate::kSocket5_Microstep_2PinNumber,
    Motate::kSocket5_VrefPinNumber>
  motor_5 {M5_STEP_POLARITY, M5_ENABLE_POLARITY};

// StepDirStepper<
//    Motate::kSocket6_StepPinNumber,
//    Motate::kSocket6_DirPinNumber,
//    Motate::kSocket6_EnablePinNumber,
//    Motate::kSocket6_Microstep_0PinNumber,
//    Motate::kSocket6_Microstep_1PinNumber,
//    Motate::kSocket6_Microstep_2PinNumber,
//    Motate::kSocket6_VrefPinNumber>
//  motor_6 {M6_STEP_POLARITY, M6_ENABLE_POLARITY};

Stepper* Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4, &motor_5};

Next open g2/g2core/board/ArduinoDue/board_stepper.h and uncomment the motors you need. In my example, motor_5:

extern StepDirStepper<
    Motate::kSocket5_StepPinNumber,
    Motate::kSocket5_DirPinNumber,
    Motate::kSocket5_EnablePinNumber,
    Motate::kSocket5_Microstep_0PinNumber,
    Motate::kSocket5_Microstep_1PinNumber,
    Motate::kSocket5_Microstep_2PinNumber,
    Motate::kSocket5_VrefPinNumber> motor_5;

Now open g2/g2core/board/ArduinoDue/hardware.h and change the MOTORS channels to the number of motors you’ll use. Again, five for me!

/***** Motors & PWM channels supported by this hardware *****/
// These must be defines (not enums) so expressions like this:
//  #if (MOTORS >= 6)  will work

#define MOTORS 5                    // number of motors supported the hardware
#define PWMS 2                      // number of PWM channels supported the hardware

Let’s add a custom config where we’ll define motor variables and machine settings. Open the g2/g2core/boards.mk file and add a new ifeq statement:

ifeq ("$(CONFIG)","myconfig")
    ifeq ("$(BOARD)","NONE")
        BOARD=gShield
    endif
    SETTINGS_FILE="settings_myconfig.h"
endif

Of course we need to add this file to the g2/g2core/settings/ directory. What you set in this file really depends on your machine. Read the official documentation carefully what to set here. But what’s really important to make your steppers work; add them in the settings_myconfig.h:

#define M5_MOTOR_MAP                AXIS_Z
#define M5_STEP_ANGLE               1.8
#define M5_TRAVEL_PER_REV           1.25
#define M5_MICROSTEPS               8
#define M5_POLARITY                 0
#define M5_POWER_MODE               MOTOR_POWER_MODE
#define M5_POWER_LEVEL              0.750

In my example, I defined Motor 5 for the Z axis. Now run make in g2/g2core/ directory:

make CONFIG=myconfig BOARD=gShield

The BOARD parameter should be optional because we set in the boards.mk file that when myconfig is choosen and no BOARD parameter is set, make should use the gShield as default.

When this is done, connect your Arduino Due via the programming USB port and flash:

stty -F /dev/ttyACM0 1200 hup
stty -F /dev/ttyACM0 9600

bossac --port=ttyACM0  -U true -e -w -v -i -b -R g2/g2core/bin/myconfig-gShield/g2core.bin

That should take a minute. After flashing is done, you will see a slow blinking orange led. This is the TinyG “heartbeat” so everything went well!

Share

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *