TIC825 programming in c

Hi there,

Recently I acquired the TIC825 stepper controller to run my stepper via USB. My aim is to control the stepper via a program code written in c. I am not advanced in c programming, but usually find my way. Unfortunately, I could not find any code samples on the internet, so I was hoping that someone could share a piece of code.

I already had a look at the tic.h library as well as code examples for the Arduino.

One of my question relates to the command tic_handle_open(). Not sure if needed and how to correctly use. From reading the comments related, seems like it is required to address the tic controller.

Many thanks for any hints!


Hello, Helge.

Yes, the tic_handle_open function is crucial for communicating with a Tic if you are using the C library, since it opens a handle that all the Tic USB commands go through. Here is the signature of the function:

tic_error * tic_handle_open(const tic_device *, tic_handle **);

To specify which Tic device you want to connect to, you have to pass a pointer to that device in as the first argument. This means that prior to calling tic_handle_open, you must use tic_list_connected_devices to get a list of Tic devices, and select which one you want to connect to.

The second argument is a pointer that the function uses to return a tic_handle * to the caller, which represents the new open handle.

Directly using the C library is one of the most challenging ways to use the Tic because you have to carefully manage pointers to the Tic device list, the devices themselves, the handle, and the errors. It’s also important to check the return value of any function that returns an error pointer so you can see if any errors happened, and print an informative error message. It would be easier to just invoke our command-line utility, ticcmd, from your program, and let it take care of all of those details for you. The “Example code to run ticcmd in C” section of the Tic user’s guide shows how to do that.

Another option would be to start with the source code of ticcmd, which is written in C++, and modify it to do what you need. Once you get used to that, you could remove all the code you don’t need and convert the remaining code to C.


Hi David,

Many thanks, the last couple of days I did a lot of Google research on pointers and handles. Whilst I think I got the concept behind, I wonder how to practically apply. Still I am somehow keen to have the driver based on the tic.h library. Reason is that I wanted to integrate in another program already existing.

Probably I am asking for too much, but could you drop just a few lines of code which show what the tic-commands in a ‚real life’ example would look like (incl. the device and handle), just to simply move the stepper forth or back? Maybe I can then leverage on the example provided for the Arduino, especially on the structure of the code.

Best, Helge

just wanted to add this. Could you kindly let me know whether in principle it should work like that, and if not absorbing too much time, correct where needed?

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <tic.h>

int main()
//do I need to make the following typedef definitions like that, or anything else? 

typedef struct tic_error tic_error;
typedef struct tic_settings tic_settings;
int tic_handle *;

// providing I already know the device number, for instance “12345678"


tic_settings_set_product(tic_settings *, TIC_PRODUCT_T825);

tic_settings_set_step_mode(tic_settings *, TIC_STEP_MODE_FULL);

//what to put in for the "handle", anything to be done???

tic_error * tic_handle_open(12345678, tic_handle *);

tic_error * tic_energize(tic_handle *);

tic_error * tic_exit_safe_start(tic_handle *);

tic_error * tic_halt_and_set_position(tic_handle *,0);

tic_error * tic_set_target_position(tic_handle*, 100);

tic_error * tic_reset_command_timeout(tic_handle *);

tic_error * tic_set_target_position(tic_handle *, -100);

tic_error * tic_reset_command_timeout(tic_handle *);

tic_error * tic_deenergize(tic_handle *);

Hello, Helge.

While it would be nice to have an example C program that moves the stepper motor back and forth using the Tic C library, it would take more than a few lines, and unfortunately, working on such an example is not a priority for us right now.

There are many issues with the code you posted. You should not need to write any typedefs in your code. I suggest that you start with a simple program that just calls tic_list_connected_devices. The second argument of that function is used to report to the caller how many Tic devices are connected. So you should be able to make a simple program that just calls that function and then prints the number of Tics connected via USB.


Hi David,

Understood and appreciated. For the last 48 hours I was reading over and over again the cli.cpp code and tried to figure out how to write up a simple c code to get the device name - looked to me like the easiest case. Also looked at the code for the device_selector. I tried different many different things (I better not show here…), compiling with gcc and linking to -I/usr/local/include/libpololu-tic-1 . But did not manage to compile.

Would be great service if you could just drop the piece of code that examplifies how to make it work for a simple query of the device or anything else you would deem more appropriate.

Thanks a lot in advance, Helge

We now have an example showing how to control the Tic using the C API. You can find it in the “Example code using the C API” section of the user’s guide.


Hi David, really really appreciated. I would have never worked out myself. Best, Helge

Hi David,

Sorry for bothering again - all worked well what is now provided in the user guide.

Now I wanted to integrate into an already existing program and need to update the (existing) CMakeList.txt file and add the tic libraries to the line which is:

target_link_libraries(for example with /usr/local/lib/libpololu-tic-1.so and same for libusbp-1.so ect.)

Which did not work, after runnning cmake -DCMAKE_INSTALL_PREFIX=/usr …, I applied sudo make, which brought up an error message that tic.h: No such file or directory.

I followed the instructions shown here, e.g. for udev-rules

I guess something is not yet ideal as regardshe earlier mentioned target_link_libraries.

Many thanks in advance, Helge


It sounds like you have an existing CMake project and you are trying to configure it to use the Tic library.

The Tic library provides configuration files that allow the pkg-config utility to find it. So you can run pkg-config libpololu-tic-1 --cflags --libs in a shell to get all the compiler options needed to use the library.

You need to configure CMake to run pkg-config like that and use those options. Unfortunately, CMake doesn’t have an easy one-line command you can use. The code you need to use is something like this:


pkg_check_modules(LIBTIC REQUIRED libpololu-tic-1)


# your target definition here, e.g. add_library or add_executable

target_link_libraries (yourtargetname "${LIBTIC_LDFLAGS}")

I have not tested this code, but I adapted it from working code in the the top-level CMakeLists.txt file and the lib/CMakeLists.txt file in the Tic software. The Tic software depends on two libraries using code like this: libusbp and libyaml. If you have trouble getting this code to work, I recommend carefully examining the way that libusbp and libyaml are integrated into the Tic software.

If you need further help, please tell me what operating system you are using, post your CMakeLists.txt files, post the full output from pkg-config libpololu-tic-1 --cflags --libs, post the full output you get when running cmake, and post the full output you get when running make VERBOSE=Y to build your project.


Hi David,

Thank you once again for dedicating your time to this.

I have enhanced my CMakeLists.txt file as suggested. I applied the cmake-command succesfully. When I have done so first time, I got the confirmation “Found libpololu-tic-1, version 1.6.2”. I guess this confirms it is somehow working.

When applying “sudo make VERBOSE=Y” , I get the error message “tic.h: No such file or directory”

I have uploaded a file pkgconfig_makeVerbose (3.1 KB) which shows the full outputs as suggested for

a) pkg-config libpololu-tic-1 --cflags --libs
b) make VERBOSE=Y

Then I also attached my CMakeLists.txt file. Essentially it is a mix of the original file plus the a.m. enhancements.

In addition, please also find the rpi-focus.cpp file in its original version, where I only added “#include <tic.h>” , to see if it is compiling.

rpi_focus.cpp (14.8 KB)

N.B. The rpi-focus is actually the code where I wanted to replace the usage of the Raspberry GPIOs, which are connected to the pololu A4988 driver by the new TIC825 - this is what my ambition here is all about. If I succeed, I will share the solution in the indilib forum (astronomy), so other users might also be able to benefit. There are many people interested in stepper motors in order to move the telescope focuser forth and back without touching the scope.

Best, Helge

Earlier I assumed you were programming in C. Since you are programming in C++ instead, I think you will need to add this line some time before your define your target and after you find the Tic library:


Whenever the compiler cannot find tic.h, it means that it did not receive the proper -I argument that is specified in the output of pkg-config.

Since you are actually using C++, you might consider using the Tic’s C++ API, which is easier to use because you do not have to remember to manually check errors or free allocated resources. The only example we have currently for using the C++ API is the source code of ticcmd.

If you need further help compiling your program, please post all of the information I asked for in my last post.


Hi David,

you are right, and apologies for not realizing earlier, that my code is in c++ - which was kind of obvious from the file name (.cpp). I also did not mention that all of this is running on a Pi, with Ubuntu Mate as OS (16.04, adapted for the RPi 3B+). Hope there is nothing else of importance that I missed out. Thank you for pointing me to the C++ API - I will further look into.

The latest updating of the CMakeLists.txt file brought some improvements - tic.h is no more reported to be missing.

Now, the make process is stopping at 50%, error message is:
c++: error: ${LIBTIC_CFLAGS}: No such file or directory

I uploaded the output.

makeVERBOSEY (2.2 KB)

Would you also need the CMakeOutput.log or any other file generated when applying cmake …?

Best, Helge

I think you forgot to type one of the dollar signs in the line that sets CMAKE_CXX_FLAGS, so you should carefully check that line. Also, the error you quoted in the body of your post is different from the actual error shown in your makeVERBOSEY attachment; the error message in the attachment has no dollar sign in it.

It seems like you are forgetting to post your CMakeLists.txt files and the output from running cmake. If you need further help building your program, please provide all of the following pieces of information in your post:

  1. The operating system you are using.
  2. Your CMakeLists.txt file or files.
  3. The full output from pkg-config libpololu-tic-1 --cflags --libs.
  4. The full output you get when running cmake to configure your project.
  5. The full output you get when running make VERBOSE=Y to build your project.

Please post any attachments with an appropriate extension like .cpp or .txt so it is easy to open them.


Hi David,

Looks like I accidentally added the $ in my quote - to me, the CMakeLists.txt seems to have been correct, I try to provide the information as suggested, also took care that when opening in Windows, the line ending is correctly reflected (I know realize that after uploading the appendix txt appears twice, hope it still works).

  1. My operating system is Ubuntu Mate 16.04.5 LTS Xenial

  2. CMakeLists.txt: CMakeLists.txt.txt (3.9 KB)

  3. Output from pkg-config: pkg-config.txt.txt (154 Bytes)

  4. Full Output from CMake (hope this is what you are looking for):
    CMakeTraceDebug.txt.txt (28 KB)

  5. Make Verbose: SudoMakeVerbose.txt.txt (1.8 KB)

  6. rpi_focus.cpp (with include <tic.c>): rpi_focus.cpp (14.8 KB)

Sincerly hope this now provide all the information needed.

Best, Helge

You forgot to type some dollar signs in your CMakeLists.txt file. Here are the correct lines again from my earlier post:

pkg_check_modules(LIBTIC REQUIRED libpololu-tic-1)


Hi David,

I just wanted to take the occasion to thank you for your kind support on this matter. In the meantime, I have been able to complete my project, which was about the creation of a new INDI driver leveraging on the Tic controller.

I have published the project and driver on github, see below link. In case I made any incorrect references to your product, please let me know and I will update.

All the best, Helge

1 Like