Tuesday, June 24, 2008

Modify PAL Atari 2600 for S-Video output.

I got an Atari 2600 from ebay some time last year 2006. It's one of those "vader" editions. Unlike the one I had growing up (which was a NTSC model from the US), this one is a PAL model. After hooking up the antenna to the TV, I was ready to play some retro games... or so I thought.

The PAL unit came with an IEC 169-2 connector (no it wasn't RCA). I did recall that the NTSC unit came with a TV/GAME switch box so that you can choose between antenna to watch TV or your game but the PAL unit didn't come with one. The back of the TV also had the same anttena connector so I just plugged it in.

Then I spent hours trying to tune the TV to get the picture to come out clear... I tried all the different PAL systems and B/G came out the best (others had bad/no audio, no colour, etc). The best picture I got was washed out, and had some snow in the background.





Now, I was thinking that somewhere inside the unit the console probably works with some kind of composite signal, and it might just have a bad RF modulator. Or maybe the coax cable was shot? At any rate I looked around the internet for a possible "video out" solution. I found something better. S-Video. From this site: http://www.atariage.com/2600/faq/index.html?SystemID=2600#composite, a circuit was published. This isn't exactly the simplest of circuits, there's 2 other solutions I found, one involves just a bunch of resistors, and the other was the same mod without the IC. But where's the fun in that? Besides this circuit also isolates the video circuit from the 2600's circuits, so if I were to do something stupid, like feed the s-video port some voltage, or hook it up to an ADB (apple desktop bus) port, it will only affect the video circuits I added. Plus, it doesn't put any load on the circuits like the other mods.
Since the article already explains what you need to do in detail, I'm not going to repeat all of that here. After obtaining the required materials this is how it ended up looking. This was the original RF cabling, internally it was RCA:


This was the main board with the shielding in place:

You have to untwist 5 of these to remove the shielding:

I used wire wrap wire to connect the circuit to the connection points. I did not make any changes to the existing circuit so i can revert it back to the original condition if I ever decide:



I made the output cable long, like the original RF cable so you can pull the console far from the TV, since the controller cables are so short.


It's time to hook it up to the TV


Now the moment of truth:







That was definitely a lot better than the RF cable. Well I have to assemble the unit back together and try out some other games:

Monday, June 23, 2008

Rebuild a laptop Li-ion battery pack

Warning!!! If you are not completely sure what you are doing, don't apply what is described below. In any case I am not responsible in any way to the consequences that this guide may have. Read it at your own risk. Please do not proceed if you don't agree with the above.

After having read a different how-to article on the same topic:

I decided to do some repairs on a similar laptop. This was a Fujitsu Lifebook S6120. The battery wouldn't charge anymore and after 5 to 10 minutes of attempting to charge it the onboard LCD displays a "shorted battery" error:



So, following the directions in the electronics-lab article, I proceeded to disassemble the battery:

Unfortunately for me, it contained very different cells. And to make things worse, there are no markings on the cells whatsoever, just (what seems to be) red shrink tube and some tape:

After doing some research I found out that these cells are called "18650 Lithium-ion cells". A few more searches and I found a company selling them:


Make sure you order the non-protected ones as the protected ones have a built in circuit that cuts off power when you go below a certain voltage, this circuit is already part of the battery pack and would probably cause problems if you have two of them.

After waiting around 2 weeks, this arrived in the post:

The package arrived opened so customs must have x-rayed it and checked it just to make sure. (It might look like dynamite in the x-ray, who knows, better safe than sorry).
Now, slowly pry out the old batteries, there are some double-sided tape holding them to the battery pack case:



Test fitting it just to make sure it does (fit):


After taking more pictures and noting down the polarity of the original batteries:



It's time to take the whole thing apart. Use a screwdriver and/or pliers to remove all the connectors. Try your best to keep them all intact:


Next would be to transfer all the tapes and insulators to the new batteries (keep them the same way you took them off). The next part involves attaching the connectors back on the batteries, ideally you would use a device for welding the tabs to the cells, but I don't have one of those. Instead I am going to solder them to the battery. I have read a lot of warnings that extreme heat (like that from a soldering iron) can destroy a lithium-ion battery and even cause explosions. What I did was wrap the cells in a moist cloth and not apply more heat than necessary. I also sanded down the contacts and applied soldering paste before soldering. I REPEAT: If you apply too much heat for too long, you could destroy the cells and/or cause an explosion. Ok, with the unpleasant stuff out of the way, we connect the cells the same way we took the connectors off the original cells:





Then put them back in the battery pack case. Note that because the solder was a tad thicker than what was originally there, you might have to force them in. There should be enough space there to still fit the new cells in. Note that you have to return all the insulators/cardboard pieces back where they came from. In the last photo above, this will cause a short (and a possible explosion) if you do not.

Then, to glue the case back together, I applied a small amount of epoxy all around the are and pressed it down with a phone book.



That's it. After plugging the battery in, it's working again. I also did a battery recalibration so that ACPI would show the correct charge level. This varies with different laptops and have their own recalibration procedures, but generally, you turn off all energy saving settings and fully charge the battery and leave it plugged 2 to 3 hours even after it says full. Then completely discharge it until the laptop turns off. Note that this will not damage the battery since at 0% reading the cells actually still have some charge left in them but the protection circuit cuts it off before real damage happens.


Thursday, January 10, 2008

Django with PostgreSQL on CentOS/RHEL 5

This is a quick practical walkthrough on how to setup the current SVN trunk of Django on CentOS / RHEL 5.

This assumes that if you have a Red Hat Enterprise Linux system, that is is registered to the Red Hat Network and that you have a valid entitlement.

Install software for this deployment:

As the title says, This site is aimed at people wishing to deploy Django on RHEL/CentOS 5 with Postgresql, no religious wars please. All of the packages mentioned in this article except for psychopg2 are available in the distribution itself.

The nice guys at the Extra Packages for Enterprise Linux have packaged up psycopg2. As this is the official repository for Red Hat and its derivatives, packages from this repo should -never- conflict
with packages from the distributions main tree.

Download and configure yum for this repository with this command:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm

Now use yum to install packages needed with the command:

yum install subversion postgresql-server postgresql-python httpd python-psycopg2

Configuring PostgreSQL

Become the postgres user
su - postgres

Connect to the template1 database with PostgreSQL user postgres:

psql -d template1 -U postgres

Yes, the default PostgreSQL user is postgres, and the linux user postgres is different, these are not related changing one does not change the others.

From the SQL command line, change the PostgreSQL user postgres‘s password:

ALTER USER postgres WITH PASSWORD '';

Quit the SQL command line:

\q

Setting the password – which can differ from the password for the linux user postgres – will allow you to connect to the PostgreSQL command line as the PostgreSQL user postgres (if necessary) after changing the authentication settings in the next step.

Modify /var/lib/pgsql/data/pg_hba.conf to require password authentication for local connections:

Comment or remove any existing lines at the end of the file, then append this:

local all all password

Create a user on the postresql server. This is going to be the username and password to be entered in the settings.py file:

createuser -P -s -e yourusername
Enter password for new role:
Enter it again:
Password:
CREATE ROLE yourusername PASSWORD 'secretpassword' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
CREATE ROLE


createdb --encoding=UNICODE yourdatabasename -O yourusername
Password:
CREATE DATABASE

Then restart the postgresql server with the command
service postgresql start
Install and configure Django:

The current trunk for Django has many changes (check out Jonathan Buchanan's post on the topic), most of which are very useful features or fixes for uncommon use.

Make a directory where you would like to keep the current svn (I usually make a django user specifically for this purpose), change to this directory, then check out the current trunk with the command:

svn co http://code.djangoproject.com/svn/django/trunk django_trunk

We now symlink this newly made directory
ln -s `pwd`/django_trunk/django  /usr/lib/python2.4/site-packages/django
Making django-admin usable:

The django-admin.py command is used quite commonly during Django development and testing. You could refer to it by its complete path, but its easier just to add this directory into your current $PATH environment variable.

In bash, i'd modify $HOME/.bashrc and add the line:

PATH=$PATH:/path/to//django_trunk/django/bin/

Log out and in for the changes to take affect, to test try and run the command "django-admin.py" without a full path. You should see something like:

[root@hostname ~]# django-admin.py
Type 'django-admin.py help' for usage.



Where to store your files

Make the following directories

mkdir -p /var/vhosts/virtual.subverted.net/htdocs/media/
mkdir -p /var/vhosts/virtual.subverted.net/django/


The /var/vhosts/virtual.subverted.net/django/ directory is where the django code will live and the media directory is where static files such as images, css and javascript will hang out.

Starting a project

Change into the django directory:

cd /var/vhosts/virtual.subverted.net/django/

run the command

django-admin.py startproject yourprojectname

It should return nothing if done correctly, but a skeleton layout of a project should appear in the current directory.

If you installed with SElinux enabled, you will want to set the context on these files correctly, do so with the command:

chcon -R --reference /var/www/html/ /var/vhosts/virtual.subverted.net/

Configuring Apache

There are many political arguments surrounding the best web server to use, I don't care enough to get in to the arguments. There /etc/httpd/conf.d/hostname.conf file, following along with our virtual.subverted.net host, here is my configuration file:


ServerAdmin webmaster@virtual.subverted.net
DocumentRoot /var/vhosts/virtual.subverted.net/htdocs/
ServerName virtual.subverted.net
ErrorLog logs/virtual.subverted.net-error_log
CustomLog logs/virtual.subverted.net-access_log common


PythonPath "['/var/vhosts/virtual.subverted.net/django/'] + ['/var/vhosts/virtual.subverted.net/django/yourprojectname/'] + sys.path"


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE yourprojectname.settings
PythonDebug On



SetHandler None




The name of the file isn't important, but it must end in .conf to be processed by the main apache script.
You will also want to have another single file which instructs apache to use the namedvirtualhost option to make the above named virtual host "work"

Create a file called /etc/httpd/conf.d/allow-vhost.conf, and have it contain:

NamedVirtualhost *:80

Restart the apache server with the command

service httpd restart

And you should be greeted with the "It worked!" welcome page (Shown earlier in this article)


This essentially means the apache is serving up the page correctly, the next step is to configure your settings.py to point to your database.


The settings.py file should have been autocreated when the django-admin startproject yourprojectname command was run.

It should be in the /var/vhosts/virtual/django/yourprojectname directory. Here is an excerpt from the configured settings.py on my system:

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'yourdatabasename' # Or path to database file if using sqlite3.
DATABASE_USER = 'yourusername' # Not used with sqlite3.
DATABASE_PASSWORD = 'secretpassword' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.

--- snip --

The DATABASE_* settings are the lines that were modified to point to the database and username password that you should have created above.

Thats all we have time for now kids... Join us again next time. Bye for now.

If you have any corrections, let me know in the comments and I'll fix things above.