Your Tamagotchi character has to be on generation 2 or higher to visit its parent, and generation 3 or higher to visit its grandparent.
Go to the TamaTown site and click on the Parents or Grandparent's house. A password prompt will appear.
Quote from TamaTown parent / grandparent house online help:
>>
Before you can visit your parents / grandparent, you need to get a password from your Tamagotchi toy.
Here's how:
1. On your toy go to the Friend list icon, and press the ( button to select it.
2. Then, use the ( button to select "Family" and press the ( button again to select "History."
3. Select your grandparent, and press the ( button. This should give you a password.
4. Now take the password you get from the Tamagotchi toy, and enter it here!
<<
*edit: Yes, I know it says "History" where it should say "Parent", but that's the way it's listed on the TamaTown web site. So, don't complain to me, complain to Bandai.*
Note: to visit the parent in TamaTown, you need to use the parent password from your Tamagotchi toy, and to visit the grandparent in TamaTown you need to use the grandparent password from your Tamagotchi toy. In the Family list, your Tamagotchi character's parent will be shown with the number 1 in the upper right corner, and her/his grandparent will be shown with the number 2 in the upper right corner.
Well mine is G3 but it's a toddler still so I don't know. I have gotten two codes from my family list but so far they both only work to see the parents.
aha! I figured it out...I was looking at the wrong parent.. I got the code and they gave me a code of a bicycle... I thought it was something different.