Skip to content
Code for the R2-D2 nightlight to run on a local (home network) server/pi.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
css
img
js
scripts
sounds
README.md
index.php
starwars.mp3

README.md

Intranet controlled R2-D2 nightlight

Greetings! This is the repository for a local version of the R2-D2 nightlight that lives here: http://r2d2.hyperjoule.io

To make this nightlight, you will need the following supplies:

The nighlight itself, you are going to pretty much gut - take the bottom off completely, use wire cutters to cut everything out except the base that supports the acrylic, and you might even need to trim that down. You are also going to need to widen the hole in the back of the base in order to get that usb power cable through to the pi. Throw away all the existing electronics -- you don't need them, the only thing you need for this project is the round base and acrylic.

This README.md only covers the R2-D2 nightlight in LOCAL MODE (setting up a web server on EC2, creating ssh keys back and forth to your home network, host port forwarding -- it is a bit of a process) on your home network. For that reason, I suggest setting your pi-zero-w to have a static IP on your network. Read your router configuration manual on how to set up a static IP.

Burn a copy of raspbian to an sd card and set up your pi-zero-w on your local network. Make sure the following interfaces are enabled on your pi

sudo raspi-config
  • SSH
  • SPI
  • I2C
  • Remote GPIO

Also, while in the configuration screen, make sure your keyboard settings and localization settings are correct. You might want to change your hostname from the default as well

There are some things you are going to need to install on your raspberry pi in order to run this code.

Once your raspberry pi is setup on your home network, ssh to it on your home network with pi@127.0.[whatever the rest of the local ip is] or by ssh pi@hostname.local if you have bonjour service installed.

Run:

sudo apt-get update
sudo apt-get upgrade
Now that that's done, we need to make some changes on the pi itself. Run the following command:
sudo visudo
Select 2 nano as your editor. Add this line:
# Members of the admin group may gain root privileges
%admin  ALL=(ALL) NOPASSWD:ALL
CTRL-X to save. Now we need to edit our user groups:
sudo vigr
Confirm 2 as your editor again. Scroll to where the admin group is listed and change the line to this:
admin:x:1001:pi,www-data
CTRL-X to save. What you have just done is allow www-data to execute sudo commands -- necessary to run the python scripts that drive the UNICORN pHAT.

Next step is to configure the pi to talk to the unicorn pHat.

sudo raspi-config

Now you are ready to install your webserver. Follow this guide here: https://howtoraspberrypi.com/how-to-install-web-server-raspberry-pi-lamp/

The next step is to install the packages and dependencies your nightlight is going to need to run. The documentation for the unicorn pHat is here. Pimoroni has made a really great nifty little install tool that makes setting up the unicorn pHat a breeze. https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-unicorn-phat.

curl https://get.pimoroni.com/unicornhat  | bash
There are also some additional libraries required for some of the python scripts:
sudo apt-get install python-pip
sudo pip install requests
sudo pip install numpy
sudo pip install webcolors

Move all the files in this repo to /var/www/html. Make sure your permissions are correct and everything in /var/www/html/scripts is executable:

cd ~/scripts
sudo chmod 755 *
And... reboot your pi:
 sudo reboot
 
Once your pi has rebooted, point your web browser to its IP on your network or hostname.local and have fun!

Todo: Clean up mobile - having issues closing the bootstrap color changing modal on my phone

-- hyperjoule.io

You can’t perform that action at this time.