3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Track How Far Your Hamster Runs

Step 11Write the Program

Now remember that we've connected DTR (pin 4) to DSR (pin 6) on the serial port through a switch that is activated every time the hamster runs once around the wheel. We can write a pretty quick program in Python that will let us set DTR and monitor DSR for when the switch is activated.

Note that I've chosen Python in this tutorial since its pretty easy to learn and use. If you're comfortable with another language and it has a library for accessing the serial port, I would suggest going with that as it will give you more flexibility with what you want to do later.

Assuming you're using Python you'll need to install a couple of things
- Python : Follow the instructions for installation on the type of system you will be using. If you haven't had too much programming experience it might be worth running through a couple tutorials. However, I have provided some code listed below.
- pySerial : To access the pins on the serial port reference above you'll need to to install this library. This allows you to "import serial" so you can connect to the serial port.

Once you have these installed, here's some code you can use to record the distance your hamster runs. I've tried to comment it as thoroughly as possibly so even beginner programmers know what's going on.

In addition to recording and printing the distance every time the wheel turns, it will write the speed and time of each revolution to a file. If the program ever crashes then you can count the number of rows and multiply that number by the circumference. Once you've downloaded the script you can run the program from the command line like this and it will write each rotation of the wheel to "progress.txt".

python hamster-serial.py progress.txt
« Previous StepDownload PDFView All StepsNext Step »
2 comments
Nov 3, 2009. 1:17 PMReCreate says:
Ummm...can  you upload it somewhere else?
May 6, 2009. 4:08 PMhaji_1369 says:
it,s good

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
0
Followers
1
Author:dduke11