I have completed a Python program that uses the Stockfish chess engine with rules governed by the ChessBoard Python module. The code allows the user to choose whether to play black or white, has an adjustable skill level, and lets the chess engine look 15 moves deep. The program will also check the legality of each move made and accounts for special moves such as en passant, castling, and pawn promotion. It also checks for stalemates, the 50 move rule, and the three move repetition rule. In its current iteration, the program prints out the board after each move to make sure it is working correctly. Here is a copy of the program for Python 2.7. You must have the Stockfish engine installed as well as the ChessBoard module with the code pointed to the appropriate places. Moves must be entered in algebraic notation with quotes. For example, a typical opening move may be 'e2e4', castling may be 'e1g1', a pawn promotion may be 'e7e8q', and en passant may look like 'e5d6'.
I have had it in my head for a while to build a robotic chess board, a chess board where I play against a computer that controls a robotic arm of some sort that moves real pieces on a real board. The "thinking" will be done on a Raspberry Pi computer, which I bought this week as a graduate gift to myself for having finished my PhD program. The arm will be controlled by an Arduino microcontroller. I have already learned how to get Arduino and Raspberry Pi to communicate with each other by reading Simon Monk's nice book Programming the Raspberry Pi: Getting Started with Python. The Arduino and Raspberry Pi communicate nicely though the serial port using the PySerial package. I have tested this out and it works wonderfully. I must write the Arduino code on my Mac though because the Arduino software released for the Linux Debian operating system is a very old version.
For the chess engine, I have decided to use Stockfish, which uses the Universal Chess Interface. It is consistently rate one of the strongest chess engines. The creators of Stockfish have not provided any documentation for their engine, and the Universal Chess Interface was nontrivial to decipher. Therefore, it took me some time to figure out how to communicate with Stockfish through the terminal.
Tonight, I was able to write a proof-of-concept Python program which let me play chess with Stockfish through the Python shell. This is the first step in writing the software for a USB chessboard. I have included the Python code below. Of course, the Stockfish engine must be installed first.
#This code talks to the Stockfish Chess Engine. Entries are to be made in algebraic
#chess notation (eg. e2e4). Stockfish is set to think for a maximum of 1 sec.
chess = r'/Applications/stockfish-4-mac/Mac/stockfish-4-64'.split()['linux' in sys.platform]
import subprocess as S
getprompt = 'isready'
proc= S.Popen(chess, stdin=S.PIPE, stdout=S.PIPE, bufsize=1, universal_newlines=True)
while True :
text = proc.stdout.readline().strip()
if text == "uciok":
print('Choose skill level (0-20):')
proc.stdin.write('setoption name Skill Level value '+skillLevel+'\n')
moveList='position startpos moves '
proc.stdin.write('go movetime 1000\n')
while True :
text = proc.stdout.readline().strip()
if text[0:8] == 'bestmove':
This morning, I clipped the perf board from the connectors, resoldered a few loose connections, and reattached the audio jacks. I removed the push switch entirely since I didn't wire it up correctly to start it. I had it in an on/off configuration instead of an on/bypass. After all this, the pedal magically worked! There must have been a loose connection somewhere, or I had wired the switched so poorly that I was unknowingly shorting the circuit.
I am posting the promised video. This one is shot by a 5 year old. My apologies, but it was either that or hearing "What are you doing? What are you doing? What are you doing?" throughout the duration of the video. The video is short and sonically unknind, but it demonstrates that the pedal works. I am also including a short audio clip of a few short riffs showing the range of the pedal. I'm sure you can hear my kids talking in the background. Also, I got distracted at the end and you can hear why.
Next step it so make some more effects and put them all in the same case with a selector switch of some sort. Exciting!
Today, I attempted to make a prototype of my little fuzzbox from before. I figured that if I put it in some shielded box, that might cut out some of the radio noise. Also, when I fired the fuzzbox up today, the interference wasn't nearly as bad and the distortion was much louder. I had resoldered some of the connections so perhaps that was the issue.
I purchased a project box, a push switch, and a handful of NPN transistors from Radio Shack on the way home from working at the library. I swapped out the transistors and replaced the diodes with different sorts of LEDs but the fuzz box sounded pretty much the same no matter what I did. I like the sound. It only really makes a difference through the middle pickup on my Fender Highway One Stratocaster and even then, it is most noticeable on the low notes. It is a very limited pedal.
I decided to go ahead and transfer my circuit to a perf board. After drilling out the project box, soldering the perf board, and wiring up the jacks and the switch, the pedal does not work. I spent over an hour troubleshooting and found some mistakes, but after fixing them, the pedal still does not work. I think I will just start again from scratch as I have all the parts. Anyway, I thought I would share some photos from the adventure. When I have a working pedal, I will make a video.
Also, I'm not a fan of soldering.
Today, I put about an hour of effort into creating a guitar effect pedal. I figured I would start small and aimed to reproduce Mike Hayworth's simple distortion pedal since I had most of the parts already. I picked up some diodes, the mono jacks, and the NPN transistor from the Radio Shack down the street.
The first thing I learned when putting the circuit together is that soldering copper wire to the mono jacks is a pain. I could not get the solder to stick to the jack for the life of me. I must be missing some Soldering 101 skills.
After assembling the circuit, I did some minor troubleshooting (including realizing I neglected the k at the end of the resistor values--hot transistor is hot) and plugged it in between my guitar and amp to find a very pleasant fuzz effect. I would include a video, but there are two things I would like to troubleshoot. The first is that the pedal is not very loud so I need to figure out how to boost the outgoing signal. The second and most important problem is that the pedal is a fantastic radio receiver for a local station. It was very hard to her the pedal over the obnoxious radio broadcast that was being amplified through my tube amp. Once I resolve those two problems, I will permanently solder the project into a perf board and make a video. My overall goal is to make several different pedals and to be able to select though them, possibly with an Arduino interface. Below is a photo of the project so far (note, the 9V batter is not attached). Pretty simple, no?
I have spent the last month at Wash U, finishing up some work for my dissertation for a late August defense. As a result, all things Arduino related are on the back burner. It has given me a little time to think about what I would like to do with my Arduino though.
I think I have finally hit the point where I am not learning many new things from the Arduino projects in the Evil Genius book. As a result, I don't suspect I will be completing too many more parts of The Great Arduino Project. I would like to do one small projects with an LCD display I received for Christmas just to see how that works. Then, I will either work on a lo-fi guitar effects pedal or a LED array of some sort. I have it in my head that I could make a Gameboy emulator where the screen is a giant RBG LED array. Dissertation first I guess. Anyway, there are great Arduino-related things coming in the hopefully-not-too-distant future.
Time to complete: 2 hours over several sittings
Earlier, I wrote about an LED Dice project that used seven LEDs to simulate the dots on a die. Today's project is very similar. Here, we are simulating the rolling of two dice with a 2-digit seven-segment LED. The dice roll when the push-to-make switch is held. This project took me an unreasonably long time to complete, but not because the project itself was difficult. The LED display I had did not have a readily available pin-out diagram and did not match the one provided in the book. Also, I found a shorting wire half way through the process. The excessive time comes almost exclusively from having to derive the pin-out diagram for the display and obsessively checking the wiring. The rest of the project took about 30 minutes to complete.
The wiring of the LED display was a little cumbersome because my breadboard was too small for the project. In order to alleviate some of the cramped conditions, I found some longer wires to branch out to a second small breadboard. This helped immensely in troubleshooting the LED display. Having some space to work with in the circuit allowed for rapid testing of the pins. In the book, the LED display is connected directly to the Arduino through a single resistor from each pin. This would have made troubleshooting the display nearly impossible.
When I showed my nine year old son this project, his response was "Didn't you already do this?" I guess he wasn't impressed. He did, however, inquire as to how I was able to generate the random numbers. He listened to my explanation for about five seconds before wandering off to pretend to battle with his brother.
Below is a video of the working dice.
Time to Complete: 30 min
The Light Harp is essentially a theramin with light sensors controlling the volume and pitch of sound. I only had one light sensor that worked in the visible spectrum (the top one in the photo). I think the one on the bottom is a UV sensor. Needless to say, it didn't work to control the volume. The top sensor worked well to control the pitch as the video below demonstrates. You can also see my stylish Angry Birds bandage covering up my attempt to slice off my thumb while doing the dishes.
We were introduced to the speaker and the audio amplifier in the Tune Player project. The light sensor makes its debut in this project, referred to as the LDR. The program for this experiment is similar to the previous project but with the appropriate corrections to allow for the light sensors to control the pitch and volume.
As you can see in the video, the right light sensor controls the pitch very well, but the sensor on the left does nothing. I wasn't so what the light sensor on the left was rated for but after looking at the package, I'm pretty sure it's a UV sensor. It's times like these that make me wish I had little electronics stash with tons of sensors and such. Sadly, at the moment, that is cost-prohibitive. Someone (me) needs to hurry up and graduate so he can get an adult job.
Time to Complete: 30 minutes
This project is awesome. With just a handful of parts, I have assembled a crappy synthesizer the can play any tune that is programmed into it. In the video below, the Arduino plays the default song "Jingle Bells". The potentiometer is used as a volume knob.
The program for the project is interesting in that each note must be separately constructed from the appropriate sine wave, and the duration of each note must be adjusted so they are all roughly equal. The author has taken the time to create two octaves worth of notes. The song below is played in the higher octave. After I took the video, I played it in the lower octave, which sounded better. Since the notes are already defined, it's possible to play any song by simply writing the appropriate notes and spaces to account for the duration of the notes and silences between them. It would also be simple to add the accidentals to the array of available notes. By default, the only available notes are two octaves of ABCDEFG. Perhaps I will take the time to add the accidentals and program a new tune. I also think I made need to make some adjustments to tune the tune player. "Jingle Bells" sounds pretty bad.
Time to Complete: 30 minutes
The VU Meter records the volume of sound picked up by the electret microphone and displays the intensity in the LED bar graph. There are two modes. The first displays the intensity in real time, and the second mode records only the highest intensity picked up by the microphone. The push-to-make switch is used to toggle between the modes.
The most interesting part of the circuity in this project is in the wiring of the microphone and the transistor used to amplify the signal from the mic. The transistor is wired in a collector-feedback bias arrangement. In order to avoid a discreet switching of the transistor on an off, part of the voltage at the collector is used to bias the transistor. This lets the transistor amplify the signal from the microphone in a linear fashion. Clever. There are some subtleties in the program to ensure that the transistor bias does not permanently illuminate the button bars of the LED. Other than that, the program is pretty straight-forward.
My eldest son helped me out with this video this time by clapping into the microphone as I filmed.