Lately I've been experimenting with different DIY solutions for linear motion so that I can design and build my own custom plotters and CNC machines. This simple project encapsulates the basic elements of a linear motion system. Using the MicroMod Qwiic Carrier Board as a chassis, this linear motion system could be adapted for any number of applications, or you could even just build it for fun.
From the hardware store:
How to assemble the MicroMod Rail Car:
Thread four ¾” 4-40 screws through four nylon standoffs as shown in the top left corner of the above image
Use these four standoff screws to secure the four spring rollers to the underside of the Qwiic carrier board as shown below.
Place the Qwiic motor driver on the mounting posts furthest from the carrier’s USB connector, using two nylon standoffs to secure it in place. Make sure the board is oriented so the 4-pin screw terminal is on the “outside” and can be accessed later.
Connect the 2-pin screw terminal on the motor driver to the ground and 3.3V pins of the carrier board with some jumper wire. I soldered a right angle header to mine to make this easier.
Finally, complete the circuit by connecting the qwiic breakouts to the carrier using some 100mm Qwiic cables.
As long as you’ve already completed the setup for the SAMD51 MicroMod processor, you should be able to upload the following sketch to test out the Qwiic rail car. If everything is working, after you upload the sketch, click one of the limit switches and the motor should start turning. If you click the limit switch again, the motor should change directions.
MicroMod Rail Car Sketch:
#include <Arduino.h>
#include <stdint.h>
#include "SCMD.h"
#include "SCMD_config.h" //Contains #defines for common SCMD register names and values
#include "Wire.h"
#include <SparkFun_Qwiic_Button.h>
QwiicButton button;
uint8_t brightness = 70;
SCMD myMotorDriver;
#define LEFT_ 0
#define RIGHT_ 1
#define LEFT_MOTOR 0
#define RIGHT_MOTOR 1
void setup() {
// put your setup code here, to run once:
Wire.begin();
button.begin();
button.LEDoff();
pinMode(8, INPUT_PULLUP);
myMotorDriver.settings.commInterface = I2C_MODE;
myMotorDriver.settings.I2CAddress = 0x5D;
myMotorDriver.begin();
while ( myMotorDriver.busy() );
myMotorDriver.enable();
myMotorDriver.setDrive( LEFT_MOTOR, 0, 0);
myMotorDriver.setDrive( RIGHT_MOTOR, 0, 0);
}
bool directionMoving = false;
void loop() {
bool limitReached = false;
limitReached = button.isPressed();
if (limitReached == true){
if(directionMoving == true){
myMotorDriver.setDrive( LEFT_MOTOR, 0, 100);
directionMoving = false;
}else{
myMotorDriver.setDrive( LEFT_MOTOR, 1, 100);
directionMoving = true;
}
}
delay(200);
}