Write up of hardware

This commit is contained in:
Laura 2017-02-17 15:39:43 +00:00
parent c60046687f
commit 92db1a6bcd
11 changed files with 122 additions and 8 deletions

View file

@ -0,0 +1,80 @@
from picamera import PiCamera
from gpiozero import Button
from overlay_functions import *
from time import gmtime, strftime
from guizero import App, PushButton, Text, Picture
from twython import Twython
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
# Tell the next overlay button what to do
def next_overlay():
global overlay
overlay = next(all_overlays)
preview_overlay(camera, overlay)
# Tell the take picture button what to do
def take_picture():
camera.capture(output)
camera.stop_preview()
remove_overlays(camera)
output_overlay(output, overlay)
# Save a smaller gif
size = 400, 400
gif_img = Image.open(output)
gif_img.thumbnail(size, Image.ANTIALIAS)
gif_img.save(latest_photo, 'gif')
# Set the gui picture to this picture
your_pic.set(latest_photo)
def new_picture():
camera.start_preview(alpha=128)
preview_overlay(camera, overlay)
def send_tweet():
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
# Send the tweet
message = "The All Seeing Pi saw you!"
with open(output, 'rb') as photo:
twitter.update_status_with_media(status=message, media=photo)
# Set up buttons
next_overlay_btn = Button(23)
next_overlay_btn.when_pressed = next_overlay
take_pic_btn = Button(25)
take_pic_btn.when_pressed = take_picture
# Set up camera (with resolution of the touchscreen)
camera = PiCamera()
camera.resolution = (1024, 768)
camera.hflip = True
# Start camera preview
camera.start_preview(alpha=128)
# Set up filename
output = strftime("/home/pi/allseeingpi/image-%d-%m %H:%M.png", gmtime())
latest_photo = '/home/pi/allseeingpi/latest.gif'
app = App("The All Seeing Pi", 800, 480)
#app.attributes("-fullscreen", True)
message = Text(app, "I spotted you!")
your_pic = Picture(app, latest_photo)
new_pic = PushButton(app, new_picture, text="New picture")
tweet_pic = PushButton(app, send_tweet, text="Tweet picture")
app.display()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

BIN
images/IMG_2167.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
images/asp-cardboard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 KiB

BIN
images/asp-lasercut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 KiB

BIN
images/connect-camera.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 137 KiB

View file

@ -3,6 +3,11 @@
To install the software you need, run the following commands in the terminal:
```bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install raspberrypi-ui-mods
sudo apt-get install raspberrypi-net-mods
sudo apt-get install python3-picamera python3-pip
sudo pip3 install guizero
sudo pip3 install twython

View file

@ -2,10 +2,31 @@
In this resource you will make a tweeting touch screen photo booth using a Raspberry Pi.
## Making the photo booth
## Making the photo booth housing
You can create your All Seeing Pi using any housing you like. Our first iteration used a humble cardboard box, but you might want to create a masterpiece of carpentry or laser cutting wizardry to hold your All Seeing Pi.
Carrie Anne / James to write up how they set up the touch screen, camera and button hardware
![All Seeing Pi in a cardboard box](images/asp-cardboard.png)
Buttons wired to pins 23 and 25 please
## Connecting the Raspberry Pi touch screen
Then a [link to worksheet 2](worksheet2.md)
1. Set up your Raspberry Pi touch screen. There is a [good tutorial](https://thepihut.com/blogs/raspberry-pi-tutorials/45295044-raspberry-pi-7-touch-screen-assembly-guide) available to help you. Ensure that you power the touch screen via the Raspberry Pi with jumper leads as shown in the tutorial, and that the power supply you use is a good quality one.
1. Situate your screen within the housing of your choice, ensuring you can still access the Raspberry Pi.
## Connecting the camera
1. Connect the PiCamera to the Raspberry Pi with the blue side of the connector facing the USB ports:
![Connect the camera](images/connect-camera.png)
1. Situate the camera in place in your chosen housing. If you are using glue to secure the camera in place, be careful not to get any glue onto the connectors or camera components or they may stop working.
## Connecting the buttons
1. Using jumper leads, wire up one button to pin 23 and any ground pin, and the other button to GPIO 25 and any ground pin.
1. Situate the buttons in your chosen housing. In the software, the button connected to GPIO 23 will select the next overlay, and the button connected to GPIO 25 will take the picture. (Don't worry if you accidentally wire your buttons up the other way around, simply swap the pin numbers in the code!)
![All Seeing Pi in a laser cut box](images/asp-laser.png)
Once you have set up your hardware, head over to [worksheet 2](worksheet2.md) to find out how to write the software to control your All Seeing Pi.

View file

@ -56,7 +56,7 @@ With the hardware set up, we can begin to program the software that will make ev
![Test the buttons](images/test-buttons.png)
# Set up the camera
## Set up the camera
1. Now that we know the buttons work, let's set up the camera. First add an import statement with the others at the top:
@ -241,9 +241,9 @@ You probably don't want your photo booth participants to have to go digging thro
If you just want a fun photo booth to take and save pictures, you could stop there. Alternatively, why not go one step further and make your All Seeing Pi tweet the photo that was taken.
1. You will need to set up a Twitter account and create an app for your All Seeing Pi. Follow steps 1-4 on the [Getting started with the Twitter API](https://www.raspberrypi.org/learning/getting-started-with-the-twitter-api/worksheet/) resource in a separate file and check that you can send a text tweet from Python.
1. You will need to set up a Twitter account and create an app for your All Seeing Pi. Follow steps 1-4 on the [Getting started with the Twitter API](https://www.raspberrypi.org/learning/getting-started-with-the-twitter-api/worksheet/) resource in a separate file and check that you can successfully send a text tweet from Python.
1. Save a copy of the `auth.py` file containing your Twitter API keys (which created during the "Getting started" tutorial) inside your `/home/pi/allseeingpi` folder.
1. Save a copy of the `auth.py` file containing your Twitter API keys (which you created during the "Getting started" tutorial) inside your `/home/pi/allseeingpi` folder.
1. Go back to your `allseeingpi.py` file and after the other import statements, import Twython:
@ -280,7 +280,7 @@ If you just want a fun photo booth to take and save pictures, you could stop the
)
```
1. Add some code that will tweet the `output` picture:
1. Add some more code inside the `send_tweet()` function to tweet the `output` picture. You can change the `message` if you want your tweet to say something different:
```python
message = "The All Seeing Pi saw you!"
@ -299,3 +299,11 @@ If you just want a fun photo booth to take and save pictures, you could stop the
1. Save and run your program. Test that when you take a picture and press the **Tweet picture** button on the GUI, the picture is tweeted from your twitter account.
![Tweeted picture](images/tweet-result.png)
The finished code is [here](code/finished_allseeingpi.py) for you to check against yours.
## What next?
- Can you add a text box or perhaps a touch screen keyboard to your GUI to allow someone to enter their Twitter handle?
- Can you add an `@username` mention to the tweet text, using the Twitter handle that was entered via the GUI?
- Could you make a more imaginative housing for your All Seeing Pi?