Tuesday, April 13, 2010
How to change payment information in itunes when caught in an endless loop
Monday, January 11, 2010
Valg av varmeløsning
Friday, January 01, 2010
Mini review of "The Power of LESS" by Leo Babauta

Tuesday, December 29, 2009
Mini review of "Brain Rules" by John Medina

- 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.
Thursday, October 15, 2009
How to locate, read and write property lists for iPhone
Here is what I wanted to do:
- Locate a property list created in xcode
- Read the XCode property list to a NSDictionary
- Append one or more extra items to the NSDictionary
- Save the updated NSDictionary to disc
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:
- Connect a 4.7-10 kOhm pullup resistor from one of the two VDD wires to the _MCLR pin.
- 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.
- Open MPLAB IDE and choose "Configure-Select Device". Choose the device you are using.
- Open "Programmer-Select Programmer"and select "MPLAB ICD3".
- Open "Programmer-Settings-Power" and check "Power target circuit from MPLAB ICD3".
Tuesday, March 24, 2009
Simple TWI / I2C communication with AVR ATMega8 and TC1321 DAC
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;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:
TWBR=32;
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.
