Getting started with Raspberry Pi: Difference between revisions
added some simple instructions on how to blink a led connected to the raspberry pi |
|||
Line 124: | Line 124: | ||
* [https://github.com/fenlogic/vga666 Add VGA port to your Raspberry Pi]. | * [https://github.com/fenlogic/vga666 Add VGA port to your Raspberry Pi]. | ||
* Turn your Raspberry Pi into [http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter FM transmitter]. | * Turn your Raspberry Pi into [http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter FM transmitter]. | ||
=Blinking a LED= | |||
A led is connected to each RaspberryPi on to GPIO 18. | |||
==Blinking from the terminal== | |||
To blink it from terminal you first have to become a root user. | |||
sudo su | |||
Then you have to export gpio number 18 | |||
echo 18 > /sys/class/gpio/export | |||
After that is done you have to set the direction of the gpio pin, in this case you have to set it to out direction. | |||
echo out > /sys/class/gpio/gpio18/direction | |||
And now you can blink your led on and off. | |||
# Turn the led on | |||
echo 1 > /sys/class/gpio/gpio18/value | |||
# Turn the led off | |||
echo 0 > /sys/class/gpio/gpio18/value | |||
==Blinking with a Python script== | |||
todo.. |
Revision as of 14:05, 24 September 2015
Raspberry Pi is a credit-card sized single-board computer which can be used for variety of purposes. The official operating system for Raspberry Pi is Raspbian. Rasbian and Ubuntu both are derived from Debian, providing seamless access to thousands of software package ready to go via Advanced Packaging Tool. Compared to other similar single-board computers Raspberry Pi has vibrant community and plenty of code examples that you can run out of the box. Before you continue make sure you're comfortable with basic command-line usage, if that's not the case take a look at CodeAcademy track for learning command line.
Feel free to improve this wiki page by clicking edit above.
Preparing SD card
Before you continue make sure you have backed up any important data on the SD-card
Download and uncompress Raspbian:
wget https://downloads.raspberrypi.org/raspbian/images/raspbian-2015-05-07/2015-05-05-raspbian-wheezy.zip unzip 2015-05-05-raspbian-wheezy.zip
For Linux there is no need to fetch extra tools to write the image to a SD card, simply use dd
:
sudo dd bs=4M if=2015-05-05-raspbian-wheezy.img of=/dev/mmcblk0
Make sure you flush buffers, otherwise you'll get partial write:
sync
If you're running on Windows, you can use Win32 Disk Imager to write the image to the SD card.
Powering up
Use USB-UART bridge to power up Raspberry Pi and gain access to the command-line.
Accessing command-line
For Linux there are variety of programs for connecting to serial port:
screen /dev/ttyUSB0 115200 picocom /dev/ttyUSB0 -b 115200 minicom -b 115200 -o -D /dev/ttyUSB0
If you get the error message [screen is terminating], you must put your user in the "dialout" group. To do this, enter the following command (only with your own computer):
sudo gpasswd -a $USER dialout
Then you will see a message that your user has been added to the group dialout. Now log out from Ubuntu and log in once again.
For Windows you need to install driver for your USB-UART bridge first.
For Windows 8 use this workaround.
Then you can use built-in HyperTerminal, PuTTY or KiTTY for connecting to the virtual serial port.
The default user is pi
with the password raspberry
. Make sure you change the default password. For more information about user management see Raspbian documentation.
If you're facing issues with USB-UART bridge, simply proceed to network section below.
Setting up network
Raspbian as Debian attempts to request IP address using DHCP on the Ethernet port.
This assumes a functioning DHCP server on the network, which is the case most of the time.
If you want to connect your laptop directly to the Raspberry Pi you can set up manual IP addresses.
The networking configuration is stored in /etc/network/interfaces,
remember to issue service networking restart
after you've tweaked the configuration.
Use nmap
to discover Raspberry Pi on your network:
nmap 192.168.0.1-255 -p22
Don't worry if you mess up the network configuration, you can always recover with the USB-UART bridge method described above.
Remote shell
For more convenient access to command-line SSH is recommended. You can start by installing OpenSSH server on Raspberry Pi:
apt-get install openssh-server
Assuming Raspberry Pi sits on an DHCP enabled network you can use following on your Linux laptop to connect to remote shell:
ssh pi
Otherwise determine the IP address of your Raspberry Pi, for example with ip addr list
:
ssh 192.168.x.x
Make your life easier by setting up public key authentication. Windows users might want to take a look at PuTTYgen instructions.
Note that while you are connected via USB-UART bridge you can simply copy the contents of your public key and paste it to Raspberry Pi as follows:
mkdir -p /root/.ssh cat - >> /root/.ssh/authorized_keys # Paste now # Press Ctrl-D
Beyond installation
Once you are comfortable with Raspberry Pi command line and SSH you can do a lot of cool stuff:
- Set up ownCloud as your very own Dropbox replacement.
- Set up PulseAudio network sink and use Raspberry Pi as wireless speakers.
- Set up motion and use Raspberry Pi with USB webcam as a IP camera.
- Set up hostapd, dnsmasq and packet forwarding turning your Raspberry Pi into a wireless hotspot. Easier approach here.
- Set up nginx and create static web page using Jekyll.
- Add VGA port to your Raspberry Pi.
- Turn your Raspberry Pi into FM transmitter.
Blinking a LED
A led is connected to each RaspberryPi on to GPIO 18.
Blinking from the terminal
To blink it from terminal you first have to become a root user.
sudo su
Then you have to export gpio number 18
echo 18 > /sys/class/gpio/export
After that is done you have to set the direction of the gpio pin, in this case you have to set it to out direction.
echo out > /sys/class/gpio/gpio18/direction
And now you can blink your led on and off.
# Turn the led on echo 1 > /sys/class/gpio/gpio18/value # Turn the led off echo 0 > /sys/class/gpio/gpio18/value
Blinking with a Python script
todo..