Today I was bored and I remembered this video I saw awhile back that had a TF2 kill counter using an Arduino. I’ve been playing TF2 a lot recently (since it became free to play, I’ve been doing a lot better in comparison) so I figured it would be cool to implement something like that. I could’ve done it with LEDs or even GLCD screens (actually it might be cool to do something with the LoLShield), but since Cubey’s been sitting on my desk unused for the past few months, I thought I’d put him to use. Cubey gradually turns around as I get more kills, and after a certain point, he starts moving his ears. He turns back around in disappointment when I die, though.
I used Python to read the config.log file located in the tf folder (on mine, it’s “C:\Program Files (x86)\Steam\steamapps\your_username_here\team fortress 2\tf”). It reads the latest lines and looks for “A killed B” or “A suicided” and sends either a + to the Arduino when A kills someone or it sends a 0 when A is killed by someone else or kills themself. The Arduino then reads from the serial port one character at a time and makes the Cubey servos move accordingly.
Python and Arduino code are in this zip file.
I modified the scrolling text program some more, and was able to get it to display text based on received serial input. Then I wrote a Python script to get random entries from various RSS feeds (In the video above, the RSS feeds were the Twitter favorites of various people) and send them to a serial port (to be received by the Arduino). One issue was that sometimes the text was too long for the Arduino’s 128-byte serial buffer, so it would get cut off at the end. To resolve this, in the Python script, I split the text into multiple parts and had it wait for the Arduino to request the next part before sending it.
The Arduino code works on its own; you can use the serial monitor in the Arduino compiler to send text to it, but if it’s more than 128 characters, it’ll get cut off. Just remember to have it add a newline character to the end of your input. Also, removing the lines that say “Serial.write(GET_NEW);” and “Serial.write(GET_MORE);” would be a good idea, if you don’t plan on using an external program to provide the input.
(Edit: I’ve updated the code so that it doesn’t spam the serial monitor if you don’t input any text. Also the python code has many flaws and sometimes it crashes, whoops)
You can download the source code here.
I found this thing about making an IRC bot in Python, and thought: since I know how to send serial information from Python using pySerial and how to receive serial information on the Arduino as well as knowing how to output text on a GLCD, why not make an Arduino program that shows IRC text on a GLCD?
Basically, the IRC bot connects to a server and channel you choose, and it just stays in there, sending serial information to the Arduino. Using the GLCD library 3 beta, the Arduino simply prints each character received to a text area and checks for newlines.
The IRC bot isn’t that great (probably still needs a lot of work) but it gets the job done.
My final project for the Python summer course was “Diff EQ Wars”, a game/simulation of units on a battlefield using graphics from Advance Wars. It uses ordinary differential equations for the motion and health of the units, with terms based on certain conditions (i.e. is the unit near an enemy? / is the unit near a base? / is the unit in a forest? / etc).
During summer 2010, I took a course where we learned how to program in python; specifically for finding numerical solutions for ordinary differential equations using Runge-Kutta. Most of the things we did were physics-related, though for the final project it didn’t have to be.
I learned quite a bit from this course; Python is really easy to use and understand. Before this, the only things I knew how to program were the things we learned in CS102 (not very much; our hardest assignment for that class was to write a program that converted formatted data to a more readable format), and some really simple ActionScript things for Flash.
If you’d like to see the programs I wrote for this class, you can find them here. It was written in Python 3.1 (I think) and requires pygame. The final project is in that zip file as well, but I think I’ll make a separate post for that.
Also important note: the code is incredibly inefficient because this was before I learned “proper” programming methods and efficiency, I kinda just did what worked and disregarded time complexity and the overhead associated with making and filling huge multidimensional arrays.
May 2017 S M T W T F S « Jun 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31