Smoothie firmware for mbed

4 October 2012

As per my ScottCNC page, I am planning to use the Smoothie firmware running on an mbed to convert G-code movement and tooling instructions into step and direction signals for the stepper motors. As a start, I decided to get Smoothie running on my mbed without any connections to any motors (or anything else). There were only a few steps needed to get Smoothie up and running:

0. I used Windows but the instructions should be similar or identical for Mac and Linux users.

1. I was advised not to use the version found here as it is out of date, and should use the latest version with an offline toolchain.

2. Download this file: Smoothie firmware. This ZIP file contains both the latest version of the Smoothie firmware source code, and all the necessary setup files for the offline toolchain that will allow you to compile it. Extract the contents of the ZIP to a folder.

3. Inside your new folder is a folder called arthurwolf-Smoothie-xxxx (Arthur Wolf is the main Smoothie developer). Inside this folder should be the src and gcc4mbed folders. Go into the gcc4mbed folder and find the win_install command script file (or mac_install or linux_install as required). Run this install command script by double clicking it. This will download and install the offline toolchain. This beautiful piece of work is courtesy mostly of Adam Green I believe.

4. There will now be a number of new folders and files within your arthurwolf-Smoothie-xxxx folder. There are a few changes to the code that need to be made before you can compile it:

- Go to the build folder inside the gcc4mbed folder, locate the mbed.ld file and open it in a text editor. Remove the comments markers from the beginning and end of line 4 and add them to line 5. Your code should now look like this:

/* Linker script for mbed LPC1768 */
MEMORY
{
  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K 
/*  FLASH (rx) : ORIGIN = 16K, LENGTH = (512K - 16K) */
...

- Go to the src folder (the one inside the arthurwolf-Smoothie-xxxx folder), locate the main.cpp file and open it in a text editor. Comment out lines 24, 26 and 43 and uncomment line 25. Your code should now look like this:

/*  
      This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
      Smoothie 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.
      Smoothie 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 Smoothie. If not, see <http://www.gnu.org/licenses/>. 
*/

#include "libs/Kernel.h"
#include "modules/tools/laser/Laser.h"
#include "modules/tools/extruder/Extruder.h"
#include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
#include "modules/tools/switch/SwitchPool.h"
#include "modules/robot/Player.h"
#include "modules/utils/simpleshell/SimpleShell.h"
#include "modules/utils/configurator/Configurator.h"
#include "modules/utils/currentcontrol/CurrentControl.h"
#include "modules/utils/pausebutton/PauseButton.h"
#include "libs/ChaNFSSD/SDFileSystem.h"
#include "libs/Config.h"
#include "libs/nuts_bolts.h"
#include "libs/utils.h"

#include "libs/USBCDCMSC/USBCDCMSC.h"
//SDFileSystem sd(p5, p6, p7, p8, "sd");  // LPC17xx specific : comment if you are not using a SD card ( for example with a mBed ).
LocalFileSystem local("local");       // LPC17xx specific : comment if you are not running a mBed
//USBCDCMSC cdcmsc(&sd);                  // LPC17xx specific : Composite serial + msc USB device

int main() {

    Kernel* kernel = new Kernel();

    kernel->streams->printf("Smoothie ( grbl port ) version 0.6.1 \r\n");

    //kernel->add_module( new Laser(p21) );
    kernel->add_module( new Extruder() );
    kernel->add_module( new SimpleShell() );
    kernel->add_module( new Configurator() );
    kernel->add_module( new CurrentControl() );
    kernel->add_module( new TemperatureControlPool() );
    kernel->add_module( new SwitchPool() );
    kernel->add_module( new PauseButton() );   

//    kernel->add_module( &cdcmsc );
...

5. Now you are ready to compile the source code. Inside the gcc4mbed folder find the BuildShell command script and run it. This will open up a command window that has all the appropriate PATH settings etc.

6. At this point in the command window you are probably in the gcc4med folder still. Go up a level into the arthurwolf-Smoothie-xxxx folder (in Windows you do this by typing cd..).

7. If you show a directory listing at this point (dir in Windows), you should see, amongst other things, a file called makefile. If not then you are in the wrong folder. You must be in the arthurwolf-Smoothie-xxxx folder. Now, type make clean, and when that has finished, type make.

If the compilation was successful you should see a main.bin file in the arthurwolf-Smoothie-xxxx folder. Copy this main.bin file to your mbed as per normal.

8. The final step in the setup is to copy a file named config (no extension) onto the mbed also. This config file contains all the settings peculiar to your CNC machine. Here is the one I used for testing, with nothing connected to the mbed:

# Robot module configurations : general handling of movement G-codes and slicing into moves
default_feed_rate                            4000             # Default rate ( mm/minute ) for G1/G2/G3 moves
default_seek_rate                            4000             # Default rate ( mm/minute ) for G0 moves
mm_per_arc_segment                           0.3              # Arcs are cut into segments ( lines ), this is the length for these segments.  Smaller values mean more resolution, higher values mean faster computation
mm_per_line_segment                          5                # Lines can be cut into segments ( not usefull with cartesian coordinates robots ). 
z_axis_max_speed                             140              # Max allowable speed for this axis

# Arm solution configuration : Cartesian robot. Translates mm positions into stepper positions
alpha_steps_per_mm                           63               # Steps per mm for alpha stepper
beta_steps_per_mm                            63               # Steps per mm for beta stepper
gamma_steps_per_mm                           4000             # Steps per mm for gamma stepper

# Planner module configuration : Look-ahead and acceleration configuration
planner_queue_size                           64               # Size of the planning queue, must be a power of 2. 128 seems to be the maximum.
acceleration                                 2000             # Acceleration in mm/second/second.
acceleration_ticks_per_second                1000             # Number of times per second the speed is updated
max_jerk                                     400              # Max instant cornering speed change. Higher means jerkier/faster, lower means smoother/slower.

# Stepper module configuration
microseconds_per_step_pulse                  2                # Duration of step pulses to stepper drivers, in microseconds
minimum_steps_per_minute                     1200             # Never step slower than this
base_stepping_frequency                      70000            # Base frequency for stepping, higher gives smoother movement

# Stepper module pins ( ports, and pin numbers, appending "!" to the number will invert a pin )
alpha_dir_pin                                1.18             # Pin for alpha stepper direction
beta_dir_pin                                 1.21             # Pin for beta stepper direction
gamma_dir_pin                                2.1              # Pin for gamma stepper direction
alpha_step_pin                               1.20             # Pin for alpha stepper step signal
beta_step_pin                                1.23             # Pin for beta stepper step signal
gamma_step_pin                               2.0              # Pin for gamma stepper step signal
alpha_en_pin                                 nc               # Pin for alpha enable pin

# Serial communications configuration ( baud rate default to 9600 if undefined )
uart0.baud_rate                              9600             # Baud rate for the default serial port               

# Switch module for spindle control
switch.spindle.enable                        true
switch.spindle.on_m_code                     03               # clockwise. use m04 for CCW           
switch.spindle.off_m_code                    05           
switch.spindle.output_pin                    0.11 

# Endstops
alpha_min_endstop                            1.30          
beta_min_endstop                             1.31         



# Extruder module configuration
extruder_module_enable                       false            # Whether to activate the extruder module at all. All configuration is ignored if false

# Laser module configuration
laser_module_enable                          false            # Whether to activate the laser module at all. All configuration is ignored if false.

# Hotend temperature control configuration
temperature_control.hotend.enable            false            # Whether to activate this ( "hotend" ) module at all. All configuration is ignored if false.

# Switch module for fan control
switch.fan.enable                            false   

# Panel
panel.enable                                 false

# Only needed on a smoothieboard
currentcontrol_module_enable                 false

You can see that at the bottom I have disabled a number of modules (mostly those relating to 3D printing). I have also assigned certain outputs to the pins that connect the LPC1768 to the mbed's onboard blue LEDS (P1.18, P1.20, P1.21, and P1.23): the alpha and beta step and the alpha and beta direction signals (alpha and beta will translate into X and Y axes for me).

Now to see if it works, make a serial port connection with the mbed (I used 9600-8-N-1 with the baud rate set in the config file) and your usual serial terminal program. I use Windows HyperTerminal. If you now reset your mbed, you should see in the serial terminal window this message: Smoothie ( grbl port ) version 0.6.1 start.

Assuming you have gotten this far, you can now type in G-code movement commands into the serial terminal eg: G0X1000Y1000 (move 1000mm along X axis and 1000mm along Y axis). When you hit enter, Smoothie on the mbed interprets the command and in this case creates a certain number of stepper motor pulses that you can see on LED2 and LED4.

The default setting for movement instructions is for the X and Y coordinates to be absolutely referenced from the 0,0 starting point. So if you now send G0X50Y50, the tool won't travel 50mm further on each axis, but will actually travel back 950mm on each axis. This reversal of motor direction is indicated by LED1 and LED3.

My thanks goes to to Arthur Wolf, both for all his work generally on Smoothie, and for his help today in getting me started with this, via IRC. The Smoothie project have an active IRC channel (#smoothieware) on the Freenode IRC server. If you don't have an IRC client, you can use the web-based one here.


3 comments on Smoothie firmware for mbed:

13 Jan 2013

When I downloaded Smoothie today and ran win_install, all seemed to go OK. I edited mbed.ld, qnd main.cpp OK,but when I went to run BuildShell, I could not find it, neither could Search.

The dounloaded folder was named Smoothie-Master, not arthurwolf-Smoothie-xxxx. Could this name change have confused win_install?

So where can I get a copy of BuildShell.bat ?

John

14 Feb 2013

Hi I got the code to compile and build, but it does not send anything to the terminal just blinks 2 LEDs. I had to include mbed.h. It seems that the newer version has changed something withe SD card and Serial output. And i most likely broke something in order to make a build.

06 May 2016

New mbed source has separate ld files instead of 1 mbed.ld file. I changed the file mbed\src\vendor\NXP\cmsis\LPC1768\GCC_ARM\LPC1768.ld. But the main.cpp file has changed to much so these suggested changes are not valid anymore. Its hard to see what to change now to make it work...

It does build but doesn't work (as expected). Because the sdcard / local flash file system is incorrect mbed cannot load the config file. Does anyone know how to change the main.cpp file to work with local flash instead of sdcard?

LED1 is on, LED2 is blinking fast...

Please log in to post comments.