Got the Raspberry Pi yesterday. I had already downloaded an installation disk image (NOOBS) and saved it to an 8GB sans disk (following the quick start guide). It was easy as.... well, something very easy.
When I got the Pi, I plugged in keyboard and mouse to 2 USBs, HDMI from Pi to TV, and network cable... then the mini USB power adapter. It started right up and went through configuration screens. I enabled SSH and changed everything from the UK to my locale and changed my password, then did the updates. Everything worked just swell.
It already has Python installed and Pygame and git. I opened a terminal window and installed the python package manager, pip:
sudo apt-get install python-pip
Then the python web framework, Flask, since I think I might use this to interface with smartphones/pads as controllers at some point:
sudo pip install flask
Then I added my git credentials to my .netrc file. I used the same ones that I put in my windows _netrc file in an older post. Something like:
cd ~
echo "machine code.google.com login me@gmail.com password [GeneratedPassword]" > .netrc
chmod 600 .netrc
Then added a folder to store my code and cloned my git repo there:
mkdir Code
cd Code
git clone https://TimKracht4@code.google.com/p/no-arms-darts/
So then I wanted to try to see if I could just plug in the dartboard via the arduino and run it on the PI. I needed another USB port for that, so I got out a powerd USB hub, plugged it into the Pi and plugged the keyboard, mouse and arduino into the hub. I loaded up the python IDE, IDLE, and opened the serial test script and ran it. It complained because it couldn't find the Serial module... so I opened the lightweight web browser, Midori, and tried to download the PySerial tarball, but I kept getting empty files.... so I tried pip, something like:
sudo pip install pyserial
Which did the trick. so I went back to IDLE and tried running the code again. This time it complained about not being able to find the "COM5" serial port. Makes sense since COM5 is on my windows laptop. To find out what pi port the duino was connected to, I first unplugged the duino from the USB hub, then checked out what all was in the /dev folder for tty connections:
ls -alt /dev/tty*
Then I plugged in the duino, waited a few seconds and ran the command again. The second time around there was a new entry, /dev/ttyusb0, so I figured this was the guy. I modified the script like so:
# ser = serial.Serial("COM5", 9600) # windows
ser = serial.Serial("/dev/ttyusb0", 9600) # *nix
Saved and ran it again and then saw the output scroll as the Pi connected to the duino, then the dartboard speaker beeped "Charge!" when it entered play mode, then correctly reported what segments I pressed on the dartboard contact film matrix thingy.
So another milestone, I successfully (and quite easily) ported the python code from my windows laptop to my Raspberry Pi and have both talking with the duino/dartboard circuit.
Just for kicks, I loaded my Jumpman intro into IDLE and it ran flawlessly.
Next steps: hardware=cut perfboard/pcb down to size and move breadboard prototype over to it. considering adding LED indicators where the 6 game buttons are --- maybe a couple RGB leds, one for connection to the game server (red not connected, yellow/orange connecting, green connected) and one for play mode (red stopped, orange paused, green playing) and then 4 more LEDs to do whatever with. Or maybe instead of 2 RGB, just 2 red, 2 orange, 2 green and use 3 separate indicators for each state... that will tie up all 6 button holes with something that is reasonably useful and I won't have to think of something else to use LEDs for, like wasting time with blinking patterns or something... although I know where you can find some sweet LED blinking code. So if I get the pcb built, then screw it into the dartboard case and close it up and hope it doesn't fall apart when I start throwing darts at it.
Next steps: software=still need to jump in and code the game engine in pygame. Have been jotting down ideas here and there, but now is the time to act, now is the time to code. Need to try to convince myself to use a simple, working design and refactor bells and whistles later. I think I want to try to auto-detect the serial port that the duino is on as a first step, then do a simple game menu maybe, and then the game play for a simple game, like around the clock.
l8r
No comments:
Post a Comment