Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teeest #60

Closed
wants to merge 41 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
60a6dc3
Started the christmas decorations post
softarn Dec 1, 2014
6113499
First draft of Snowglobe done.
softarn Dec 1, 2014
e62f7fc
Added christmast-craft images
softarn Dec 1, 2014
471286b
Changed size of image
softarn Dec 1, 2014
4428c81
Updated 2014-3-3-Hello-World.md
softarn Dec 1, 2014
06b8e8b
Updated config
softarn Dec 1, 2014
0d96e90
Updated images size
softarn Dec 1, 2014
d57f52b
Updated 2014-3-3-Hello-World.md
softarn Dec 1, 2014
7dbcd7e
Added profile picture
softarn Dec 1, 2014
ce38331
Updated 2014-3-3-Hello-World.md
softarn Dec 1, 2014
90d22ec
Updated 2014-3-3-Hello-World.md
softarn Dec 1, 2014
b130cbe
Updated 2014-3-3-Hello-World.md
softarn Dec 1, 2014
8955e3b
Added new images
softarn Dec 3, 2014
9050d64
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
047a5ef
Deleted 2014-3-3-Hello-World.md
softarn Dec 3, 2014
33c7449
Updated Control snowglobe with Raspberry Pi
softarn Dec 3, 2014
d6f928e
Deleted 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
bf97961
Updated Control snowglobe with Raspberry Pi
softarn Dec 3, 2014
1e128f4
Updated Control snowglobe with Raspberry Pi
softarn Dec 3, 2014
c0b84de
Updated Control snowglobe with Raspberry Pi
softarn Dec 3, 2014
f431540
Updated Control snowglobe with Raspberry Pi
softarn Dec 3, 2014
b3d9da0
Created 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
1d8d77a
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
27e3a3b
Updated Test
softarn Dec 3, 2014
587dfd2
Deleted 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
5069bdb
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
5c76e04
Deleted Test
softarn Dec 3, 2014
9621919
Resized picture
softarn Dec 3, 2014
a3f3664
Added title
softarn Dec 3, 2014
5eb484a
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
a180b20
Resized picture
softarn Dec 3, 2014
d5c8cd8
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
cf169ec
Added code
softarn Dec 3, 2014
21b12d9
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
7a19178
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
99a3735
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
b399bd4
Updated 2014-12-3-christmas-craft-raspberry-pi.md
softarn Dec 3, 2014
661dfc7
Updated finished img
softarn Dec 3, 2014
09fd833
Fixed linked in link
softarn Dec 3, 2014
d5d9bce
Fixed urls
softarn Dec 3, 2014
d2fa823
Updated 404
Dec 5, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated 2014-12-3-christmas-craft-raspberry-pi.md
  • Loading branch information
softarn committed Dec 3, 2014
commit 5069bdba56f840451465418dd8709e8abf8e5142
54 changes: 54 additions & 0 deletions _posts/2014-12-3-christmas-craft-raspberry-pi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
layout: post
title: ""
published: true
---

Christmas is around the corner and it is time for some geeky Christmas Crafts! Got an RaspberryPi from a hack night at iZettle and wanted to make something fun out of it, decided on "Git merge activated snowglobe". If the name doesn't say it all, it's an electronic snowglobe that is gonna start "snowing" and playing christmas music each time someone merges a pull request on Github.

## What you need

**Hardware**

- RaspberryPi
- Electric snowglobe or similar that can be turned on by button
- Cables (like these: http://goo.gl/jYLQuW)
- A transistor
- Tape (some people would probably advocate soldering here)
- Tools for opening the snowglobe

**Software**

- Heroku or similar
- Node.js
- Redis db

## Putting the hardware together
This is the snowglobe I found at a toys store. It plays 8 songs, whisps around some styrofoam and is powered by 3 1.5v AA batteries.

Opening it up it was really easy to modify it by cutting the cables. I started out with cutting the wires to the battery pack and replacing hooking it up to the RasPi. To strip the cable I just used a normal scissor and to make sure it doesn't pop out I used some normal tape. First make it work, then make it better :) At least I'm using the correct colors!

![Wiring the power cables](/images/christmas-craft/power_wiring.jpg)

It was running as expected so I continued with replacing the button. To simulate a button I used a transistor. A transistor has three pins, the outer two which the wires that previously were connected to the button should be connected to, and the middle one which should be connected to a pin on the RasPi. To test this out, connect the power cables to the RasPi and the button cables to the transistor, then tap the cable connected to the middle pin on one of the 3v pins on the RasPi. If works as expected this should start the snowglobe just as if you'd press the button. If that is the case then connect the cable to one of the pins on the RasPi which is not ground or power supply. I connected it to pin number 10.

![Transistor wiring](/images/christmas-craft/transistor.jpg)
![Connect to Raspberry Pi](/images/christmas-craft/raspi.jpg)

So with all the physical stuff running let's get coding.

## Writing the code
The software is going to consist of two parts, one small server that will receive POST messages from Github and expose a small API with information if a merge has been done or not, and the code on the RasPi that will make a request to the API every second.

### Server
The server needs one endpoint that can receive POST messages from Github webhooks, parse the message and see if a merge has been done and save the information to Redis.

The other endpoint is called by the RasPi to determine if it should "press" the button or not. It gets the information from Redis, returns true if the button should be pressed and then resets the information on Redis so it returns false the next time.

### Rasberry Pi
The code on the RasPi is just an infinite loop that makes a request to the server a couple of times every second. If the server returns true in the request, the RasPi turns on the power on the pin connected to the transistor for 100ms, which simulates a button press and turns on the snowglobe.


![_config.yml]({{ site.baseurl }}/images/config.png)

The easiest way to make your first post is to edit this one. Go into /_posts/ and update the Hello World markdown file. For more instructions head over to the [Jekyll Now repository](https://github.com/barryclark/jekyll-now) on GitHub.