close-circle
Close
0%
0%

keyboard controlled treadmilldesk

Build a treadmill desk that can be controlled from your PC

Similar projects worth following
close
From times to times I work from home, and I wanted to try to work on a treadmill desk. So first, what is a treadmill desk? It's an elevated desk on top of a treadmill, it allows you to work while walking at a reasonable pace. It is better for your health than sitting all day and it can help with concentration as well.
I didn't want buy a ready made treadmill desk, instead I chose to build one from off the shelf... and some arduino board of course ;-)

In the process of improving my workstation I decided to try a sit-stand treadmill desk setup, meaning I can use it as a treadmill desk and also quickly turn it into a regular desk.

 I was thinking about doing this for a while, and when I noticed the Hackaday prize challenge was about :
"Movement and support for things that help move humanity forward"
Well, surely a treadmill desk help moving humanity forward... while staying in the same room ;-)
I wasn't in the top 20, but then the HaD staff suggested me to submit this project for the "Assistive technology" contest.
I still wasn't in the top 20, so here I am  now, in the "Anything goes" category!
Even if I don't win anything it would have been a good thing to participate since it forced me to complete this project.

Goal #1 : those are pretty hefty devices, so I figured out I'd better try to make my own setup from off the shelf items.
→ done, I use commonly available products from Ikea and Decatlhon for my setup, the result is looking good so far:



Goal #2 : after setting up my treadmill desk, I found the control panel quite big and inconvenient, there was no room for it on my cluttered desk full of TODO lists, empty mugs, dev boards and cats(!) .So I decided to try to control the treadmill from my keyboard.

→ done, I connected an Arduino to the treadmill, the details are in the logs and the instructions.

Control Panel board


Goal #3 : every 5 seconds the display is cycling through different measurements, distance, speed, burned calories, etc. Sometimes you need to wait for 20 seconds to get the value you want, I'd like to have the value on my PC

→Done, but the distance accuracy could be better


Goal #4 : USB is nice, but it could be useful to have Bluetooth as well

→TODO, I received a CC2541 and will be working on it when the display is finished

twebstats.py

Webserver and chart generation

x-python - 4.35 kB - 10/09/2017 at 05:49

download-circle
Download

treadmill-control.ino

Arduino code controlling the treadmill

x-arduino - 3.78 kB - 10/09/2017 at 05:48

download-circle
Download

udp2serial.py

Listen on UDP socket and forward the data on the serial port (to the Arduino)

text/x-python - 5.74 kB - 07/23/2017 at 19:57

download-circle
Download

treadmill-control

Send prodived string on local UDP port

treadmill-control - 222.00 bytes - 07/16/2017 at 09:43

download-circle
Download

  • 1 × treadmill I used the "Walk By Domyos" from Decathlon
  • 1 × Ikea SKARSTA desk a variable height desk, electric or mechanical version
  • 1 × arduino pro mini any Arduino board should do
  • 1 × CC2541 If you want to control your treadmill through BLE

  • Need more accuracy?

    PixJuan5 days ago 0 comments

    When I compare the distances in my CSV file and the ones displayed on the original panel screen, they do not match and I am not very surprised.

    Currently I just take for granted that the treadmill runs at the speed it is supposed to, and that acceleration/deceleration is instantaneous, I know it is not true.

    On the  6 pins connector between the panel and the treadmill, I strongly suspect there are some rotary encoder signals. This is probably how they read the speed of the engine.

    To get the real speed of the treadmill and improve the accuracy, | see 3 solutions :

    • add a PCB with a LS7083N and a 12V-to-5V converter
    • read the speed at the LCD controller level
    • not using any other signal but using a less naive modelisation of the treadmill speed in my arduino code, including the time ittakes to accelerate

    I will probably try the 3rd approach first since it doesn't involve any hardware modifications. It won't be as accurate as the 2 other approaches but it's not a big deal if I don't know the precise number of calories I burn each day. After all, the number of calories is already an estimation, and in my case I mostly use those values to track how much exercise I do during the week

    On another topic, I added a git repository to the project, and I improved the charts by removing the year from the dates and limiting the display to the last 10 days.

  • Logging my physical activity

    PixJuan10/04/2017 at 09:32 0 comments

    Now that the treadmill is working and can be controlled from my PC, there is one more feature I need, logging how long I use my treadmill everyday and what distance I walk.

    This feature requires modifications both on the Arduino and python code:

    • The Arduino should give more information about the status of the treadmill, running or not, and about its speed.
    • The Python script should store the time and the speed when the treadmill starts and log everything in a file when it stops.
    • A new script should  draw a bar chart of the data

    Let's not reinvent the wheel and use CSV to store our data. But wait, there is one problem: in what format will we store the date?
    I was going to store it in the European format, dd/mm/yy, but what if an American user (imaginary user of course, I'm not sure anybody else than me will use this)  wants to import the data in LibreOffice or Excel?

    Well, according to Stack Overflow, it looks like there is an unambiguous format  that works with every locale : yyyy-mm-dd
    So even if it doesn't matter for this project, I learned a useful trick next  time I need to deal with both sides of the Atlantic.

    Here is a line of my CSV file:

    #   date   ,hours,minutes,seconds,distance, duration,calories
    2017-10-04, 10  ,   44  ,   42  ,  1845  ,    23   ,  53
    

    Now to draw the chart, I had a look at the web based solutions, but for now I think I'll stick with Python, I don't want to use JS for this project. So here is what it looks like with matplotlib

    I could just bind a key to generate this graph and display it with eog, but I'd rather serve it through a web page, so I think it will be the next step.


  • Treadmill as an assistive technology

    PixJuan09/03/2017 at 17:41 0 comments

    I started this project as an ergonomic improvement for my workstation, but treadmills can also be used in the context of post surgery rehab, like for hip surgery.

    Of course, in this case it would be wise to add handles or hand rails and to have a mat around the treadmill so that if the user needs, he can safely leave the treadmill in case of urgency.

  • Buzzer and Power

    PixJuan07/27/2017 at 05:12 0 comments

    There was a problem I didn't mention with the control panel, I couldn't control it anymore when the Arduino was not powered.
    This could probably have been fixed by adding diodes but as I will need to power the Arduino anyway if I want to use Bluetooth, I just chose the later.

    So I just soldered a pin on the on an unpopulated part of the PCB that said "5V". I first tried one saying "5V Backlight" but it turned out to be 0V, it is probably activated by the MCU on other models of treadmill.
    Then I connected the Vin of my Arduino Nano to this pin. From what I read, 5V is not enough to power the Nano through Vin, you must directly connect it to the 5V Pin (which makes sense but I thought it was an output only pin).

    Also I unsoldered the buzzer because it was too loud. I soldered pins instead so may be I will add a resistor or feed the signal to the Arduino. It feels a less safe to not have the three warning beeps before the treadmill starts, I will try to find something safe and not annoying.

  • The whole picture

    PixJuan07/20/2017 at 12:13 0 comments

    I realize I did not put a lot of pictures of the treadmill itself :

    -Here is the treadmill mode

    -Here is the standing desk mode,

    I just put the treadmill away and attach it to the desk with a snap hook. It is relatively safe but if you have kids or pets you'd better not let them in the room when you're not around.

    -Here is the normal desk mode

    Just lower the desk and take a chair

    It was quite important for me to keep a single desk. If you are just using a laptop it's, ok to a treadmill desk plus a regular desk but in my case I didn't want to move all my stuff around each time, plus I didn't have a lot of room for another desk.

  • I've been replaced by a robot!

    PixJuan07/19/2017 at 20:30 0 comments

    Robots were taking our jobs, now they're taking our pastimes ;-)



    I tried to use a robot (Mip) on the treadmill just for fun but it may be useful for those are working on a robot for the Hackaday prize. It can be less tiring than running after your robot, it may really be easier to spot a problem with your robot if you're just standing instead of trying to follow your him. For example I noticed that my Mip was going to much on the right, it was really obvious on a treadmill.

  • Distance & Calories

    PixJuan07/18/2017 at 22:25 0 comments

    I'm working on the display now. It won't require any hardware modification for now.

    Distance calculation

    I'm going to trust the speed the Arduino thinks it has : I know that the treadmill starts at 0.5 km/h and I know when the speed is modified, at least when it is changed by the Arduino. So every second I can add a certain value to the total distance, depending on the speed.

    I'd prefer to avoid using floating point arithmetic in the Arduino code, in the end, it's just a 8 bit mcu!

    So I'll count the speed in tenth of kilometers

    // speed are in tenth of km/h
    unsigned int maxSpeed = 80;
    unsigned int minSpeed = 5;
    unsigned int currentSpeed = 5; // the initial value is the speed of the treadmill when it just switched on
    unsigned int speedStep = 1; // the step it increases/decreases every time we push a button

    and I also need to know if the treadmill is running or not, I'll only update the distance if the treadmill is running

    int treadmillRunning = 0; // 1 if the treadmill motor is on, 0 otherwise

    Then I'll store the value in an unsigned long, because int are only 16 bits on Arduino, and I'll call the update function every second with a timer :

    unsigned long totalDistance = 0;

    void countDistance()
    {
    if (treadmillRunning)
    totalDistance += currentSpeed ;
    }

    I'm using this library for timers : http://playground.arduino.cc/Code/Timer

    Display

    How will I display the data? On Linux desktops I'll use the Freedesktop notifications. For example here is the result with notify-send from the libnotify-bin package

    Calories

    I found a formula on Shapesense :

    CB = [0.0215 x KPH3 - 0.1765 x KPH2 + 0.8710 x KPH + 1.4577] x WKG x T
    CB = Calorie burn (in calories)
    KPH = Walking speed (in kilometres per hour)
    WKG = Weight (in kilograms)
    T = Time (in hours)

    Once I get the distance right, it should be easy. It will be calculated on the PC, not on the Arduino, so you can easily enter your wheight/height parameters in a config file.

  • Status:working

    PixJuan07/16/2017 at 09:41 0 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:

    • I tried to send commands to the Arduino with picocom : OK
    • I set up the serial port with stty and tried to echo/cat some commands to the serial port /dev/ttyX : failed
    • I connected to the Arduino with socat - /dev/ttyUSB0 : OK
    • I tried to send commands to the Arduino with echo -n s | socat - /dev/ttyUSB0 : failed

    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 :

    • echo $(sleep 3 && echo s)| socat - /dev/ttyUSB0 :ok

    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 :

    • socat PIPE:/var/run/pipo.pipe /dev/ttyUSB0,raw :failed
    • socat UDP-LISTEN:6666,fork GOPEN:/dev/ttyUSB0 : failed

    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

  • Controlling the treadmill with an arduino

    PixJuan07/15/2017 at 09:29 0 comments

    The easiest way to control the treadmill is to simulate button presses, the original MCU will take care of changing the speed and stopping/starting the treadmill.

    So the Arduino code should look like this :

    Loop
    {
    check serial port for commands
    if we receive a valid command, then simulate a key press
    }

    There is only 3 switches on the control panel :

    • slower
    • start/stop
    • faster
    After checking on the board, they are respectively linked to pin 2, 3 and 4 of the panel MCU.

    The plan is to connect some Arduino pins to those switches, but first we need to check if the switches are connected to the ground or to VCC: They are connected to the ground, so it in the code we must set the pins to HIGH on init and set them to low when we want to simulate a key press.

    So we just solder 4 jumper cables on the panel board, 3 for the switches and one for the ground and we will connect them to the Arduino.

    So far it is working!
    I tried to set pin connected to 'faster' to LOW for 500ms and it simulated 2 key presses. I lowered the timing to 250 ms and now it is reliable!
    I will quickly upload the code here.

  • What is this chip?

    PixJuan07/13/2017 at 05:39 0 comments

    My treadmill desk setup is done, now I have to control it with my computer. Time to do some reverse engineering to see how the treadmill works.

    When I opened it I saw a chip I can not identify :

    Here is what is engraved on the chip :

    HT48R066B
    B435U0093G1

    There was also a label on it saying : TC5376A-V2.00-B OTP

    Any idea what this chip could be ?

    EDIT: well, I found, it's a Holtek, I misread the T and thought it was a I

View all 10 project logs

  • 1
    Detach the control panel from the threadmill and remove the handle

    Remove the screws at the bottom of the control panel so you can open it and remove it from the handle. The cable must be unplugged from the panel so that we can get rid of the handle.

    We also need to remove the handle bar from the threadmill because we ill put it under the desk.

    In order to be able to put back the cable in the handle if we need, we need a string to make a knot on the cable, before the connector so that when you remove the cable, you can make a loop with a thread.

    They you can remove the cable, it will pull the thread. So if you ever want to restore the threadmill to its original step, you just have to attach the connector to the thread and pull the thread.


    You can then remove the handle completely and dispose it.

  • 2
    Hang the control panel to the Desk

    Take the control panel and put a string in the hole left when removing the handle, put some tape to attach the string to the top of the panel. Tie a pen or a small stick the will be used to hang the panel from the desk lever

  • 3
    Add a hook to the threadmill

    Put a ring or a hook where the handle was attached to the threadmill. If you take a hook, bend it to close it.

    This is an optional step. When I don't use the threadmill, I put it on its side and I hang it to my desk so I can use my desk with a chair.

View all 6 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates