Tuesday, April 13, 2010

How to change payment information in itunes when caught in an endless loop

I have been sufferig the latest couple of week by not being able to change my billing information in either iTunes or directly on my iPhone. I kept trying to change my old credit card info to a different card or setting the payment method to none, but every time I returned to my payment information nothing had changed. A message allways appeared in iTunes stating that "there were errors or omissions". I was unable to buy anything from iTunes or update apps on my Iphone.

The solution: I am currently an iphone developer and opened my web browser to developer.apple.com/iphone. I then resent my programmer status and contact information and accepted the latest agreement from apple. I suddenly was able to change my billing information to whatever I wanted.

Monday, January 11, 2010

Valg av varmeløsning

Jeg har i den siste tiden hatt mye å tenke på angående hvordan vi skal varme opp det nye huset vi skal bygge. I den siste tiden har det dessuten vært en glohet diskusjon angående varmekilder, noe takket være den kalde perioden vi har vært gjennom nylig.

Til å begynne med ble jeg svært fristet av å installere en vannbåren varmeløsning, med varme i alle golv i begge etasjene, totalt 190 m^2. Jeg har blant annet hørt om denne fantastiske lunheten man får med bruk av rørlagt vann i gulvene.

Vi ba utbygger om å komme med pris på luft-vann varmepumpe og vi fikk prisantydning på ca 170000, noe jeg personlig synes var styggdyrt. Etter å ha sett på NRK og FBI fikk jeg høre at prisen på strøm antagelig ville øke med 25% de neste ti årene. Jeg antok at merkostnaden for ei bergvarmepumpe kommer på prisen for borring, kanskje 50000. Jeg ønsket dessuten å sammenlikne med ei habil luft-luft varmepumpe på 25000. Pellets eller sentral vedfyring ble først vurdert, men disse falt bort da vi ikke har kjeller eller plass til silo for disse løsningene.

Etter å ha gjennomgått energikalkylen for vårt planlagte hus (205 m^2 BRA) hos energimyndigheten.se fikk jeg mengen energi som kunne spares for hvert år. Med beregnet prisøkning for strøm fikk jeg følgende kurver:



På kurven ser vi at det tar ca 4 år å spare inn en luft-luft varmepumpe, 12 år for luft-vann og 14 år for vann-vann. Det tar dessuten ca 20 år før alle løsningene er like lønnsomme. Dette forutsetter selvsagt at anlegget holder i hele perioden. De beste garantiene for varmepumper gjelder for 10 år, så du skal være heldig dersom pumpen varer en hel investeringsperiode.

Etter en prat med utbygger i dag ble jeg til slutt overbevist: På grunn av den nye byggenormen av 2010 vil huset være svært godt isolert og ventilert. Gulvene vil også være lune. Med elektriske panelovner på alle rom og varme i golv på bad og vaskerom burde vi ha et hus som er lett å holde passe varmt. Vi vil dessuten installere en god ovn med gratis fyring og evt en luft-luft varmepumpe dersom vi ser at strømforbruket blir høyt allikevel.

Friday, January 01, 2010

Mini review of "The Power of LESS" by Leo Babauta


Personal productivitiy systems have been very popular the latest years, kickstarted by David Allen's massive success "Getting Things Done". The book probably made Allen a very rich man and started a cult of GTD followers. Every follower had their own little twist of change to what Allen wrote in his book and websites and blogs like 43 folders and lifehacker introduced readers to new systems on how to adapt to GTD. Leo Babauta also started his own site Zen Habbits where he wrote about his own experiences with GTD.

I first found Zen Habbits about a year ago, when I was looking for other GTDers stories about how they made GTD work for them. I had been an avid user of the system about two years then, and was looking for a new GTD software system to change to.

Leo Babauta identified some flaws with Allen's orignal system. The most important ones being the lack of priorities amongst different projects and thus the lack of focus on each individual task. Even though Allen have suggestions for selecting projects based on long term goals and a "someday maybe list" for those projects you cannot work with right now, he never seem to mention anything about minimizing the amount of simultaneous projects and reducing the number of tasks you are saying yes to. I think Leo Babauta is into something when he asks you to limit yourself to the essentials in order to get the maximum out of everything you do.

Ok, so I was about to tell you about feelings about the book "The Power of Less". It would be impossible to write something about it without the former introduction. If you allready are a user of GTD today I would say that you can find everything extra you need to know from reading the most important articles at Zen Habits. I have a slight feeling that some of the articles might be word by word the same as on the web site. If you are new to GTD or don't know about Zen Habits on the other hand, I would highly recommend you pick up the book and start reading. It is a quick read (about a day for me) and adds good wisdom in today's fast lane society.

Tuesday, December 29, 2009

Mini review of "Brain Rules" by John Medina



I am not sure how I came across the book "Brain Rules" by John Medina, but I had put it on my Christmas wish list and got it as a gift. My hopes before starting reading it was that I was going to pick up a few tips and be inspired to change my ways of doing things in a more brain friendly way.

The book chapters are sectioned in what Medina calles "brain rules" or principles of how the brain is working. The chapter titles are exercise, survival, wiring, attention, short-term memory, long-term memory, sleep, stress, sensory integration, vision, gender and exploration. The actual brain rules for each topic can be found on medinas site: http://www.brainrules.net/. The videos on the site are quite good for catching the essence of each rule too and for repetition as well.

Each chapter usually uses plenty of examples of how the brain is working, usually experienced by the author himself. The examples are coupled to brain research and brain anathomy in a humorous way. At the end of each chapter Medina has a few ideas on how the brain rules can be put to practical use.

Many chapters are quite captivating and I found myself fascinated on how complex the brain actually is. The most important points I picked from the book are:

  • Learning is better done while exercising. Try to combine the two if possible.
  • Create strong pictures when you really want to remember things.
  • Teach and learn in periods of about 10 minutes at a time. The brain loses attention and gets bored after this time.
  • Recreate the environment of where you learned something when you want to recollect it.
  • Understand every word in a sentence that you want to understand.
  • In a presentation: Catch the audience's attention at an early moment.
  • Use plenty of examples when you want to explain something.
  • Multitasking is a waste of time.
  • Learn by doing. The brain is an expert at adapting to new tasks.
  • The best way of really learning something: Repeat every 10 minutes for three times and then repeat the most important things every 3-4 days.
  • Get sufficient sleep.
  • Avoid long term stress. Ask the question "am I in control?" if you are not sure if you are stressed.
  • Strengthen learning by using many senses at a time.
  • Your learn much by watching pictures in combination with relevant text, but more with narration and videos.
  • Reduce the amount of text in powerpoints - The brain is lazy and avoids reading text.
  • Vision is the most powerful sense and actually uses half of the brain's processing power.
  • Women capture the emotional details while men see the gist when experiencing acute stress.
So was the book worth reading? I think it was ok reading the book, but I think Medina got a little to detailed for my taste. I never wanted to be a brain scientist. I got what I wanted in the end: some great techniques for improving learning backed up with science. I will put it to practise - no doubt about it.

Thursday, October 15, 2009

How to locate, read and write property lists for iPhone

I had a real headache trying to figure out how to read and write property lists yesterday. It should have been an easy task, and I did everything according to the manual.

Here is what I wanted to do:
  1. Locate a property list created in xcode
  2. Read the XCode property list to a NSDictionary
  3. Append one or more extra items to the NSDictionary
  4. Save the updated NSDictionary to disc
The problem was that the iPhone has a sandboxed area called "Documents" where you can read and write property lists, but the property list you created in xcode is not located in this folder.

If you create a property list "MyPlist.plist" for an application called "MyApp" in XCode it will be located here:

appPath/MyApp.app/MyPlist.plist

Where "appPath" is a string that you can only get while running the app. You can get the whole path to the plist by using this code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"MyPlist" ofType:@"plist"];

This file could be read from, but not written to due to the location on the iPhone.

But I wanted to save data to the iPhone. This could only be done in a property list located here:

appPath/Documents/MyPlist.plist

To locate the folder "Documents" where I have rights to both read and write I can get the path by using this code:

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@"History.plist"];

Reading and writing to the property list from a NSDictionary could be done with the following code:

Reading: NSDictionary *dict=[[NSDictionary alloc] initWithContentsOfFile:path];
Writing: [dict writeToFile:path atomically:YES];

Here is the whole code put into action:

NSMutableDictionary *dict;

//Reading plist created in xcode
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyPlist" ofType:@"plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

//Reading plist stored on device
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
path=[documentsDirectory stringByAppendingPathComponent:@"MyPlist.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
//Merging dictionary created in xcode with dictionary stored on the iPhone
[dict addEntriesFromDictionary:tempDict];
}

//Creating dictionary if it doesn't exist
if (dict==nil) dict=[[NSMutableDictionary alloc] init];

//creating and adding array to dictionary
NSArray *array=[NSArray arrayWithObjects: [NSDate date], [NSNumber numberWithDouble:double1], [NSNumber numberWithDouble:double2], [NSNumber numberWithDouble:double3], [NSNumber numberWithDouble:double4],nil];
[dict setObject:array forKey:@"First Array"];

//writing dictionary to plist on device
[dict writeToFile:path atomically:YES];
[dict release];

Wednesday, September 02, 2009

How to connect icd3 ac162049 with a PIC microcontroller.


I confess I'm a hopeless beginner when it comes to Microchip's PIC microcontrollers. After playing around several years with AVR microcontrollers I figured it was time to go for the hobbyists second choice - the PIC.

My first impression is that Atmel has outpriced themselves after earlier being able to deliver cheap developer boards like the STK500. I wanted a programming device that was able to program DIL devices for rapid prototyping and for hobby projects and ended up buying an Microchip ICD3. I also bought a AC162049 universal programming module to be able to program several different DILs without having to make circuit boards first.


I am familiar with some other chips from Microchip, and have always found the datasheets quite understandable. With the ICD3 it was a completely different story. I was not able to connect to the dsPIC33FJ128MC that I knew was compatible with the ICD3. After looking around a bit I found out how to communicate with the device:

  1. Connect a 4.7-10 kOhm pullup resistor from one of the two VDD wires to the _MCLR pin.
  2. Connect all other wires except VPP to the pins in the datasheet for the microcontroller. GND wires should be connected to Vss. PGC and PGD should be connected to any of the pins starting with PGC or PGD. I used PGC1 and PGD1.
  3. Open MPLAB IDE and choose "Configure-Select Device". Choose the device you are using.
  4. Open "Programmer-Select Programmer"and select "MPLAB ICD3".
  5. Open "Programmer-Settings-Power" and check "Power target circuit from MPLAB ICD3".
Now you should be able to connect to the microcontroller. For me it was the setting for the power that I missed. After using a voltmeter I found that the microcontroller didn't have any power.

Tuesday, March 24, 2009

Simple TWI / I2C communication with AVR ATMega8 and TC1321 DAC

I wanted to set up and test the D/A-converter TC1321 with a AVR, but had no previous knowledge of TWI. These are my experiences:

To make things easier I used a AVR with built in TWI function. I got a little confused on this subject when I read on AVR Freaks that for example the ATTiny26 had TWI function. Actually the microprosessors with a lowercase "y" in the comparison chart has USI which can be used for TWI. The uppercase "Y" for TWI indicates that the uC has built in TWI functionality. With such uCs you can include the to get some free predefined twi-codes.

To connect to a TWI device you need to connect the SCL and SDA lines to the uC. For ATMega8 it is PC4 (SDA) and PC5 (SCL). You then need to connect each of these via a pullup resistor to the source voltage (5V). For this connection I used two 220 ohm resistors.



So to sum up: I found it easier than I thought to interface the TC1321. Reading through descriptions that others have made describing both reading and writing to a slave (EEPROM etc) was not necessary when the only thing I wanted was to send data.

I found it easier than I had thought to communicate with the TC1321. First you need to set up the SCL-clock rate. You can calculate the TWBR with this formula:
TWBR=(fCPU/fSCL-16)/(2*4^TWPS)

So if you run your uC at fCPU=8MHz and you want fSCL=100kHz and try to use a prescaler TWPS=0 you get TWBR=(8e6/100e3-16)/(2*4^0)=32. So you start by setting:

TWPS=0;
TWBR=32;
To send data to the TC1321 you can use two protocols: 1-byte format (8-bits) and 2-byte format (10-bits). The progress of sending data is made in a sequence like this:

1-byte format:
START
SLA+W
COMMAND
DATA
STOP

2-byte format:
START
SLA+W
COMMAND
DATA
DATA
STOP

In between every sending you check the status codes by looking at TW_STATUS. The SLA+W is actually only the slave adress, 0x90.

Here are some functions that can be used to send data to the TC1321:


So to sum up: I found it easier than I thought to interface the TC1321. Reading through descriptions that others have made describing both reading and writing to a slave (EEPROM etc) was not necessary when the only thing I wanted was to send data.