TM1638 Display Driver for Stellaris Launchpad

Here I am, roughly 3 months after my last post…

Ok, ok, the video isn’t very interesting I have to admit… but this is because this post is not about some nice looking IKEA lamp that changes colours remotely (and made me famous in Germany for some reason 🙂 ) but about my first attempt at writing an actual library / driver for a nice little display board.

TM1638 display board and the Stellaris Launchpad from TI

Another first is that I won’t be pasting my code here as I usually do, as this whole thing is intended to be re-used and improved.

So you can find it all here:

2 things are worth noticing on the hardware side:

  1. the TM1638 board is normally 5V but seems to be happily running on the 3.3V provided by the TI board
  2. beyond GND and VCC, you only need 3 wires, CLK, DATA (both input and output, you’ll notice in the code that we change the way of the pin) and STROBE.

It’s really simple to connect the 2 boards, you just connect these 5 wires together, with no other electronics parts. They also both seem to be happily running from my laptop’s USB port, which makes for a very quick and easy set up!

It’s already quite late and I need to go to bed before my son does his 3am wake up routine, so I’ll keep it brief… however, I can’t end without thanking the 2 guys that wrote similar libraries which I used as inspiration:

I initially wanted to go down Evgeniy’s way and use the hardware SPI/SSI (there are 4 of them on the Stellaris Launchpad) as it felt like a shame to bit bang the communication when there’s specialised hardware available.

However, here are a few drawbacks:

  • all the SSI configuration made the library less flexible (could not specify whatever pins you wanted)
  • had to use 4 wires instead of 3
  • had to use an extra 2 diodes and 1 resistor
  • never really understood what the FSS pin in the SSI configuration was for…:)

And ultimately I had issues with making it work… which is an euphemist for “it was NOT working”…:)

So I decided to go gown Ricardo’s way, which to be honest works perfectly well !

If you guys have the necessary boards, please give it a try and let me know ! As usual, any feedback is welcome.


19 Responses to TM1638 Display Driver for Stellaris Launchpad

  1. Pingback: Блог инженера » Доступен для предзаказа новый Launchpad | Блог инженера

  2. Pingback: Блог инженера » Библиотека msp430 — LED driver tm1638 | Блог инженера

  3. VirtualEnder says:

    Code works great! I loaded it up without problems.

    I’ve had some trouble integrating the library into another project though. As soon as I include the TM1638.h file in my code I get some pretty crazy errors on build (not in my the project files, but in the included compiler files, weird!). I’ll let you know if I find a solution. I’ve posted the problem on the forums. I also posted a link to your site there as well. Thanks for your work!

    • trandi says:

      I had to deal with exactly this problem yesterday.
      The CS project on Google Code is an “executable” one, simply so that you can easily execute that test class.
      I spend a couple of hours trying to put together a project that would generate both a static library and an executable, but to no avail.
      That has by the way, put into perspective my “complaints” about Java and Maven (I’m a Java developer by day…) and how hard it is to manage dependencies and multiple artifacts from the same project… but the Java ecosystem is light years ahead compared to all this C / C++ stuff, or at least Code Composer / TI… 🙂

      Anyhow, the solution I went with was to create a 2nd project of type “static library” and LINK to the same files that are in the original project.
      This 2nd project will produce a “.lib” which can be imported / linked into your own project.

      I have actually JUST pushed these changes into the repository, and now you’ll have 2 projects (an executable one and a static library one), LINKING to the same files.
      You use the 1st one to play with the library / test it, and the 2nd one to generate a “.lib” file to integrate in your other projects !

      Hope this helps, do let me know how it goes.

      • VirtualEnder says:

        Thanks! That explains a lot! I’m still trying to figure out this whole C/C++ thing! I’m a web programmer myself, so most of my background is in PHP/JavaScript etc. It’s a long jump! Thanks for your quick response. I’ll check out the update and see if I can get it working.

      • trandi says:

        No problem.

        While I was reading your post on the Stellarisiti forum (you should maybe include link to my library in case other people want to use it to) it occurred to me that your problem might be that you’re trying to use my library in a C project (my library is C++, as the TM1638 is defined as an object) !?

        I know I spent a non trivial amount of time figuring out how to tell CCS that I wanted a C++ project, which it seems to be simply declaring the main method inside a “.cpp” file.

        Sorry if this is trivial and you’ve already checked it… I just though this might well explain your “s soon as I include the TH1638.h header in my stepper project I get hundreds of build errors.” …


        P.S. I would have replied to you directly on the Stellarisiti forum, but I’ve been waiting for several days to have my account validated by an admin, to no avail… lol… 🙂

      • VirtualEnder says:

        Bahh! I feel like an idiot! That was totally it! I should have picked up on that! Thanks! Now I’m back on the right track!

      • trandi says:

        No worries, I’m really glad I could help.

        I’ve read what you say on your post, about the InterruptHandler issue, and it’s interesting… it seems that it HAS to be declared in a C file (as opposed to C++)… I get a feeling that for CCS, C++ is really a 2nd option, less well supported, due to the “C++ generates too big binary files” kind of reason… which I don’t get, as for the Arduino, which is a mere 8bit proc, they use C++ without any issues…

        Anyhow, I was really curious to see your code, but guess what… my Stellarisiti account is still not validated (argg…. what the heck is going on !?) and I can’t download it… lol…


      • VirtualEnder says:

        I put a plug in for you over there! Hopefully they’ll get it sorted out. My account just activated via email, so I’m not sure what’s going on.

        Also I’ll try to get my code posted on github tonight and I’ll post a link here and there. I added some functuionality to adjust speed a direction via the buttons and display the current clock divider for the interrupt on the screen I noticed that the larger I make the clock divider (faster the steps) the slower the system seems to come back from adjusting the interrupt. Haven’t tested it further, but it really eats up cycles. I’m sure there is some way to reduce the overhead in the interrupt, I’ll have to explore that further.

      • VirtualEnder says:

        Here’s the git repo! Email me if your interested in working with this project further!

      • trandi says:

        Great thanks.

        I’m probably missing something here, but why would you do delays INSIDE an Interrupt Handler (like “SysCtlDelay(((SysCtlClockGet() / 3) / 5000));”) ?

        It’s probably just for testing? Because you know while the CPU is inside an interrupt routine, NOTHING else happens. Even I/O shouldn’t really be done there, but delays are basically the worst thing…:)

        You should probably just set up a flag, that you would check in the main code and take appropriate action…

        But again, I’m probably missing something…


        P.S. as for working on this project, thank you for the offer, it sounds interesting, but there’s no way I will find enough free time… I’m struggling to find time to finish plenty of old and already started projects…:)

      • VirtualEnder says:

        To clarify I’m trying to basically simulate PWM using a timer, maybe this is the wrong approach.

      • trandi says:

        This is probably best asked on the Stellaris forums…

        From what I know there are already hardware PWMs on the board so you should be using those. If you still want to do it manually / in software (which is obviously not recommended) then yes you should be using a timer, BUT NOT wait in it.

        There are several options: – either you fire the timer often enough so that you have a good enough resolution, and all you do in there is test a counter or something to see if you need to pull up you pin OR you need to pull it down – either you use 2 timers one that pulls up the pin and another that pulls it down (trickier as you need to make sure they are in sync)

        In any case, the timer will do a quick check on a counter or something, the either nothing or pull up/down a pin and that’s it. No waiting or other time consuming stuff…


    • VirtualEnder says:

      It’s probably not the best way to do it, but the pulse to the stepper has to last a certain amount of time to register. That explains the slowdown I get at 3500 + clock divider. How would you recommend sending the pulse? Should I put it in a function and trigger the function on the interrupt? I’m still a little shaky on what is blocking and what is not in the Stellaris MCU.

  4. Pingback: Stellaris Launchpad library to drive the TM1638 UI board | Cool Internet Projects

  5. Pingback: Stellaris Launchpad library to drive the TM1638 UI board - Hack a Day

  6. bh says:

    Awesome. You should post your link to the Stellarisiti forums.:

  7. Dan, glad to see you are still posting! are you launching something into space?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: