This is my general blog for my innermost thoughts and feelings. Unfortunately I can add posts from my mobile so there may be a lot of crazy rants on here
Been wanting to do this one since I got my first Pi!
In my old (now old-old-) job, I worked a lot with temperature monitoring (and various other metrics), which I loved because I'm a giant nerd and I love data! I've written a few posts about various logging projects that I've half-baked with Arduinos, but really wanted to take a step up with the Raspberry Pi.
I bought a USB temperature probe on eBay for about £8 (~$12). The software with it is a bit rubbish and I wanted to integrate it into something bigger. Finally I found a script which works in Linux, which made it perfect to attach to a Raspberry Pi!
The finished product is fully self-contained, featuring its own Web interface with purdy graphs. It's currently hooked up to a home beer making kit in my cupboard :)
Temperatures are really high in the graph above because I hooked the probe up to the central heating pipes
Installation - It's all packaged into a nice shell script so the intricate bits are all taken care of
NB: all of this can be done from the console - if you're like me, none of your Raspberry Pi projects will have screens attached so you should get comfortable with using the console instead of the graphical interface. This means you save on a lot of resources (processing power!!!) and you can remotely access the RPi over SSH. Anyhoo, on to the real stuff...
Start your RPi
If you're working from a fresh install of Raspbian: (if you've already done this, then skip to #3)
Start raspi-config (it may auto-start, if not type "sudo raspi-config" without quotes, then hit enter)
Note: You're going to get two identical graphs at the start - the left hand on displays the last 60 minutes, the right hand one displays the last 8 hours
Note 2: The web page is optimised for mobile phone viewing ;)
How does it work?
pcsensor.c / pcsensor
Someone (first link at the bottom) has very kindly written a small C program which simply reads the current temperature and outputs it to the console. I has to modify it slightly so that when you call it with an argument ("pcsensor -c"), it only outputs the temperature.
log_pcsensor.sh
Now that we have a way to read the data, it's simply a case of sending this data to a database table every so often (I chose every 1 minute). The log_pcsensor.sh file is a shell script which takes the output from the pcsensor script and inserts a new record into the database every time the script is called
cron job
cron is a Linux background service which executes scripts according to a schedule. I just added a job to cron to call the log_pcsensor.sh script every 1 minute
temps.php and tempgraph.php
temps.php - Data isn't awesome unless we can read and interpret it! I started off with a very simple php page which displayed the latest temperature, and a table with the previous 25 readings. It was cool, but not cool enough!
tempgraph.php - Then I thought, "Why can't I graph it?" So I researched some graphing packages for PHP, found one I liked (JpGraph), and created a page which will read the database and display a graph of the data.
setup_pcsensor.sh
Finally, I knew I was going to have to blog about this (I feel better as a person when I see my page views go up!) so I decided to make it easy for people to install. It's probably not the most educational way to present the project (the RPi is, after all, an educational tool), but I prefer to learn by example rather than blindly follow a list of instructions.
The Raspberry Pi is a fantastically versatile, cheap and tiny computer. It's very easily comparable to the ever popular Arduino, except that it provides significantly more processing power and programming options. One of the major drawbacks to this power, however, is the increased power consumption which makes powering the device problematic.
Power
For example, a standard Arduino Uno requires mere tens of milliamps (mA) to function at full power (nanoamps in sleep mode), while the RPi is rated at 700mA. This means it can't technically be powered from a standard USB port because USB 1.0, 1.1 and 2.0 permit a maximum power draw of 500mA.
You need a wall adapter to supply that 700mA, or more with peripherals such as wifi. The idea if powering it off a small lithium-ion battery or standard AAs is completely out the window.
One field which is particularly experienced at supplying huge amounts of electrical power is the field of remote control (cars,boats, airplanes, flying blimps with faces on them [LINK]). All of the batteries and technologies we need already exist, we just need a way to join the two in the middle.
Enter the lithium polymer (LiPo) battery, and the ironically named Battery Eliminating Circuit (BEC)!
LiPo batteries are relatively new to the RC party and are more or less the favourite due to their high energy densities and performance. The photo above is my 2,200mAh Turnigy battery which I got off eBay for less than £10 (about $15). It can power my RPi plus wifi for about 3.5 hours on a full charge.
STOP!
An import safety note about LiPo batteries!!!
LiPo batteries are not for beginners, not for kids and not for adults who don't read safety precautions! Slightly over charging, over discharging or improper charging can cause serious explosions. Just looking at them funny can cause them to burst into flames!
Anyway, safety concerns aside, these are great batteries to make your RPi more mobile. Unfortunately a 3 cell (series) [more info] LiPo provides 11 - 12v, enough to fry the lovely RPi which you had to wait for14 weeks for delivery. That's where the BEC comes in!
BEC
A battery eliminating circuit is used to power the electronics in a RC airplane, which as chance would have it works on a RPi-friendly 5v. It takes the higher and variable battery voltage and turns it into 5v for your electronics. BECs are sometimes built into a larger speed controller and/or RC module, however standalone ones are available.
A note on efficiency:
BECs come in two varieties: switching and linear/unswitching. Linear ones rely on inefficient voltage regulators which waste a lot of the input power. Switching ones are a lot more efficient (mine is about 92%). It's worth the slight cost increase for a switching BEC.
Note that the terms UBEC (unswitching/linear) and SBEC (switching) are often confused. Particularly, Ultimate BEC is/was a brand of BEC, which was switching. Be sure to read the description when purchasing. (Thanks to the anonymous commenter for pointing this one out)
So that's what you need, now how do we put it all together?
1. Connectors for batteries
When buying a BEC, if you don't like soldering, make sure you buy one with the same connector as your battery. There are a few standard connectors, such as XT60 (my fav), JST, EC3, banana plug (should be avoided!!), and Traxxas. Make sure you buy a matching pair.
Obviously if you're a fan of soldering you're not limited here and can choose which ever BEC and battery you want.
Incidentally, you don't have to use LiPo batteries, you can use any battery which supplies a voltage which your BEC can handle (car batteries are 12v and around 40,000mAh!)
2. Connection to RPi
The only modification you need to make to your BEC is on the 5v side, at the connector to the RPi.
The pinout of a RC connector is one of the following:
If we were to plug our BEC in as it is we'd hear a pop and our RPi wouldn't work any more. Luckily its very easy to change the BEC without soldering or fancy tools
The connector of the BEC is made of a plastic case with metal pins inside, which clip in place with a springy bit of plastic on the case.
Simply take a knife, pin or screwdriver and GENTLY raise the spring. You may need to wiggle the wire up and down a bit, but it will come out. Now just make sure it's lined up right and pop it into the correct slot.
That's it! Now, this bit scares me because one slip and you potentially fry your RPi. It may help to disconnect your battery from the BEC first, connect the BEC to the RPi then reconnect the battery (you should never leave your battery connected to your BEC anyway when it's not in use).
To connect, set your RPi with the Ethernet and USB ports towards you (the SD slot facing away from you). Locate the golden pins at the top right of the board. Slide your connector on, with the RED wire to the TOP, RIGHT-MOST pin, and the BLACK wire two pins towards you.
Provided that the RPi lights up, you can begin to enjoy mobile and more flexible projects!
DONT STOP READING YET!!
Remember what I said about exploding batteries? Unless you want that to happen (hint: you don't) then pay attention!
When do you turn it off?
Unlike your laptop, the RPi has absolutely no way to monitor the voltage or remaining capacity of the battery. This is a problem for two reasons:
1 - for LiPo users, over discharging your battery causes copper deposits to form and damages your batteries. If this goes too far it can actually cause an internal short, and when you charge it again the whole thing goes on fire (seriously)
2 - for everyone, if your RPi is busy doing stuff, it'll just shut down all of a sudden when it runs out of juice. That may or may not be a problem, but will probably lead to data corruption if you're writing data at the time (like when you pull the plug on your PC)
The only solution I have at the minute is to time the how long it has been running and pull the plug manually. I do mean literally pull the plug, because the RPi uses a significant amount of power when "off" as it does while running (106mA according to my meter, vs 300-400mA when running. This is OK for NiMH batteries but a disaster for LiPos. I'd love to hear any suggestions anyone has for how to get around this.
Had a great day today! Finally used my Arduino camera controller for something useful - making a timelapse photo of our photo society's portrait session
The motivation After seeing Matt Richardson's video about his high-speed photography controller, I thought to myself "Wow, I want one of those!" And I had all the necessary bits, so I set about building one.
This post isn't going to be a how-to (I'll write one if enough people offer to buy me beer), but just general boasting about what it does.
What can it do?
Ok, so I now have a device which can trigger my camera's shutter, fire off a flashgun or turn a bunch of sockets on and off at my command. Just think of the possibilities!! It's basically up to me and what program I write.
Taking Matt's lead, I first created a program to take photos of popping balloons. Here's a rough outline of the process:
Start the process (by pressing a button)
Arduino turns room lights off (via a relay attached to an extension lead)
Camera shutter opens
Arduino waits for sound of balloon popping
I stick a pointy thing in a balloon
Arduino hears the sound, and fires off the external flash unit
Camera shutter closes
Room lights turn on
Paddy has a beer to celebrate a successful day's work
For an explaination of the above, see my next post (LINK COMING SOON). For some results, see my Flickr Arduino tag
I've also created a timelapse Arduino program, which allows me to repeatedly take photos a certain number of seconds apart - I created a simple video of a candle burning away, seen below
The parts
What I've used (essential stuff)
1x Arduino Pro (though most Arduinos are suitable)
1x Quad opto-isolator
1x 7d remote trigger (sabbotaged for its connector and cable) - A cheap knock-off one was ideal because it cost about £5 ($8)
Various pieces of stripboard
Various colours of wire - For wiring up the circuit, but I also used a lot to make the tails to go off to the external stuff like the flash and camera
Non-essential stuff (added for the cool factor)
Real time clock module - allowing for more accurate timelapses
Lots of male and female PCB pin headers - these make up the plugs for wires, or the slots to plug the Arduino in so it can be removed easily
4x LEDs (various colours) to show the status
2x PCB-mount buttons to set the functions
Transistors - Arduino can't source enough current to power LEDs itself (though I'm told it can sink it - can any confirm?)
Piezo transducer - to pick up loud sounds
Photodiode - to pick up the light from a laser pointer (laser tripwire!)
Various resistors - they're boring, but ya need 'em
Stuff I didn't add (but would love to)
LCD status screen
Ion cannon - not really essential for this project, but how cool would it be if you could take photos and then blow stuff up?
Some requirements I aimed for Functionality:
Control the camera focus and shutter (obviously) - the "how" is discussed below
Control an external flash gun - also discussed below
Two buttons to program the device - so I don't have to download a new program every time I want to change between "take picture when lights are bright" and "take picture when lights are dark" modes, for example
4 LEDs to display the status - in the end only 3 of mine worked, but it's still plenty
Expandability:
Inputs and outputs should be as generic as possible This wasn't always possible (i.e. for the camera connector) but where I could, I tried to make the inputs and outputs generic. For example, the relay to switch the sockets on and off is on a separate piece of stripboard, and just plugs into a simple digital out. This means I can design as many little plugins as I can think of and still use the same main board
Input buttons have ports to plug external buttons in (so I can carry a button around with me, instead of having to be right beside the controller)
Camera Control The camera (in this case a Canon EOS 7d) is controlled via the cable from a remote shutter release (about £5 on Amazon). These shutter releases (at least for Canon) are just simple switches. There are three wires in the cable - ground, focus and shutter. Connect focus to ground, the camera enters "focus" mode (like half-pressing your shutter button). Connect shutter to ground... well you get the idea.
In order to isolate my very expensive and love-of-my-life camera from my shoddy soldering, I used an opto-isolator. These little devices look like a standard IC chip, and basically consist of an LED on one side, and a photo-diode on the other. Apply a voltage to the input side, LED lights up, photo-diode allows a current through on the other side. You'll notice that there is no direct electrical connection between the input and output side - there's no need to worry about frying your camera if you short something out on the other side of the isolator, it provides about 7,500V of electrical isolation (or so the datasheet says).
Flash Control I needed to be able to control an external flash to really get that "motion-stopping" effect. I have two external flashguns - a YN-460 and YN-468. The trigger for both of these is a hotshoe, which means the flashgun provides a 6V voltage on the center pin, and when this is brough to ground (via another contact around the edge of the shoe), the flash will fire. This sounds like another job for an opto-isolator!
To make things easier for me (and because I don't have any hotshoe adapters) I added a small homemade sync port, which you can read about here
External lighting control This was such a good idea from Matt's video that I couldn't not do it!
Matt had a fancy extension lead with a digital input for turning it off and on. I don't have such crazy technology, so I had to make one myself.
What you see above is a small piece of stripboard, with relay which opens or closes based on a digital signal it receives from the Arduino. I've cut the live wire in a 4-way extension lead, and inserted the relay in the gap.
There's a little bit of circuitry so that the low current 5v output signal from the Arduino can power a 12v relay coil, but other than that it's very simple.
Because this board needs 12v, I usually power it directly, and I've added a socket so I can take power from this board and take it to my main board (which has the Arduino). The main board has an onboard regulator to give me 5v.
Inputs In this iteration there are 4 (3?) inputs - two buttons and a socket for a photodiode. I know I'd said I was trying to keep everything generic, but I didn't have the awesome idea of having additional bits of stripboard with extra circuitry at that stage.
One of the buttons also has a socket, so that I can plug an external button with a long wire on it. This gives me freedom to move around the scene, makeing life so much easier!
There's room for other inputs too, and another socket for an opto-isolator, but I haven't got round to doing the wiring yet.
Arduino Code This is coming in my next blog post. [INSERT LINK HERE]
As part of a larger project today I needed to sync my flashgun with an Arduino. Since I don't have any hotshoe connectors or anything like that, I decided to add a sync port to the flash itself.
Now I've read more than a few posts about people adding PC sync ports to their flashes (especially the YN-46x series), but since I don't own a single PC sync cable or any kind of connectors, I decided to go with a more breadboard/Arduino friendly option.
This hack doesn't impare the function of the flashgun in any way - it still functions as a normal flashgun, via the hotshoe or optical slave. It's just got an extra connector.
What you see above is the finished product - the addition is just a tiny 2-pin PCB header, like the ones you get on the Arduino itself. It's cheap, tiny and versatile, and it fits right into the base of the unit.
And that's the inside of the base. I've simply drilled a few 3mm holes in the side, cleaned up the hole with a knife, and slid the connector in.
The connector (seen above right) is 2.56mm pitch female PCB header (the big black strip). It comes in rows of 20 and needs to be cut to size. You can do this with a knife (carefully, and on a cutting mat!). It's pretty cheap on eBay, which is good, because I go through stacks of it!
Once I had the hole drilled and the connector slid in place, I soldered from the terminals on the new connector to the terminals on the existing connector. Finally, I covered the whole thing in Uhu glue to keep it secure (I forgot that the centre pin moves up and down - DON'T PUT GLUE ON THE CENTER PIN)
What I have now is a flashgun which can be hooked up to a breadboard for use with an Arduino. To trigger the flash, simply join the two leads together (either physically, with a physical switch, or with some kind of electronic switch)
Check out my next blog post (still to be written) to see what you can achieve with a Canon 7d, flashgun, Arduino, laser, and things which will break or pop or explode
First post in a loooooong time! I've since picked up a new hobby, so you're going to be seeing a lot of posts about photography!
It's a well known fact that using a longer focal length lens, and then stepping backwards so you can still fit your subject in frame, will "compress" the perspective in your image (i.e. make background objects appear a lot closer to your foreground).
What I haven't been able to find out until today was the effect of using different focal lengths, but keeping the same shooting position and cropping the image down to the same field of view. Seems that this has no (or very little) effect on perspective.
Any slight differences in the image above are probably due to the effect of lens distortion (barrelling, pin cushioning), or me forgetting to focus on the same point for each frame.
Images above taken with a Canon EOS 7d (1.6x FOVCF), using a 28mm f/2.8, 50mm f/1.8 and the awesome 70-200mm f/4.0 USM. All shots taken at f/4.0