From charlesreid1

 
(61 intermediate revisions by the same user not shown)
Line 1: Line 1:
Ordered the CanaKit Raspbery Pi starter kit from Amazon, mainly because it came with a breadboard and a case.
A guide to hacking on the Raspberry Pi, a microcomputer that runs a full stack Linux OS, all on a mobile processor:


[[Image:RaspberryPi_PluggedInRPi.jpg|500px]]
=Installing=
Instructions for installing an operating system on the Raspberry Pi: [[RaspberryPi/Installing]]
==After Installing: Interfacing with Headless Pi==
Instructions for interfacing with headless Raspberry Pis, including how to change their boot sequence to find them on a network: [[RaspberryPi/Headless]]
==After Installing: First Steps with Pi==
You can find a guide to your first steps with Raspberry Pi, mainly covering the setup process for Raspbian Linux: [[RaspberryPi/First Steps]]
=Raspberry Pi Projects=
==Hardware Focus==
Most recent projects listed first.


NOTE: "cronus" refers to my Mac OS X laptop.
===Making an Internet of Things Morse Code Keyer with Raspberry Pi===


=Installing Operating System=
Combining the morse code example below with [[Flask]], a lightweight web server for Python, allows us to create an API for remotely controlling the Raspberry Pi. We can then use the Raspberry Pi to send morse code with the LED.


The kit came with an 8GB SD card with the NOOBS operating system (for beginners at raspberry pi) pre-installed. Nice touch, but I didn't want to use NOOBS, I wanted to use a Raspbery Pi version of Debian so that I can hack this thing up. I downloaded an image file from http://www.raspberrypi.org/ (it was a zip file, containing an img file).
Here are the details: [[RaspberryPi/IoT Morse Code Keyer]]


==Step 0: Plug the SD card in==
===Morse Code on Raspberry Pi===


You're going to be installing the operating system for the Raspberry Pi onto an SD card, so pick an SD card that you'll use, and plug it into your laptop.
This page has more details on a quick-and-easy way to get a Morse code library I wrote in Python up and running on the Raspberry Pi: [[RaspberryPi/Morse Code]]


==Step 1: Find your SD card==
===Raspberry Pi Timelapse Photo===


I plugged my SD card into my Mac OS X (running 10.8), and ran this command to list all the devices:
You can find a short guide to how I built a Raspberry Pi time lapse photo camera here:  


<pre>
[[RaspberryPi/Timelapse]]
$ diskutil list
 
dyld: DYLD_ environment variables being ignored because main executable (/usr/sbin/diskutil) has __RESTRICT/__restrict section
===Hello World LED Circuit with GPIO===
/dev/disk0
  #:                      TYPE NAME                    SIZE      IDENTIFIER
  0:      GUID_partition_scheme                        *250.1 GB  disk0
  1:                        EFI                        209.7 MB  disk0s1
  2:                  Apple_HFS Cronus                  249.2 GB  disk0s2
  3:                Apple_Boot Recovery HD            650.0 MB  disk0s3
/dev/disk1
  #:                      TYPE NAME                    SIZE      IDENTIFIER
  0:    FDisk_partition_scheme                        *7.9 GB    disk1
  1:                DOS_FAT_32 NOOBS                  7.9 GB    disk1s1
/dev/disk2
  #:                      TYPE NAME                    SIZE      IDENTIFIER
  0:    Apple_partition_scheme                        *16.7 MB    disk2
  1:        Apple_partition_map                        32.3 KB    disk2s1
  2:                  Apple_HFS Flash Player            16.7 MB    disk2s2
</pre>


That means my sd card is at <code>/dev/disk1</code>.
This project controls a simple LED circuit with the Raspberry Pi's onboard GPIO cable: [[Hello World Raspberry Pi]]


==Step 2: Unmount card==
This project uses a python code to send high/low voltage signals to pins on the GPIO, and make an LED on a breadboard blink.


Now I unmount the SD card:
==Software Focus==


<pre>
===Run Web Server on Pi===
$ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful
</pre>


==Step 3: Write image to SD card==
You can find a guide to running a lightweight web server with Flask or something similar:


For the last step, you use <code>dd</code> (disk formatter utility) to write that image to your SD card:
[[RaspberryPi/Web Server]]


<pre>
===Kali Linux on Raspberry Pi===
$ sudo dd bs=1m if=2014-06-20-wheezy-raspbian.img of=/dev/disk1
2825+0 records in
2825+0 records out
2962227200 bytes transferred in 1571.202055 secs (1885325 bytes/sec)
</pre>


Getting deeper into the world of networking and using the Pi for security and networking applications:


The above command took 27 minutes on my system.
[[Kali Raspberry Pi]]


==Resources==
===Tor Proxy with Pi===


* http://www.raspberrypi.org/documentation/installation/installing-images/mac.md
More info here: [https://learn.adafruit.com/onion-pi]
* http://elinux.org/RPi_Easy_SD_Card_Setup


=Interfacing with Headless Raspberry Pi=


==Step 1: Modify Raspberry Pi boot sequence==
==Wifi Access Point==


Following http://pihw.wordpress.com/guides/direct-network-connection/
===Installing Requisite Software===


Plug the SD card back into your computer. Edit the file cmdline.txt to include a directive
Basically, you will be setting up your Pi as a host access point, which requires some software. Specifically, here is the software required:


<pre>
<pre>
ip=169.254.113.200
$ sudo apt-get install hostapd isc-dhcp-server
</pre>
</pre>


appended to the end of the line. Then run
===Set Up DHCP Server===
 
Next, set up the DHCP server by editing <code>/etc/dhcp/dhcp.conf</code>
 
Remove the following two lines by commenting them out:


<pre>
<pre>
$ cp cmdline.txt cmdline.direct
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
</pre>
</pre>


Now you'll boot with a hard-coded IP address. This will work because we're connecting the computer and the RPi directly.
Next, add the word "authoritative;" to the section where it gives you information. You should see this in your file:


==Step 2: Cat5 Network Cable==
<pre>
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
</pre>


Get a standard network cable and connect the laptop to the RPi. Remove the SD card from the laptop once you've modified cmdline and put it in the RPi to boot it up.
Finally, add the following lines to set up the IP address assignment/configuration:


[[Image:RaspberryPi_Network.jpg|500px]]
<pre>
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
</pre>


[[Image:RaspberryPi_Laptop_Network.jpg|500px]]
===Set Up DHCP Interfaces===


==Step 3: SSH==
Next, edit the file <code>/etc/default/isc-dhcp-server</code> and update the <code>INTERFACES</code> section to read:


Now you can SSH to the IP address you specified:
<pre>
INTERFACES="wlan0"
</pre>


[[Image:SSH_RaspberryPi.png]]
Now disable the wlan0 interface:


=First Steps with Raspberry Pi=
<pre>
sudo ifdown wlan0
</pre>


==Configuring your RPi==
Now change the wlan0 network interface so that it will use manually-assigned IP address information, instead of trying to set everything automatically. Edit <code>/etc/network/interfaces</code> and add/change the lines:


When you first SSH into your RPi, it will notify you that you have to run a config program to set up your RPi initially.
<pre>
# auto wlan0
</pre>


[[Image:RaspberryPi_Config.png]]
<pre>
allow-hotplug wlan0


I picked the first menu item, and that required a system reboot:
iface wlan0 inet static
    address 192.168.42.1
    netmask 255.255.255.0
</pre>


[[Image:RaspberryPi_Reboot.png]]
Finally, edit <code>/etc/hostapd/hostapd.conf</code> to set up the wireless network:


==Putting RPi on a Network==
<pre>
interface=wlan0
driver=rtl871xdrv
ssid=Pi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
</pre>


As a next step, we'll want RPi to be internet-capable so we can use aptitude to install some packages and get this operating system tuned up.
Note that the <code>driver=rtl871xdrv</code> line may need to change.


First, you'll keep your network cable plugged into your RPi.
===More Info===


[[Image:RaspberryPi_PluggedInRPi.jpg|500px]]
More info here: [https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point]
 
=Powering the Pi via UART/Serial=


Then you'll plug the other end of the network cable into a network router or a network wall jack.
UART = Universal Asynchronous Receive/Transmit


[[Image:RaspberryPi_PluggedInRouter.jpg|500px]]
While you can normally interface with and power the Pi by plugging it into a computer or a wall wart via the mini USB port, you can also power the Pi via the pins on the board, and communicate with the Pi via a serial connection. This uses the 5V, Ground, TX, and RX pins that are on the right side (the 5V side) of the pins on the Pi board.


Once you plug your RPi into the network router, it'll still have the same IP address, so you can still SSH to it the same way:
By plugging these into a USB serial adapter, which is plugged into a computer, the connection can be used to provide power and a connection to the Pi.


<pre>
More details: http://villagescience.org/running-raspberry-pi-usb-serial-ttl-adapter/
$ ssh pi@169.254.113.200
</pre>


but now the RPi will have internet connectivity:
=Notes by Date=


[[Image:RaspberryPi_Aptitude.png]]
[[Raspberry Pi 2015-07-29]] - basic hello world


==Software Installation==
[[Raspberry Pi 2015-07-30]] - basic hello world writeup


A list of commands that I ran on the RPi to get things installed:
[[Raspberry Pi 2015-07-31]] - morse code writeup, Flask Web API to control hardware


<pre>
[[August 2015]] - notes from august 2015
sudo apt-get update
sudo apt-get install python-dev
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py
sudo pip install virtualenv


sudo apt-get install build-essential
[[August 2016]] - notes from august 2016
sudo pip install flask
sudo pip install cython
sudo pip install numpy
sudo pip install pandas
sudo pip install scipy
</pre>


==Resources==
=Resources=


* http://raspberry.io/wiki/how-to-get-python-on-your-raspberrypi/
* http://raspberry.io/wiki/how-to-get-python-on-your-raspberrypi/
{{PiFlag}}
[[Category:Raspberry Pi]]

Latest revision as of 02:30, 12 August 2017

A guide to hacking on the Raspberry Pi, a microcomputer that runs a full stack Linux OS, all on a mobile processor:

RaspberryPi PluggedInRPi.jpg

Installing

Instructions for installing an operating system on the Raspberry Pi: RaspberryPi/Installing


After Installing: Interfacing with Headless Pi

Instructions for interfacing with headless Raspberry Pis, including how to change their boot sequence to find them on a network: RaspberryPi/Headless


After Installing: First Steps with Pi

You can find a guide to your first steps with Raspberry Pi, mainly covering the setup process for Raspbian Linux: RaspberryPi/First Steps

Raspberry Pi Projects

Hardware Focus

Most recent projects listed first.

Making an Internet of Things Morse Code Keyer with Raspberry Pi

Combining the morse code example below with Flask, a lightweight web server for Python, allows us to create an API for remotely controlling the Raspberry Pi. We can then use the Raspberry Pi to send morse code with the LED.

Here are the details: RaspberryPi/IoT Morse Code Keyer

Morse Code on Raspberry Pi

This page has more details on a quick-and-easy way to get a Morse code library I wrote in Python up and running on the Raspberry Pi: RaspberryPi/Morse Code

Raspberry Pi Timelapse Photo

You can find a short guide to how I built a Raspberry Pi time lapse photo camera here:

RaspberryPi/Timelapse

Hello World LED Circuit with GPIO

This project controls a simple LED circuit with the Raspberry Pi's onboard GPIO cable: Hello World Raspberry Pi

This project uses a python code to send high/low voltage signals to pins on the GPIO, and make an LED on a breadboard blink.

Software Focus

Run Web Server on Pi

You can find a guide to running a lightweight web server with Flask or something similar:

RaspberryPi/Web Server

Kali Linux on Raspberry Pi

Getting deeper into the world of networking and using the Pi for security and networking applications:

Kali Raspberry Pi

Tor Proxy with Pi

More info here: [1]


Wifi Access Point

Installing Requisite Software

Basically, you will be setting up your Pi as a host access point, which requires some software. Specifically, here is the software required:

$ sudo apt-get install hostapd isc-dhcp-server

Set Up DHCP Server

Next, set up the DHCP server by editing /etc/dhcp/dhcp.conf

Remove the following two lines by commenting them out:

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

Next, add the word "authoritative;" to the section where it gives you information. You should see this in your file:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Finally, add the following lines to set up the IP address assignment/configuration:

subnet 192.168.42.0 netmask 255.255.255.0 {
	range 192.168.42.10 192.168.42.50;
	option broadcast-address 192.168.42.255;
	option routers 192.168.42.1;
	default-lease-time 600;
	max-lease-time 7200;
	option domain-name "local";
	option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Set Up DHCP Interfaces

Next, edit the file /etc/default/isc-dhcp-server and update the INTERFACES section to read:

INTERFACES="wlan0"

Now disable the wlan0 interface:

sudo ifdown wlan0

Now change the wlan0 network interface so that it will use manually-assigned IP address information, instead of trying to set everything automatically. Edit /etc/network/interfaces and add/change the lines:

# auto wlan0
allow-hotplug wlan0

iface wlan0 inet static
    address 192.168.42.1
    netmask 255.255.255.0

Finally, edit /etc/hostapd/hostapd.conf to set up the wireless network:

interface=wlan0
driver=rtl871xdrv
ssid=Pi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Note that the driver=rtl871xdrv line may need to change.

More Info

More info here: [2]

Powering the Pi via UART/Serial

UART = Universal Asynchronous Receive/Transmit

While you can normally interface with and power the Pi by plugging it into a computer or a wall wart via the mini USB port, you can also power the Pi via the pins on the board, and communicate with the Pi via a serial connection. This uses the 5V, Ground, TX, and RX pins that are on the right side (the 5V side) of the pins on the Pi board.

By plugging these into a USB serial adapter, which is plugged into a computer, the connection can be used to provide power and a connection to the Pi.

More details: http://villagescience.org/running-raspberry-pi-usb-serial-ttl-adapter/

Notes by Date

Raspberry Pi 2015-07-29 - basic hello world

Raspberry Pi 2015-07-30 - basic hello world writeup

Raspberry Pi 2015-07-31 - morse code writeup, Flask Web API to control hardware

August 2015 - notes from august 2015

August 2016 - notes from august 2016

Resources