Sals Hacker Space

Sal's Hacker Space

Saturday, April 20, 2013

Game Dev Story: Work on Side Walk Empire

I recently attended the +Udacity HTML5 Game Development study group hosted by +Colt McAnlis , +Sean Bennett and +Peter Lubbers  in San Francisco.

It was an awesome experience as there was a lot to learn not only about HTML5 but also about game development in general. Colts rants were very very instructional.

I met +Derek Duarte there and two of us immediately hit off. We started building a game for the HTML5 competition, but unfortunately due to work and personal reasons were unable to finish in time for the contest.

But all was not lost. We have decided to continue on with the game and eventually launch it on the web and Android.

The game is a coffee shop management game where you try to manage your inventory based on customer preferences. The goal is to make the most amount of money you can and build a coffee empire all over the city. (incidentally most of the dev work for this game happened in a coffee shop... how... quaint)

It is based on the popular Side Walk Empire comic strip made by +Eddie Ahn. You can follow his work here: http://www.ehacomics.com/

Here is a brief video of what the prototype currently looks like:

I am running this on the desktop with the help of the wonderful Libgdx by +Mario Zechner and his team of snazzy code monkeys.

A lot of work still needs to be done on this some of which is:


  • New Levels / Shops
  • Improved Animation
  • Optimization 
  • ....
...and the list goes on.

Dev work on this will continue and we will hope to see a finished product by the end of the year.

Props to Udacity and Libgdx that made this possible.


Note: I am aware of the resolution issues of the video on this page. They will be fixed as soon as possible.  

Sunday, April 14, 2013

Coming Up! Bluetoothy Goodness

So i just got these and have been playing around with them..


Bluetooth Module, Arduino Pro Mini, and Servos

The bluetooth module i got off ebay for $8 and the Arduino pro mini is easy to find. The servos in the picture are from hobbyking.

Ill have a tutorial up on how to control two Arduino pins through bluetooth. 

The possibilities for this are endless as far as home automation goes. What the upcoming tutorial will provide is a means to use your android phone to connect to the bluetooth module and control any of the arduino pins independently. You can control servos for robots, RGB leds etc.

The tutorial will cover the following:

1) Making an Android Application to send data over Bluetooth 
2) Sending data over bluetooth and through serial to communicate with the Arduino
3) Parsing that data so that the Arduino can figure out which pin to control and control its PWM out according to the data being sent (we will have vertical sliders that will change the duty cycle of the PWM signals depending on where the slider is)

We wont be using any of the current bluetooth to android applications out in the market, although we could and you should definitely check them out.

The idea behind this would be to give readers who have not explored android yet to see how easy it is to get started making your own applications.


Expect it to be up within a week :)






Saturday, April 6, 2013

Google+ News-Feed LCD Display

If you search online for LCD RSS feed readers, youll notice that most of them target twitter. Wheres the love for Google+? Right here.

I wanted to make a display, which i could put on my desk, that would stream Google+ feeds. That way i could resist the urge to log onto Google+. 

You will require the following for this project:

1) 1x Arduino Uno
2) 1x LCD Display. Anything compatible with the Hitachi HD44780 driver will work. 
3) Some jumper wire. 
4) Basic knowledge of python and HTML
5) Google Plus Developer Key. 

To find out how to get your developer key go here: https://developers.google.com/+/api/oauth#apikey

NOTE: Depending on whether you have a perf-board or a bare Arduino shield such as the maker shield, you might or might not need a soldering iron and some hookup wire. 

How it all works:


We will be using Python and the Google Plus API to pull activities that people that we want to stalk....er follow post. The Python script will store all activites onto a file and then read it line by line and send it in chunks to the Arduino through serial communication. The Arduino would then display the information on the LCD screen. 

We could have sent directly without saving it to a file but during debugging i was getting some goofy characters on the console screen if i directly printed data to it. Oddly enough saving the information to a file and then reading from it fixed everything. 

We will send the information in chunks of 64 char because that is the limit of the Arduino's Serial RX Buffer. Sending information in a continuous stream could result in losing data. The Arduino could be saving the information in the buffer to a char array and at the same time the python script could be sending the rest of the data through serial. That would be bad.

That being said, lets start building.

Connecting the LCD Screen to the Arduino:


This process is fairly painless. I followed the following tutorial:
http://arduino.cc/en/Tutorial/LiquidCrystal
I suggest you do the same. Once your setup come back.


Accessing Google+ using Python



Pulling information from Google+ is relatively simple. At the time of writing these API calls are read only.


You will need to install the PySerial module to be able to transmit over Serial.

This can be found here: http://pyserial.sourceforge.net/

The httplib2 library to create your http object found here: https://code.google.com/p/httplib2/


The Google+ API python starter found here: https://code.google.com/p/google-api-python-client/


Here is the code:



The code is pretty self explanatory. Ive tried to comment it as best as i can. 
Heres a brief summary of whats happening:
An http object is created to pull information of interest from Google+. Make sure you use your developer API key. A dictionary holds information of the pages to be displayed on the LCD screen. You can enter your own pages here. A random number is generated to pick a random index in the dictionary and pull that index's contents and display name and save them to a file. The strip function strips all HTML elements from the content.

Once information has been stored to the file, it is opened and is read back line by line (You dont need to close and open it like i did). Every time a line is read it is broken up into chunks of 64 characters. This is because the RX buffer of the Arduino can only hold 64 characters at a time. If data was sent in a continuous stream then the buffer would overflow and some data would be lost.

If the data is very large it will be transferred a maximum of 6 times. This is because of the small LCD i am using.

Once a line has been transmitted, the script will wait for the Arduino to request another line by sending the 'n' character.

Once all information has been read, the file is closed before the script is terminated. This script can be scheduled to run at specific intervals. I have set it up to run every 30mins.

Reading from Serial with the Arduino


Now that we are sending data through the serial port, lets read it with the Arduino.


Here is the code, Ill explain how it works below




Upon power up the Arduino displays a welcome message and then waits for data from the serial port. If 10 seconds pass and no data has arrived it sends a request for the next line. Ill explain why it was done this way later on.

Once the Arduino receives a ready bit from the python script it gets ready to receive data from the python script. It receives data in chunks of 64 bits and tracks the time from when it first started receiving data. It waits for 10 seconds till all data has arrives and then displays it on the screen. If the data is longer than the screen width then it scrolls it across the screen. 


Once its done scrolling it requests for the next line from the python file. 

During testing i found that sometimes the python script would keep waiting for the request to transmit the next line. To prevent the script from waiting forever, the arduino sends another request if it has not received anything for more than 10 seconds. 

And thats pretty much it.


Lets see how it works!




video


Hope you guys enjoy!