Close

Status:working

A project log for keyboard controlled treadmilldesk

Build a treadmill desk that can be controlled from your PC

pixjuanPixJuan 07/16/2017 at 09:410 Comments

I worked on 2 parts : the Arduino code and the integration in my desktop.

The arduino part was easy, I just had to read the serial port and wait for on of the 3 control characters I picked and set the corresponding pin to LOW.

But I met some difficulties with the serial port access from my PC. Initially I though I could avoid writing any "real" code and stick to Bash, I couldn't avoid some python script:

Then I searched the internet and found a page mentionning that to connect to the Arduino, you needed a 3 seconds delay for it to be ready to receive serial data. I had never heard of this "reset on serial connection behaviour" but it seemed to match what I was observing, so I tried the following command :

It worked, but it is not really usable, I don't want to have a 3 seconds delay for every command I send.

So instead I tried to use a pipe or UDP socket :

So I wrote a small python script that listens to UDP packets and send them on the serial port. This will make it easier to run on Windows

As I am using Awesome, I created some shortcuts to control the treadmill by adding the following in /etc/xdg/awesome/rc.lua :


awful.key({ modkey, "Control" }, "Left", function() awful.util.spawn("/usr/local/bin/treadmill-control m") end),
awful.key({ modkey , "Control"}, "Up", function() awful.util.spawn("/usr/local/bin/treadmill-control s") end),
awful.key({ modkey , "Control"}, "Right", function() awful.util.spawn("/usr/local/bin/treadmill-control p") end),

treadmill-control is just a very basic script that sends the first parameter on a UDP socket :

#! /bin/sh

if [ $# -ne 1 ] ; then
echo "error $0 needs a single parameter :"
echo "s : start/stop the trheadmill"
echo "p : increase speed"
echo "m : decrease speed"
fi

echo -n $1 | socat - UDP:127.0.0.1:5005

Discussions