Friday, June 8, 2012

Heartbeat Rev. 2

Last Christmas I took part in the Fritzing Fritzmas Challenge and won a special follow up price being the PCB fabrication of my Heartbeat project. The fabricated boards looked really great as you can see below.

They have a unique white finish which makes them look far nicer than the more common colored PCBs.

After I soldered in the required parts for the project I was a bit startled. Unfortunately I made a mistake when I redid the design for fabrication back then. One of the transistors was wired in the wrong way. So instead of an alternating smooth LED pulse I only saw one LED lighting up constantly.

Then, some weeks ago I visited the Fritzing team at IxDS in Berlin and met André and Stefan to give them a copy of my book as a sign of appreciation because without Fritzing the book would not have those great project graphics. André remembered my Heartbeat board from the challenge and gave me the great advice to design a custom heart shaped PCB for a new version of the board. I didn't know about it before but Fritzing Fab can also fabricate PCBs in custom shapes. So if you ever wanted to design a very special shaped PCB, give it a try.

So now I decided to design the Heartbeat Rev. 2 board in a custom heart shape.

The PCB is in fabrication right now and I can't wait to see the result. Once I verify that the board works great, I will publish the design files and if any of you is interested I might even develop a kit for you to build the Heartbeat project yourself.

Saturday, June 2, 2012

Arduino passive IR trigger for Canon EOS

The other day I wanted to experiment with external triggers for my Canon EOS 550D camera. I stumpled upon a nice open source project called Arduino Camera Control from Oleg Mazurov, the creator of the USB Host Shield library for Arduino.

The Arduino Camera Control project depends on the USB Host Shield library and the USB Host Shield from Sparkfun. It supports Canon EOS and Powershot, as well as Nikon DSLRs and P&S cameras. My main objective was sending commands to the camera for capturing images. The library does much more than that but if you want more detailed information about the library, you should read the original article on Circuits@Home.

In this post I want to show you how to use a passive infrared module for triggering the camera to take a picture. First off, the list of things you'll need for this project.

Now let's connect all the parts like shown in the Fritzing schematic.

Before you can upload this project's sketch, you'll need to install some libraries into your Arduino IDE.
Now depending on the USB Host Shield you are using, there are two variants of libraries you can install. If you are using the Sparkfun USB Host Shield then you'll need to install the following two libraries into your Arduino libraries folder (..\arduino-0022\libraries\).

If you are using the USB Host Shield 2.0 from Circuits@Home, then please install the ported versions of the libraries found here.

Now after installing the libraries you can copy the following Arduino sketch in a new sketch window and upload it to the board.

 #include <inttypes.h>  
 #include <avr/pgmspace.h>  
 #include <Max3421e.h>  
 #include <Max3421e_constants.h>  
 #include <Max_LCD.h>  
 #include <Usb.h>  
 #include <ptp.h>  
 #include <canoneos.h>  
 #include <MemoryFree.h>  
 #define DEV_ADDR    1  
 // Canon EOS 400D  
 #define DATA_IN_EP   1  
 #define DATA_OUT_EP   2  
 #define INTERRUPT_EP  3  
 #define CONFIG_NUM   1  
 //PIR definitions and declarations  
 #define SLEEP_MODE_PIN 4  
 #define MOTION_DETECT_PIN 2  
 int val;  
 class CamStateHandlers : public PTPStateHandlers  
    bool stateConnected;  
    CamStateHandlers() : stateConnected(false) {};  
    virtual void OnDeviceDisconnectedState(PTP *ptp);  
    virtual void OnDeviceInitializedState(PTP *ptp);  
 } CamStates;  
 void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)  
   if (stateConnected)  
     stateConnected = false;  
     Notify(PSTR("Camera disconnected\r\n"));  
 void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)  
   if (!stateConnected)  
     stateConnected = true;  
   uint16_t rc = Eos.Capture();  
   if (rc != PTP_RC_OK)  
     Message(PSTR("Error: "), rc);  
 void setup()   
  Serial.begin( 115200 );  
  delay( 200 );  
  //PIR related  
  digitalWrite(SLEEP_MODE_PIN, HIGH);  
 void loop()   
  val = digitalRead(MOTION_DETECT_PIN);  
  //the ePIR sensor is active low so if motion is detected the output is low  
  if(val == LOW) {  

The sketch is essentially just an extended version of the EOSCapture example from the Arduino Camera Control library. What it does is to poll the PIR sensor for changes. The PIR sensor used here is active low, so if the PIR sensor is triggered the signal on the motion detect pin becomes low, meaning the voltage on the pin is dropping towards 0V. If that's the case, the Eos.Task() function will be called which sends a control signal to the camera instructing it to take a picture. That's all there is.

Now upload the sketch to the Arduino board and connect your Canon EOS camera to the USB Host Shield. Turn on the camera and try triggering a photo by waving your hand in front of the sensor. If the camera wasn't properly recognized by the USB Host Shield, try to select the M-mode on the camera or try to push the capture button on the camera. The board needs to establish a session with the camera before sending command transactions. If your board is still connected to your computer open up the Serial Monitor within the Arduino IDE to see if a session was opened.

If everything works out your final project should work like shown here.

Now you can finally take pictures of animals or people when you are not around. A good use case would probably be wild-life photography.