5. Adding a GUI with Tcl/Tk

<p><a href="http://www.tcl.tk/">Tcl/Tk</a> is the most convenient way to create GUIs that will work on both Windows and Linux. Even if you only use one system, you will benefit from the fact that Tcl/Tk is quite easy to learn and used by a lot of people. The particular mix of Tcl/Tk and C that we recommend here was the best solution we found; if you know of other ways to do it, <a href="/contact">let us know</a>!</p> <p>Now, take a look at <code>ssc-tester.tcl</code>. This program is very simple: it contains a loop that runs 16 times to create sixteen sliders, one for each of the servos that can be controlled by the servo controller. The critical command is</p> <pre>&#x000A; scale .servo$i.scale -width 20 -length 200 -orient vertical&#x000A; -from 500 -to 5500 -command "stepTo 0 $i " -showvalue 0</pre> <p>This creates a slider with values from 500 to 5500, so that whenever you adjust the slider, the command</p> <pre>&#x000A;stepTo 0 slider position</pre> <p>will be run, with <em>slider</em> and <em>position</em> replaced by the slider number and position. This command is defined in <code>ssctester.c</code> by the line</p> <pre>&#x000A; Tcl_CreateObjCommand(interp, "stepTo", &amp;stepToProc, NULL, NULL);</pre> <p>The arguments are interpreted by the C function <code>stepToProc</code> and passed on to <code>stepTo</code> in <code>ssc.c</code>, where they are translated into commands to be sent to the serial port. When modifying the program for your own purposes, you will need to find the documentation for both commands in the Tcl/Tk language and special C functions used for interacting with Tcl. <a href="http://www.tcl.tk/man/tcl8.5/">The Tcl/Tk manual</a> will probably be your most useful reference. <br><br></p>

New Products

Glideforce GF01-122110-1-66 Micro Linear Actuator with Limit Switches: 12V, 8.1kgf, 6mm/s, 100mm Stroke
JST SH-Style Cable, 2-Pin, Female-Female, 16cm
A89301-Based Sensorless Brushless Motor Controller, 50V, 11A (Soldered Connectors)
Pololu Distance Sensor v2 with Pulse Width Output, 50cm Max, Side-Entry Connector
Breakout for JST SH-Style Connector, 5-Pin Male Side-Entry (2-Pack)
Pololu I²C Isolator, ISO1640
JST PH-Style Cable with Female Pins for 0.1" Housings, 2-Pin, 12cm
Pololu Digital Distance Sensor v2, 15cm, Side-Entry Connector
Pololu I²C Isolator with Isolated Power and Connectors, ISO1640, MIE1W0505BGLVH, 5V/3.3V, 200mA
JST PH-Style Cable with Female Pins for 0.1" Housings, 4-Pin, 12cm
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors