# Digital Free Library

## Overview

The Digital Free Library is a fun project that will allow you to create your own electronic library to share with others. Similiar to&nbsp;a [Little Free Library](https://littlefreelibrary.org/) but digital.

I decided to create this project so I could share my favorite digital magazines and projects with my neighborhood. Hopefully this will&nbsp;get others interested in electronics by showing them stuff they might not have know about.

We will be using&nbsp;a Raspberry Pi Zero and a WiFi adapter to&nbsp;create a hotspot that others&nbsp;can connect to and browse the digital books offered.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/037/930/medium800/raspberry_pi_File_Dec_08__4_49_39_PM.png?1481259893)

# Parts Needed

- [Raspberry Pi Zero](https://www.adafruit.com/product/2885) - Version does not matter
- [SD card](https://www.adafruit.com/product/2767) - We will be using Jessie Lite so anything 2gb or greater will work.
- [USB WiFi Module](https://www.adafruit.com/product/2810) - This one has&nbsp;been verified to work with this guide.
- [Tiny OTG Adapter](https://www.adafruit.com/product/2910) - A [USB OTG Host Cable](https://www.adafruit.com/products/1099) would also work if you have one already
- [Raspberry Pi Zero Case](https://www.adafruit.com/products/3252)&nbsp;- Optional
- [USB Cable A/MicroB](https://www.adafruit.com/product/2008)&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/037/578/medium800/raspberry_pi_parts_needed.jpg?1480180277)

# Digital Free Library

## Preparation 

# Prepare Micro SD Card

We will be using Raspbian Jessie Lite, the version I use is September 2016. To find older releases we can go to [http://downloads.raspberrypi.org/](http://downloads.raspberrypi.org/)

You may also want to try a more recent version if that's available and 9/28/2016 isnt working

[Download Raspbian Jessie Lite 9-28-2016](http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2016-09-28/)
Once that is done we need to setup the Pi Zero to be used as a ethernet gadget. This will allow us to program it from our computer when it is plugged in to the usb port.&nbsp;

Follow the Ethernet Gadget and Ethernet Tweaks steps in the following guide. I did not need to do the fixed IP step.

[Turning your Raspberry PI Zero into a USB Gadget](https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/ethernet-gadget)
To connect to the Raspberry Pi we will use SSH. If you are not familiar with using SSH to access the Raspberry Pi follow this guide and then come back to here

[Adafruit's Raspberry Pi Lesson 6. Using SSH](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/test-and-configure?view=all)
Now we can connect to the Raspberry Pi using SSH. The hostname we will be connecting to is **raspberrypi.local**

![](https://cdn-learn.adafruit.com/assets/assets/000/037/735/medium800/raspberry_pi_Screenshot_2016-12-04_13.37.11.png?1480880413)

Now is also a good time to change the default password to something more secure. Enter `passwd` and follow the prompts.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/788/medium800/raspberry_pi_passwd.jpg?1480979462)

Before moving to the next step we need to make sure we can connect to the internet. We will ping google.com

`ping -c 5 google.com`

# Digital Free Library

## Install Apache

We will be using Apache for the Web Server. These install instructions were taken from the Raspberry Pi Foundation website. Their guide can be found at&nbsp;[www.raspberrypi.org/documentation/remote-access/web-server/apache.md](https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md)

We will start with installing apache using the following command in terminal. This will take about 5 minutes to install.

`sudo apt-get install apache2 -y`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/579/medium800/raspberry_pi_apacheinstall.jpg?1480188270)

&nbsp;Next we will navigate to where this was just installed.

`cd /var/www/`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/580/medium800/raspberry_pi_apache_dir_change.jpg?1480188739)

Currently we do not have permissions to the folder html. We will need permissions so we can change the index page and add our files. To do this we will enter this in.

`sudo chown pi: html`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/581/medium800/raspberry_pi_apache_chown.jpg?1480188749)

To test that Apache installed correctly we will open a web browser and go to

`http://raspberrypi.local/`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/582/medium800/raspberry_pi_apache_test.jpg?1480189160)

We now want to leave this folder and go back to the main directory. We will have issues later in the guide if we stay in **/var/www** , to exit just enter

`cd`

# Digital Free Library

## Configure Access Point

For setting up the Raspberry Pi as an access point we will be using most of the steps from the [Setting up a Raspberry Pi as a WiFI access point guide](../../../../setting-up-a-raspberry-pi-as-a-wifi-access-point/overview?view=all)&nbsp;but with some changes for our project.

First&nbsp;we install the software onto the Raspberry Pi that will act as the 'hostap' (host access point)&nbsp;

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

![](https://cdn-learn.adafruit.com/assets/assets/000/037/558/medium800/raspberry_pi_aptgethostapd.gif?1480177648)

# Set up DHCP server

Next we will edit **/etc/dhcp/dhcpd.conf** , a file that sets up our DHCP server - this allows wifi connections to automatically get IP addresses, DNS, etc.  
  
Run this command to edit the file

`sudo nano /etc/dhcp/dhcpd.conf`

Find the lines that say

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

and change them to add a # in the beginning so they say

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

Find the lines that say

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

and remove the # so it says

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

![](https://cdn-learn.adafruit.com/assets/assets/000/037/560/medium800/raspberry_pi_authoritatinve.gif?1480177962)

Then scroll down to the bottom and add the following lines

```
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;
}
```

![](https://cdn-learn.adafruit.com/assets/assets/000/037/561/medium800/raspberry_pi_subnet.png?1480178052)

Save the file by typing in **Control-X** then **Y** then **return**  
  
Run

`sudo nano /etc/default/isc-dhcp-server`

and scroll down to **INTERFACES=""** and update it to say **INTERFACES="wlan0"**

Or whatever the name of your wifi adapter is!

![](https://cdn-learn.adafruit.com/assets/assets/000/037/562/medium800/raspberry_pi_dhcpwlan0.gif?1480178098)

close and save the file

# Set up wlan0 for static IP

If you happen to have wlan0 active because you set it up, run **sudo ifdown wlan0**  
There's no harm in running it if you're not sure.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/596/medium800/raspberry_pi_Screenshot_2016-11-26_13.50.57.png?1480377628)

Next we will set up the **wlan0** connection to be static and incoming. Run `sudo nano /etc/network/interfaces` to edit the file  
  
Find the line **auto wlan0** and add a **#** in front of the line, and in front of every line afterwards. If you don't have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old **wlan0** configuration settings, we'll be changing them up  
  
Depending on your existing setup/distribution there might be more or less text and it may vary a little bit  
  
Add the lines

```
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
```

After **allow-hotplug wlan0** - see below for an example of what it should look like.&nbsp; Any other lines afterwards should have a **#** in front to disable them

![](https://cdn-learn.adafruit.com/assets/assets/000/037/564/medium800/raspberry_pi_staticip.gif?1480178212)

Save the file (Control-X Y )   
  
Assign a static IP address to the wifi adapter by running   
`sudo ifconfig wlan0 192.168.42.1`

We will get an error message since we do not have a device connected to wlan0 at the moment.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/597/medium800/raspberry_pi_Screenshot_2016-11-26_13.53.59.png?1480377832)

# Configure Access Point

Now we can configure the access point details.&nbsp;  
  
Create a new file by running `sudo nano /etc/hostapd/hostapd.conf`  
  
Paste the following in, you can change the text after **ssid=** to another name, that will be the network broadcast name.

The password can be changed with the text after **wpa\_passphrase=&nbsp;**

To enable a password remove the **#** in front of **&nbsp;** the 5 lines that have wpa in them

```
interface=wlan0
#driver=rtl871xdrv
ssid=Pi_AP
country_code=US
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=CCMP
#wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
```

I have found that it will load the correct drivers if you comment out the line **driver=rtl871xdrv**

![](https://cdn-learn.adafruit.com/assets/assets/000/037/598/medium800/raspberry_pi_Screenshot_2016-11-26_13.54.59.png?1480378037)

Save as usual. Make sure each line has no extra spaces or tabs at the end or beginning - this file is pretty picky!  
  
Now we will tell the Pi where to find this configuration file. Run `sudo nano /etc/default/hostapd`  
  
Find the line **#DAEMON\_CONF=""** and edit it so it says **DAEMON\_CONF="/etc/hostapd/hostapd.conf"**  
Don't forget to remove the **#** in front to activate it!  
  
Then save the file

![](https://cdn-learn.adafruit.com/assets/assets/000/037/567/medium800/raspberry_pi_hostapdconf.gif?1480178441)

Likewise, run **sudo nano /etc/init.d/hostapd** and find the line

`DAEMON_CONF=`

and change it to

`DAEMON_CONF=/etc/hostapd/hostapd.conf`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/568/medium800/raspberry_pi_daemoncofng.png?1480178485)

# Update hostapd

&nbsp;_I have added this step as required since I could not get it to work with the usb wifi module until I did this._

Before we can run the access point software, we have to update it to a version that supports the WiFi adapter.   
First get the new version by typing in

`wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip`

to download the new version (check the next section for how to compile your own updated **hostapd** ) then

`unzip adafruit_hostapd_14128.zip`

to uncompress it. Move the old version out of the way with

`sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG`

And move the new version back with

`sudo mv hostapd /usr/sbin`

set it up so its valid to run with

`sudo chown root:root /usr/sbin/hostapd`

`sudo chmod 755 /usr/sbin/hostapd`

![](https://cdn-learn.adafruit.com/assets/assets/000/037/571/medium800/raspberry_pi_swaphostapd.gif?1480178694)

# Finishing up!

Now it is time to set it up as a 'daemon' - a program that will start when the Pi boots.

To set the&nbsp;daemon services&nbsp;to run every time on boot enter these commands.

> **sudo update-rc.d hostapd enable**   
> **sudo update-rc.d**  **isc-dhcp-server enable**

![](https://cdn-learn.adafruit.com/assets/assets/000/037/600/medium800/raspberry_pi_updaterc.gif?1480378872)

# Digital Free Library

## Understanding the Webpage

I have made a simple website that can&nbsp;be uploaded to the Raspberry Pi and show the media to download.

[digitallibrary.zip](https://cdn-learn.adafruit.com/assets/assets/000/037/790/original/digitallibrary.zip?1480980490)
Once you have the file downloaded you can open the index.html file in a word editing program such as WordPad and edit the links for the images and files if you want to add or remove books.

Each book has this piece of code in the file.

```
&lt;div class="responsive"&gt;
  &lt;div class="img"&gt;
  &lt;a target="_top" href="issues/coloringbook_1-23-2014.pdf"&gt;
    &lt;img src="images/rforrobot.jpg" &gt;
  &lt;/a&gt;
  &lt;div class="desc"&gt;&lt;p&gt;Ladyada's R is for Robotics is a coloring book adventure with robots, their inventors and more.&lt;/p&gt;
&lt;p&gt;Makers of all ages can learn, color and share their favorite robots and roboticists.&lt;/p&gt;
&lt;a href="https://www.adafruit.com/products/1936" target="_blank"&gt;https://www.adafruit.com/products/1936&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
```

To add aditional books to the page paste the code shown above before the **\</body\>** tag in the html file.

If you want to target a different file change the section

```
&lt;a target="_top" href="issues/coloringbook_1-23-2014.pdf"&gt;
```

Files are placed in the **issues** folder.&nbsp;

For changing the image that shows you would change the line with

```
&lt;img src="images/rforrobot.jpg" &gt;
```

&nbsp;For images we named the folder **images**

You change either folder to any name, but just make sure the code is pointing to the right folder.

To change the description under the image we would edit this part of the code from earlier.

```
&lt;div class="desc"&gt;&lt;p&gt;Ladyada's "E is for Electronics" is a coloring book adventure with electronic components and their inventors.&lt;/p&gt;
&lt;p&gt;Makers of all ages can learn, color, and share common parts and historical figures throughout history. Explore the world of electronics with Ladyada as your guide!&lt;/p&gt;
&lt;a href="https://www.adafruit.com/products/1000" target="_blank"&gt;https://www.adafruit.com/products/1000&lt;/a&gt;&lt;/div&gt;
```

# Digital Free Library

## Transferring The Files

To get our html page and files to the Raspberry Pi we will be using WinSCP.

[Download WinSCP](https://winscp.net/eng/download.php)
Once&nbsp;WinSCP is installed we will open it up and put in&nbsp; **raspberrypi.local** for the Host name. You can also enter the username and password now or it will prompt you for that info&nbsp;later.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/641/medium800/raspberry_pi_Screenshot_2016-11-28_19.29.44.png?1480639272)

Now we will click Login.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/642/medium800/raspberry_pi_Screenshot_2016-11-28_19.31.14.png?1480639336)

Once we are connected and logged in we will be put in the **/home/pi** directory. The left side window is your pc and the right side window is the Raspberry Pi

![](https://cdn-learn.adafruit.com/assets/assets/000/037/643/medium800/raspberry_pi_Screenshot_2016-11-28_19.31.50.png?1480639424)

We need to go up two&nbsp;directories. So double-click on the folder with the up arrow twice.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/644/medium800/raspberry_pi_Screenshot_2016-11-28_19.32.03.png?1480639542)

Now we are in the root folder. We need to get to **/var/www/html** , Double-click on the folder labeled **var** , then double-click on the folder labeled **www** , and finally double click the folder labeled **html**

![](https://cdn-learn.adafruit.com/assets/assets/000/037/645/medium800/raspberry_pi_Screenshot_2016-11-28_19.32.25.png?1480639682)

We first need to delete the index.html file currently there. Then&nbsp;drag the files downloaded previously to this directory.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/646/medium800/raspberry_pi_Screenshot_2016-11-28_19.35.25.png?1480639811)

# Digital Free Library

## Change Hostname

Currently the Hostname is at the default of raspberrypi, we want something more suited for this project. I will be using **library** , you could use any name you want or keep it at the default.

To change the hostname we will type

`sudo raspi-config`

Then select Advanced Options

![](https://cdn-learn.adafruit.com/assets/assets/000/037/764/medium800/raspberry_pi_Screenshot_2016-12-04_18.10.45.png?1480896790)

Then select Hostname

![](https://cdn-learn.adafruit.com/assets/assets/000/037/765/medium800/raspberry_pi_Screenshot_2016-12-04_18.10.52.png?1480896852)

Now you can enter in the Hostname you want to use.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/766/medium800/raspberry_pi_Screenshot_2016-12-04_18.11.13.png?1480896922)

Once you exit the config it will ask if you would like to reboot. Select yes.

When you connect using SSH you will need to enter the new hostname **library.local**

# Digital Free Library

## Connecting To The Library

With the WiFi Dongle plugged in and the Raspberry Pi powered up we should see a Wifi connection labeled **Pi\_AP** or what you had renamed the SSID to earlier. Select that network to connect to. Depending on your device used you might get a no internet connection warning.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/768/medium800/raspberry_pi_wifi.jpg?1480900725)

In your web browser go **library.local** this may be different if you used a different hostname.

![](https://cdn-learn.adafruit.com/assets/assets/000/037/929/medium800/raspberry_pi_File_Dec_08__4_49_39_PM.png?1481237509)

The library.local link works for most web browsers that I tested except Microsoft Edge. On the Edge browser you need to put in the IP adress. From an earlier step we set that to **192.168.42.1**

![](https://cdn-learn.adafruit.com/assets/assets/000/037/769/medium800/raspberry_pi_webpage.jpg?1480900733)


## Featured Products

### Raspberry Pi Zero - Version 1.3

[Raspberry Pi Zero - Version 1.3](https://www.adafruit.com/product/2885)
At first glance, the Pi Zero isn't much. &nbsp;It just looks like a slimmed down version of the Raspberry Pi we know and love. &nbsp;But when we started to think of the possibilities - [and what a well-chosen set of accessories could add](https://www.adafruit.com/product/2816) -...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2885)
[Related Guides to the Product](https://learn.adafruit.com/products/2885/guides)
### 8GB SD Card with Raspbian Stretch Operating System

[8GB SD Card with Raspbian Stretch Operating System](https://www.adafruit.com/product/2767)
![Raspbian](../images/rasp.png)

Raspbian **"Stretch"** is the newest stable operating system based on Debian Linux. &nbsp;It's an update of the super popular Raspbian Jessie - with myriad bug fixes and tweaks as...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2767)
[Related Guides to the Product](https://learn.adafruit.com/products/2767/guides)
### Mini USB WiFi Module - RTL8188eu - 802.11b/g/n

[Mini USB WiFi Module - RTL8188eu - 802.11b/g/n](https://www.adafruit.com/product/2810)
This cute little dongle is perfect for making your Raspberry Pi&nbsp;cable-free by adding WiFi. Take advantage of the Raspberry Pi's USB port to add a low cost, but high-reliability wireless link. &nbsp;You'll have wireless Internet in 10 minutes! Works great with 802.11b/g/n...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2810)
[Related Guides to the Product](https://learn.adafruit.com/products/2810/guides)
### Tiny OTG Adapter - USB Micro to USB

[Tiny OTG Adapter - USB Micro to USB](https://www.adafruit.com/product/2910)
This super slim, super tiny, and super cute Micro-B&nbsp;to USB on-the-go adapter is so slim, tiny, and cute that we'd pinch its cheeks if it was big enough to have cheeks. &nbsp;At just ~15.5mm long, ~11.3mm wide, and ~2mm, this really is the tiniest little adapter we've probably ever...

In Stock
[Buy Now](https://www.adafruit.com/product/2910)
[Related Guides to the Product](https://learn.adafruit.com/products/2910/guides)
### Adafruit Raspberry Pi Zero Case

[Adafruit Raspberry Pi Zero Case](https://www.adafruit.com/product/3252)
This is a basic, classic **Pi Zero enclosure** with a black base and a clear top.&nbsp;The case is as minimal as it gets, coming in just two pieces of polycarbonate that snap snugly together. This case will keep your&nbsp;Pi Zero safe and secure while also looking super sleek. You...

In Stock
[Buy Now](https://www.adafruit.com/product/3252)
[Related Guides to the Product](https://learn.adafruit.com/products/3252/guides)
### ModMyPi Pi Zero Case - Frost/Clear

[ModMyPi Pi Zero Case - Frost/Clear](https://www.adafruit.com/product/3288)
Still searching for the Pi Zero enclosure&nbsp;that works for you? Try out this fully injection molded Raspberry Pi Zero case from ModMyPi! Designed to optimise protection whilst maintaining device useability, this Pi Zero case&nbsp;consists of a 3-part clip together construction with microSD...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3288)
[Related Guides to the Product](https://learn.adafruit.com/products/3288/guides)
### USB Patterned Fabric Cable - A/MicroB

[USB Patterned Fabric Cable - A/MicroB](https://www.adafruit.com/product/2008)
Oooh it's so soft! And that beautiful&nbsp;pattern! If you have to have visible cables&nbsp;then you might as well have the nicest fabric bound cable with a eye-catching snake-like pattern. &nbsp;That's why we now carry this standard A to micro-B USB cable&nbsp;for USB 1.1 or 2.0....

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2008)
[Related Guides to the Product](https://learn.adafruit.com/products/2008/guides)

## Related Guides

- [Pi Hole Ad Blocker with Pi Zero W](https://learn.adafruit.com/pi-hole-ad-blocker-with-pi-zero-w.md)
- [Haunted Portrait](https://learn.adafruit.com/haunted-portrait.md)
- [Adafruit Joy Bonnet for Raspberry Pi](https://learn.adafruit.com/adafruit-joy-bonnet-for-raspberry-pi.md)
- [Weather Wise Wifi Umbrella Stand](https://learn.adafruit.com/weather-wise-wifi-umbrella-stand.md)
- [Using ItsaSNAP for HomeKit PIR Motion Detection](https://learn.adafruit.com/itsasnap-homekit-pir-motion-detection.md)
- [Using Adafruit IO Actions to Make an IoT Door Detector](https://learn.adafruit.com/using-adafruit-io-actions-to-make-an-iot-door-detector.md)
- [How to register your drone in the US](https://learn.adafruit.com/how-to-register-your-drone-in-the-usa.md)
- [Boomy Pi Airplay Boombox](https://learn.adafruit.com/boomy-pi-airplay.md)
- [How to Make Games in MakeCode Arcade](https://learn.adafruit.com/how-to-make-games-on-makecode-arcade.md)
- [Skill Badge Requirements: Digi XBee](https://learn.adafruit.com/skill-badge-requirements-digi-xbee.md)
- [Adafruit QT Py ESP32-S3](https://learn.adafruit.com/adafruit-qt-py-esp32-s3.md)
- [AdaBox 004](https://learn.adafruit.com/adabox004.md)
- [OSHWA Project Display With Adafruit MagTag](https://learn.adafruit.com/oshwa-project-display-with-adafruit-magtag.md)
- [Control Wiz Lights With CircuitPython](https://learn.adafruit.com/control-wiz-lights-with-circuitpython.md)
- [Using LoraWAN and The Things Network with CircuitPython](https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython.md)
