Skip to content

Just for info: easily read/write from/to Smart Stepper by raspberry pi/bash #54

Description

@vmario89

Hi,

just wired up some bash stuff to operate Smart Steppers with scripts utilizing screen

apt install screen
#!/bin/bash
SCREEN_NAME="screen_smart_stepper"
LOG_FILE="/opt/${SCREEN_NAME}.log"

# remove old log file if existent
rm "${LOG_FILE}" > /dev/null 2>&1

# send "smart stepper command + enter (^M) keystroke" to first window (-p 0 could be applied) in a new named screen by stuffing (https://www.gnu.org/software/screen/manual/html_node/Command-Summary.html) the string into input; log the output to file
screen -d -m -L ${LOG_FILE} -S ${SCREEN_NAME} /dev/ttyUSB-SMARTSTEPPER 115200

declare -a cmdArray=("getcal" "microsteps" "readpos" "encoderdiag" "spid" "vpid" "ppid" "dirpin" "enablepinmode" "errorlimit" "ctrlmode" "maxcurrent" "holdcurrent" "homecurrent" "motorwiring" "stepsperrotation" "velocity" "looptime" "eepromerror" "eepromloc" "geterror" "getsteps" "torque")
for val in ${cmdArray[@]}; do
        screen -S ${SCREEN_NAME} -X stuff "${val}^M"
done

sleep 1
screen -S ${SCREEN_NAME} -X quit

# clean up the log with ^M symbols
sed -i 's/\r//g' ${LOG_FILE}

it looks easy but it was torture to find out how to communicate best without bugging the complete USB buffer or change stty settings. Maybe someone has smarter solution. That one works and might be a starting point.

same script can be used as basis to send commands or to build up some cyclic things.

i am using it for Hangprinter project to read encoder data without I2C/Two Wire interface, because there's no Duet support yet. And i dont want to mess around with firmware mods.

cheers, Mario

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions