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!

Saturday, March 30, 2013

Ham Radio

My mentor is a big ham radio enthusiast. He has finally convinced me to take the plunge.

So I picked this book up. Its amazing. Literally everything you need to know about RF

Thursday, March 28, 2013

Game Dev Story: Sal Style

Mobile phones have opened a new market for developers. The prospect of making apps/games has never been more exciting. The barrier to making your app or game has become so low that almost anyone can do it.

I cant help but feel excited about it too. I have always wanted to get into game development and i am now finally exploring this amazing field. I dont know if ill ever make something commercially available, but the prospect of writing something on my computer and running it on my Galaxy Nexus is very very, and i mean very appealing.

I have been fiddling around with Libgdx and I am currently learning the framework and the nuances of game development. However these activities occur during my spare time which i do not have a lot of, so im afraid the game development posts will not be as frequent as i want them to be. 

But there will be posts. After all, just like everyone else developing, I have a million dollar idea too ;)

No post is complete without a screenshot of what your working on. Here is my first attempt at an educational platformer that i intend on making. It will teach people electronics as they play. 

But thats a while away, right now im just fiddling around with putting things on the screen and animating them. Heres an running animation of me running on a couple of red blocks.




This took a surprising amount of work. The art is the most painful process, since im no artist. But heck, its fricking fun!

Stay posted for more!

Building a 3A Constant Current Load Box on the Fly!

I needed to get one of the boards i made tested by a third party for certification.

I was surprised to find out that the company that was supposed verify that the board meet all the necessary standards did not have a constant current load box. Well, having a constant load was one of the criteria.

Renting one involved long lead times...

So what was the quickest solution? Build one of my own and ship it over! 

Here are the features of the load box that im going to share with you.

1) 3A constant current load.
2) 6.7V UVLO (it will require atleast 6.7V to turn on)
3) Does not require any battery.

To build this load box you will require the following
  • 1x LT1635 (Micropower Rail-to-Rail Op Amp and Reference)
  • 1x 6.2V Zener
  • 1x 12V Zener
  • 1x 4148 Diode
  • 2x MUR460 Diodes
  • 2x 2n3904 NPN Transistors
  • 2x FQA140N10 MOSFET
  • 1x 0.1uF Ceramic Capacitor
  • 4x 100k 1/4W Resistors
  • 1x 130k 1/4W Resistor
  • 4x 10k 1/4W Resistors
  • 2x 1k 1/4W Resistors
  • 2x 10Ohm 1/4W Resistors
  • 1x 1M 1/4W Resistor
  • 8x 470mOhm 1W Resistors
  • 2x Heatsinks atleast 3.1 C/W
Lets get to it!

I will assume that the reader interested in building a load box is familiar with electronics and can read schematics so i wont spend time on that. Instead ill provide you with the schematic and explain how the circuit works.

Be sure to put it in an enclosure. The heat sinks will get pretty hot, so its important that they get adequate cooling, if they stick out of the box like mine do then be sure to be careful around them. 

3A Constant Current Load Box





























Our operating voltage is 12V. Q3 and Q4 each have half of the total current flowing through them (1.5A). R14 - R17 are chosen such that the opamp biases the FETs to always have 1.5A flowing through each one of them. 

To set the current in Q3 for example, we set the voltage at the source of Q3 to be 3V. Hence our sense resistors (R14 - R17) should have a total value of 3/1.5 = 2Ohms. Since 1.5A would be flowing through 2Ohms, the total power dissipation would be around 4.5W. So in order to get around that we pick smaller resistors with higher wattage. Four 470mOhm 1W resistors do the job nicely, they add up to 2V and the power dissipation in each resistor is now reduced to (1.5)^2 * (470mOhm) = 1W.

The same strategy is implemented for Q4. 

R8 and R9 provide feedback paths to the inverting terminal of the LT1635. In order for the Opamp to keep the source of these FETs biased to 3V we need to set the non-inverting terminal to 3V as well. This is done by the resistor divider at the output of the reference. If the output of the reference is at 3V, 140k and 10k drop this voltage down to 200mV and feed it to the reference Opamp. This makes the Opamp very happy indeed :)

So we just made a constant current source. However, what we want is a constant current source that needs no external power source except the load and that turns on once the V+ voltage is higher than 6-7V. We achieve this with the help of Q2, and Q1.

Q2 remains on for as long as Q1 stays off. This is due to the pullup resistor R2.  This shorts the supply of the Opamp to GND. As a result the Opamp cannot bias the two MOSFETs and they remain off. Once the voltage at VIN rises above the zener clamp voltage of 6.2V + 0.7V(of D3) the clamp turns on and biases Q1.

Q1 turns on and shorts the base of Q2 to GND. As a result Q2 turns off and a resistive divider between R3, R4 and R5 beings the voltage down to a safe value for the LT1635 to operate at. D2 prevents the input to the LT1635 from rising higher than 12V incase a transient event takes VIN to a high voltage.

R10 and R11 isolate the output of the Opamp from the gate capacitances of the FETs. The reason why those were put there were because i was seeing the op amp oscillate, the loop did not like seeing those capacitances :(

Oh and if your wondering what purpose D3, D4 and D5 serve, they are there to prevent the circuit from frying if you accidentally hook up the load box the wrong way. ;)

And there you have it. Your very own load box! 







I put mine in a plastic case, i think it looks much cooler when you can see the guts of everything. :D


Lets see it in action...
video


Notice how the current starts flowing after we cross the 6.7V threshold and ramps up till we reach our set voltage of 12V. Increasing the voltage further no longer makes a difference and the current remains constant.

You can always make the load variable by adding 10k potentiometer instead of R6. I plan on implementing that which is why i have the holes drilled in the front.







Friday, March 22, 2013

WallCrawller Update:


I have good news and bad news.

The good news is that the gears arrived and i managed to free some time to continue with the project.

Heres the bad news... the shaft that holds the gears has become loose. So the gears slip now. When the robot starts crawling forward on the whiteboard, the force on the magnetic wheels causes the shaft to bend backwards. This pops the gear teeth to pop out and get stuck and stall the motor.

It seems i will need to order a new Servo...

=(

Sunday, March 3, 2013

Wall Crawler Update: Never use superglue near a servo..

Im pretty annoyed. On thursday i decided to stay late after work and finish up the wallcrawler.

Here is a video of it crawling on the whiteboard on my wall. Keep in mind that the "pulsed" movement is intentional. I want to keep it like that in the beginning as i am unsure about the level of control i will have during turning and following black lines.

Notice how the left wheel is sleeping, this is because the shaft was slipping on the gears i.e the gears were rotating but the shaft was not.



video
Obviously i needed to fix this. I took out my trusty Krazy Glue and proceeded to glue the shaft more securely to the top gear. There was a piece of solidified glue that was near the end of the tube and it was blocking the way.

You can imagine what happened next. I squeezed harder and ended up squirting super glue all over the gears. They were totally destroyed.

I just re-ordered some new gears and once they arrive we will continue on with the prototyping.

In the mean time ill bounce onto my backup project (more on that later).

Friday, February 22, 2013

Wall Crawler: Sensor Calibration

I was initially worried that the IR sensor would not give reliable readings when it moves over a line drawn by an erasable marker.

This is because the lines of drawn by an erasable marker are not consistent and to top it off i had concerns regarding the difference in infrared light reflected back to the sensor when moving from white to black on a shiny reflective surface such as a whiteboard.

After some tests today im glad to report that i can still get reliable readings from the sensor when moving from a white glossy surface to a darker glossy surface.

Here is a video showing the sensor in action. Im using my nephews writing board and i have programmed the Arduino to move the servo's forward only when the sensor is over a black line. When the sensor moves away from the black line, the Arduino will stop the servo's from moving.

video

The basic layout at the moment is on a piece of cardboard. Here is how i am laying things out
The code used for this test is given below:

Monday, February 11, 2013

Thought Clusters - JSON

Recently I've become busy with a lot of work projects. In the course of doing my work, Ive had ideas of different tools i could build to make my life easier (next time i have a similar project). So these tools have taken up a significant amount of my time away from my "blog" projects but hopefully ill be able to share some of the tools here (ill have to find out about that).

Even though work has kept me busy, there still is something new and technically cool that i learn every week. So why not write about that when im not writing about my projects? Ill call these posts thought clusters, because they are not meant to build upon each other, rather these posts are meant to stand on their own talking about some aspect of technology.

This post, well talk about JSON.

What is JSON and why should i care?

JSON stands for Javascript Object Notation.  From the name you must have guessed that it is native to Javascript. It's a lightweight and portable format used for data interchanging.

You can think of it as a format to represent data (objects/arrays etc). JSON is becoming increasingly popular over XML since it requires less markup and its output is more readable for humans and machines as well as not as lengthy.

Being a hardware guy i probably would never have come across JSON if i wasnt interested in video game programming. Ive recently dived into learning libgdx, which is a videogame development framework (i told you that i wasnt kidding when i said im juggling a lot of things at the same time!)

I realized that many of the people using libgdx would serialize data in JSON format whenever they would create a save or a player profile etc. Its a preferred method of reading and writing data as its smaller than XML as well as faster and easier to parse. So thats why i care about JSON.

Please note that while i did mention that JSON is native to JavaScript, it is still language independent. There is a plethora of JSON parsers for many different programming languages.

Okay but how is it structured?

JSON is structured primarily using name value pairs. Let's illustrate this with the help of an example. Lets say we are making a video game and its a video game about ninjas (we all love ninjas). The ninja object has the following fields.

 String name = "Ryu";   
 String giColor = "BLACK";   
 int sobrietyLevel = 7; // Ever seen drunken fist? our ninja likes his drink.  
 List<String> weapons = { "shuriken", "sword", "spear" }; 

So in JSON this object would first be surrounded by {} braces. All objects are represented by curly braces.

The JSON representation would be as follows:

 {  
    "name": "Ryu",  
    "giColor": "Black",  
    "sobrietyLevel": 7,  
    "weapons": [  
      "shuriken",  
      "sword",  
      "spear"  
    ]  
  }  

As you can see the whole object is represented by curly braces, the variables are represented as keyvalue pairs. The array is represented with the use of square brackets.

Keep in mind that im comparing Java notation with Javascript so the conversion is possible with a suitable parser.

This post is meant to be a brief introduction to JSON. If it piqued your interest and you want to read more, please refer to the following links

http://www.json.org/
http://code.drewwilson.com/entry/an-introduction-to-json