Tuesday, September 18, 2012

What time is it?

The Pi doesn't have a real time hardware clock, in order to save $$. But that doesn't mean you cant have date returning the correct time.

ntp client is installed by default. All I do when I configure a box is to add a local time provider:

fdion@raspberrypi ~ $ sudo vi /etc/ntp.conf

where it says:
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
I added:
server clock1.unc.edu

Instead of clock1.unc.edu, choose one that is close to you from this list:
http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers



fdion@raspberrypi ~ $ sudo /etc/init.d/ntp restart

[ ok ] Stopping NTP server: ntpd.
[ ok ] Starting NTP server: ntpd.

fdion@raspberrypi ~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ns.unc.edu      .INIT.          16 u    - 1024    0    0.000    0.000   0.000
-200.140.8.72.in 64.147.116.229   2 u    8  128  357   84.964   -7.069  12.917
+a1.hotfile.com  209.51.161.238   2 u   80  128  367   33.450    1.298   1.592
+ponderosa.piney 64.90.182.55     2 u    9  128  357   47.021   -2.056  28.562
*clock.team-cymr 172.16.32.4      2 u   17  128  377   57.341    1.629   4.500


The other thing we have to fix is the timezone. Maybe you are in the right default timezone, but more than likely (statistically more probable) that you are not. So how do we adjust this?



fdion@raspberrypi ~ $sudo dpkg-reconfigure tzdata



Current default time zone: 'US/Eastern'

Local time is now:      Tue Sep 18 18:01:43 EDT 2012.
Universal Time is now:  Tue Sep 18 22:01:43 UTC 2012.



Great.

Let me check the LCD display (driven by the GPIO pins):



This particular Pi runs headless, so that's pretty convenient to get the dhcp assigned IP. I do have to make this a little bit more permanent, although I will switch to a different display (which I also have) that will give me a little more feedback. I'll post about how to do all this soon enough.


Monday, September 17, 2012

Less work, but fools google

So, I'm switching back and forth between languages on the same blog. Makes it easier to maintain just one blog instead of 3, 4 or more with the same content but in different languages (like I do for Solaris Desktop.

Having said that, it will not work with google translate, this way. Sorry for english readers, Google thinks the whole blog is in english, so you wont be able to use the translate widget I added for the whole blog. In fact, I tried the blogger translate widget too, but it will not offer english at all. So I thought I'd be clever, and add this:

<script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/translatemypage.xml&up_source_language=auto&w=160&h=60&title=&border=&output=js"></script>

The key here is source_language = auto. Unfortunately it complains the page is already in english...

To get around this, just select a specific article so that only one language is showing up on the page, and then you can use the translate tool.

Un ecran de portable pour le Pi

Sur le forum francais de raspberrypi.org on pose la question, que faut-il pour utiliser un ecran LCD de portable avec le Pi.

 Les portables ont une interface video interne LVDS, le Pi lui veut soit composite, soit HDMI. Et finalement, les kits pour "hacker" qui incluent un pilote LVDS, un paneau de controle pour le OSD, le convertisseur pour CCFL (pour LED, c'est different) et tout les cables de connexions, eux, sont en general VGA.

Si on va vers le plus haut de gamme comme ce pilote LVDS avec entrees DVI et HDMI:


Le probleme la c'est que ce n'est pas un kit, alors il faut se procurer les autres modules et cables, et avoir les bons. En plus, ces modules doivent etre programmes en fonction de la dalle LCD. Et il y a la question d'espace, ou mettre tout cela:

Le pilote ici requiert un module de programmation pour faire les ajustements. C'est facile de depenser plus de 100 euros (200 si on achete le module de programmation) au total, alors il faut voir si ca vaut vraiment la peine...

Sunday, September 16, 2012

En francais

Je vois que j'ai des visiteurs du Canada et de France. Je ne vais pas faire comme SolarisDesktop que j'ai aussi ecrit en francais et en espagnol. C'est trop de boulot d'ecrire trois blog a chaque fois. Mais plutot, je vais alterner entre les differentes langues et couvrir des sujets differents.
Ca me permettra aussi d'y aller en Portugais et Russe et d'ameliorer mon niveau de communication dans ces langues.
Alors, lecteurs, je vous passe la parole, que voulez-vous savoir sur le Raspberry Pi? Laissez le moi savoir en commentaire.
Oh, et soit dit en passant, il y a un forum pi en francais sur le site officiel. On le retrouve ici: raspberrypi.org forum en Francais

Saturday, September 15, 2012

Day 1

SD Card

In the previous article, entitled Day 0, we talked about all the stuff you need before your Raspberry Pi can be up and running. We talked about the power supply as item #1.

Item #2 was the SD memory card (in blue on the picture):


This is the equivalent to a hard disk on a computer, for your raspberry pi. The official distribution (operating system), raspbian wheezy, requires a minimum of a 2GB SD card. These can be had for a few $. Less than $5 at any rate. But it is not worth the time. Start at least with 4GB. Considering that an 8GB card is to be found in brick and mortar stores for $8 and a 16GB for $14 (i'm writing this in september 2012), I'd even go with 8 or 16 if this is more than a toy.

If you go with a different distribution, such as the adafruit Occidentalis distro, then you have no choice but to go with 4GB as the minimum, and there it makes also a lot of sense to get an 8GB or 16GB card.

Having said that, there are also specialized distributions, one trick ponies so to speak, that can fit on 1GB and 2GB cards. It all depends what you want to do with your Pi.

Beside the capacity, you'll want to get the right speed, or "class". For example the blue sandisk 16GB on the picture above is a class 4 card. That is a minimum speed, imho. If you can get class 6 or 10, that is even better:






This one is a SanDisk 16GB also, but a class 10 that promises 30MB/s and that's a good thing.


Buyer Beware


Before rushing out and buying a card, I do want to mention a few things.

1. Not all cards are compatible. Check the LIST and make sure that it is supported. I've never had any problem with any SanDisk or AData cards with the Raspberry Pi, but apparently some people have had issues.

2. You will need a way to write the SD card. That means either an on board SD card slot (such as on the Mac mini and mac books) or a USB SD card reader like this:


This should work with Windows, Solaris / OpenIndiana, Linux and Mac OS/X. Typically, I've found that a lot of embedded SD slots, such as found on Sony Vaio (with the secondary slot for MagicGate) and Dell Precision laptops, tend to not create reliable images, under any OS. The USB on the other hand seems solid. In the end, the embedded SD slot on my Mac Mini seems rock solid as far as that, so I tend to stick to that.

3. The steps to copy the operating system software image to the SD card is a bit involved. If that scares you, there is another option:

Buy a card that already has the OS on it. This can be found on forums, through your local hackerspace, your local Linux user group, ebay, electronic distributors (in the case of Adafruit, they sell SD cards with their own distribution, Occidentalis, already installed) or online shops that specialize in the Raspberry Pi. You can also check the LIST for some other suggestions.

So, we are making some progress... Next time, we'll talk about the keyboard.



SolarPi

Meet the SolarPi!




...look inside...


There is a raspberry pi in there, under the tray. Note the red key, that's a safety feature, cause this is not a toy. I reckon that I could probably run it a whole week non stop purely on batteries.

I built this a few years ago, from a toolbox on wheels.


I'm using sealed lead acid batteries (7 x 12v currently for 49Ah capacity, but 12 x 12v 7Ah for 84Ah total capacity, at some point in the past), lots of wires.





The wires are connected together with 2 rails with screws to have a common parallel connection. These are typically used for ground buses for fuse boxes. Negative side:


Positive side:



Safety first, there is a key to close the circuit. Amp meter is always on, while the voltmeter engages with the switch in the middle pulled. Yeah, I know 50 amps is crazy for the Pi, considering is pulls about 4.2 watts (less than half an ampere at 12V) without wifi or 6.8 (just a tad over half an ampere) with wifi active and transmitting. But I've designed this initially to use with a 110V power inverter too and camping gear, and it's easy to pull 30 amps + with those...


And the reason I thought about sharing this project today: the solar panel.


I have 2 of those, and I use them also to charge my electric bicycle batteries. I connect them to the battery through a solar panel controller that regulates the voltage so that I don't fry the batteries.

Why am I sharing this story today?

What happened is that I met Mike today, in the parking lot of a commercial shopping center, in Winston Salem, North Carolina. He builds electric vehicles. This one is a chEVrolet :)


144V was true some months back, he now runs a bit higher voltage using Lithium batteries with a bunch of BMS (battery monitors). He swapped the previous battery pack out (over 1000lbs, 18 batteries at 8V each, lead acid) but didn't repaint the truck :)



There is quite a bit more information on his truck here at: Backyard Green. So we talked a good bit about the tech, and even got into the subject of solar power, and I mentioned I powered one of my raspberry pi through solar power. I thought that maybe others would be interested in this aspect, the "green computing" side of the pi...

Anyway, back to Mike, he does a good bit of work with microcontrollers and he had a pi lookalike embedded in the console of his electric truck and he's thinking of building his own graphical interface. Sounds like a perfect match for the Raspberry Pi and Python... At any rate, it was a really interesting discussion.

Friday, September 14, 2012

Sidekick 2

Continuing on using the raspberry pi as your desktop's sidekick, we will focus today on making it easier to work with, better integrated, when your desktop is Unix (Solaris, OpenIndiana), Linux, Mac OS/X or even Windows (except you wont be able to use ssh-keygen or scp - instead check the section I Got a PC? toward the end of the post).

Automating login

First thing first, we need to create a new user on the Raspberry Pi. Although the user pi is pretty cool, you dont want to have to specify the user in all the commands you will do, so we'll match it to the username on the desktop.

Let's say your username is user on your desktop (of course, if you want to have a username billybob, then replace user with billybob in the below code). You will need to connect as the pi user, then set up a new user:


 ssh pi@raspberrypi  
 (enter your pi user password)  
 pi@raspberrypi ~ $ sudo useradd -d /home/user -s /bin/bash user   
 pi@raspberrypi ~ $ sudo mkdir /home/user  
 pi@raspberrypi ~ $ sudo chown user:pi /home/user  
 pi@raspberrypi ~ $ sudo passwd user  
 pi@raspberrypi ~ $ Enter new UNIX password:  (type password)
 pi@raspberrypi ~ $ Retype new UNIX password:  (type it again)
 pi@raspberrypi ~ $ passwd: password updated successfully  
 pi@raspberrypi ~ $ sudo cp .bashrc ../user
 pi@raspberrypi ~ $ sudo cp .profile ../user

The last item we have to do is to edit the /etc/sudoers file and add our user to it ([esc] means hit the escape key):

 pi@raspberrypi ~ $ sudo vi /etc/sudoers  
 (add the following line after going to last line and typing o)  
 user ALL=(ALL) NOPASSWD: ALL  
 [esc] :wq!
 pi@raspberrypi ~ $ exit

BTW, for most people, there is too much detail (such as how to add a line in vi), but keeping in mind that there are some people in schools reading this and they just starting playing with this, I think it is well justified).

 We now go back to our desktop and test that we can login as the user (no need to specify user@raspberrypi, just raspberrypi since the default is to user the desktop current user):

 user@desktop ~ $ ssh raspberrypi  
 (enter password)  
 user@raspberrypi ~ $ mkdir .ssh  
 user@raspberrypi ~ $ exit  

Now, we will generate an RSA private and public key pair. We will then copy the public key to the RPi as authorized_keys2 under the .ssh folder:

 user@desktop ~ $ ssh-keygen -t rsa  
 (enter to accept the defaults)  
 user@desktop ~ $ cd .ssh  
 user@desktop ~ $ scp id_rsa.pub raspberrypi:.ssh/authorized_keys2  
 (enter password)  

We will login once more on the RPi to change access:

 user@desktop ~ $ ssh raspberrypi  
 (enter password)  
 user@raspberrypi ~ $ cd .ssh  
 user@raspberrypi ~ $ chmod go-r authorized_keys2  
 user@raspberrypi ~ $ exit  

At last, we can now copy files using scp or login on our RPi without entering a password:

 user@desktop ~ $ ssh raspberrypi  
 user@raspberrypi ~ $  

Yeah!

SCP tasks

Getting a file

To get a file from the RPi, onto the desktop:

The file is in the /home/user directory:
user@desktop ~ $ scp raspberry:file.txt .
 
The file is in /home/user/directory:
user@desktop ~ $ scp raspberry:directory/file.txt .
 
The file is in /home/user/directory/subdirectory:
user@desktop ~ $ scp raspberry:/home/user/directory/subdirectory/file .

Putting a file

To get a file from the RPi, onto the desktop:

The file is in the /home/user directory:
user@desktop ~ $ scp raspberry:file.txt .
 
The file is in /home/user/directory:
user@desktop ~ $ scp raspberry:directory/file.txt .
 
The file is in /home/user/directory/subdirectory:
user@desktop ~ $ scp raspberry:/home/user/directory/subdirectory/file .

Action on a directory

To get or put a directory, simply use the -r flag:

user@desktop ~ $ scp -r mydir raspberry:
 
This will copy recursively mydir onto the server named raspberry, into the default home directory. There is a lot more flexibility to scp, so read up on it:

user@desktop ~ $ man scp

GUI access

I use OpenIndiana as a desktop, most of the time, and that OS, and most Linux versions, has a tool to connect to a server using various protocols and provide a GUI. In the case of OpenIndiana, it is the gnome tool that can be found in the menu as item "connect to server":


This will then open a Nautilus file browser:

Other Options

Another option under unix/linux to access files remotely is through sshfs, a FUSE module. It allows to mount an ssh (sftp) remote system as a local filesystem. If you need this, you are probably already know how to use it, so I wont get into details.

I got a mac?

There is no GUI option directly, Basically, using the technique above with FUSE, I've done it on my Mac using FUSE at http://osxfuse.github.com/, then I downloaded Macfusion.


If anybody wants a more detailed instruction, leave a comment. I dont want to spend too much time on this if no reader is using a raspberry pi as a sidekick to a Mac.

I got a PC?

To automatically login without password, you will need putty (see the previous blog entry on this) and also puttygen. But at the end of the day, why bother? 

The OS doesn't leverage this. Instead, get a GUI interface like Winscp to copy files back and forth.


I use winscp all the time with Windows 7, and you can save configurations, including passwords, so this is fairly painless.