Introduction: Touchatag+Python+Samurize Coffee Counter

Welcome to this new Instructable !

One thing I often hear while explaining basic Touchatag/Mir:ror concepts to people is that they don't seem to be much more than a glorified link and a gadget. This is totally true as far as such objects are concerned in their most basic form, Why bother put together something so complicated for tiny results ? Their real advantage lies in automation and linking unusual objects for computers to interact with.

One example I read about when I first started looking up uses RFID tags can have but haven't seen around me yet was a counter of how many times a specific RFID tag is used. This is not a native feature with Touchatags clients, in that it's not one of the applications on the website/dashboard yet yet. Until then, and with some help from a friend with a knack for Python, lots of time and lots of patience on my wife's part, I was able to wrap up that application for your Instructableing pleasure !

Today we're going to see how to use Touchatags to activate a Python script that counts how much coffee you drink a day, and use Samurize to display it on your screen. Ready, get set...Go !

Special thanks, in chronological order of involvement, go to :
Guillaume "GuiWizz" Pierron, for helping me sort out a cleaner version of the Python code ;
Christina G. Smith, for designing a nice cup of coffee ;
Nikki Pugh, for breaking this Instructable in every possible way and helping make it better.

Step 1: Requirements

For the purpose of this Instructable, you'll need :
- a Touchatag reader ;
- 2 tags ;
- a coffee mug ;
- a text editor for Python and batch files writing, such as Programmer's Notepad) ;
- a copy of Samurize ;
- the 2.6.1 version of Python ;
- you're good to go !

Step 2: Equip Your Mug With Tags

Let's start things with the easy part. Peel off touchatags and stick one under your mug, and one on the side of mug - if you're very rich ! If you're not, make the tags removable (using bluetac for example). As you can see in the pictures, I cheat by using one of my favourite Starbucks insert tumbler (and yes, I already know I drink too much coffee a day) : it's easy to tape a tag to the inside of the insert, or under the bottom screw-on cap, and to remove both before a dive in the dishwasher.

Done ? To the next step !

Step 3: Installing Samurize...

...Is a pretty straightforward process. I don't think you'll really need many pointers at that step. One important thing you can do in preparation for later is go to the Configs directory of the Samurize program, create a Coffeerize directory and write down its complete absolute path - that'll be important for later.

Step 4: Installing Python...

...is an equally straightforward process. Download the 2.6.1 version from the official site, install and check the complete path to the pythonw.exe program. Again, that'll be needed for later !

Step 5: A-codin' We Will Go !

Now it's time to write the scripts and the batch files Python and your computer will execute. We're going to create 4 different files and save them in the Coffeerize folder we created earlier then open them in Programmer's Notepad to modify them accordingly to fit your computer.

Coffeerize_reset.pyw :
file = open('Paste here the complete path to the Coffeerize folder\coffeerize.txt', 'w')
file.write('0')
file.close

Coffeerize_increase.pyw :
file = open('Paste here the complete path to the Coffeerize folder\coffeerize.txt', 'r')
data = int(file.read())
file.close()
data+=1
data = str(data)
file = open('Paste here the complete path to the Coffeerize folder\coffeerize.txt', 'w')
file.write(data)
file.close()

Coffeerize_reset.bat :
[Insert here the path to Pythonw.exe, removing the brackets]\pythonw.exe "Paste here the complete path to the Coffeerize folder\coffeerize_reset.pyw"

Coffeerize_increase.bat :
[Insert here the path to Pythonw.exe, removing the brackets]\pythonw.exe "Paste here the complete path to the Coffeerize folder\coffeerize_increase.pyw"

Check the code for each file once. Twice. Three times : there will be mistakes, unless you're already very familiar with Python and programming (in which case I'm sure you can write a more efficient version of this code - if so, feel free to post it in the comments !). In order to test the scripts, double-click on the .bat files starting with Coffeerize_reset.bat : this should create a Coffeerize.txt file which, if you open it right now, has a single number in it : 0. Now double click on the Coffeerize_increase.bat file : if all works correctly, everytime you double-click the number in the Coffeerize.txt file should increase by 1.

Everything working ? Then on to the next step !

Step 6: Display the Content of the Text File in Samurize

Having a text file which displays how many times you've been drinking coffee until you reset it, but it's not super-interesting if you have to click it open all the time. That's where Samurize comes into play, with its ability to refresh files regularly and display their content : we're going to use it to display the content of the coffeerize.txt file on the desktop following the method you can find in the awesome tutorial over at Samurize.com's.

Since Samurize gives you many options in customization, you also get to display the counter on top of an image - I'm using a coffee mug sketched by Christina Smith from 5sizes2small Studios for decoration !

And now on to the last step.

Step 7: Associating the Touchatags With the .bat Files

If you've tried double-clicking on the .pyw files, you'll have noticed they do exactly the same thing as the .bat files. Why make such files, then ? Simply because the Touchatag client doesn't seem to be able to interact directly with them (still need to test that with the latest client). Which is why we're going to create 2 applications based on Web Link application that we'll point to the .bat files directly : the way I chose it, the tag on the bottom of the mug adds to the count and the tag on the side resets the counter to 0.

Step 8: Conclusion

Of course, the purpose of this Instructable was not so much make you design this precise application as to suggest ways to use RFID tags and integrate with your everyday use of a computer - and a good excuse to learn Python !

With a little tweaking, you could easily transform this counter to make it give you warnings as soon as you reach a certain number of cooffee mugs, or you could make it call your lover and count how many times you do so a day - perfect for the Valentines season !

Remember, the only limit is your imagination !