This blog is the second installment of a review of the Ultimate Raspberry Pi Bundle provided by element14. I have been waiting for parts and struggling a bit with getting everything working, but finally all electronics are kluged together and functional. Also all software for a working project is written and working.

 

System Diagram

  This illustration shows the components of the SofballCam and how they are connected. The two main functions of the SoftballCam video recording and camera panning are divided between the Raspberry Pi and the ChipKit Pi with the Raspberry Pi performing the video recording functions and the ChipKit Pi performing the camera panning functions. The ChipKit Pi is stacked on the Raspberry Pi which is used to develop the software for the ChipKit Pi. The microphone is connected to a digital input on the ChipKit Pi to trigger panning cycles on the servo motor. The servo motor is also connected to a PWM output on the ChipKit Pi. This arrangement allows the ChipKit Pi to operate completely independently of the Raspberry Pi. The wireless microphone link has not arrived, but the microphone circuitry works fine connected directly to the ChipKit Pi.

SystemDiagram.jpg

Packaging Diagram

  My plan is to mount everything on a fibreglass chassis and wrap it with foam, then place the bundle inside a strong container and wrap the container in 2 more layers of foam sandwiching a stiff load distributing layer. The servo motor would operate a rotating pad which would allow the entire self-contained package to be knocked off the stand in the event of a direct impact. A bungee chord would prevent the package from flying too far. I'm still pessimistic about the robustness and heat dissipation of such an arrangement, but it is about the best compromise solution given the constraints. The strong containers investigated so far do not seem adequate to the task, partly because the required size is larger than anticipated, due to all the connectors, so I am still looking.

PackagingDiagram.jpg

Development

Installation of the ChipKit Pi on the Raspberry Pi and installation of the MPIDE development system on an SD card went fairly smoothly, except I ran into further issues with USB power. Currently I have one power supply for the Raspberry Pi and ChipKit Pi and including the WiPi. I have a second power supply running a USB hub with keyboard, mouse, wireless keyboard dongle and USB memory stick. I have a third power supply running the small display. I have a fourth power supply running the microphone and servo motor. All of these except the display (which needs an additional DC-DC converter) can be run directly from a 5 V battery pack with appropriate wiring harness.

The symptoms of power inadequacy were the keyboards would appear to have a stuck key - just repeating the last pressed key forever - so if this is happening to you, try a more robust power supply arrangement.

The ChipKit Pi only needs 2 signal wires connected - pin 9 for the servo output and pin 8 for the digital panning trigger. Of course there is also a ground connection. These two signal pins needed both jumper 12 and jumper 13 to be moved to the positions closest to the LEDs in order to connect the CPU to the connector pins as shown here.

ChipKitPiJumpers.jpg

I could not get the example servo driver code to run so I wrote my own servo driver.

The ChipKit Pi circuit board does not have any mounting holes on it and the connector between it and the Raspberry Pi would not survive an impact with a softball, so none of the components are well suited to this application from an impact survival point of view.

The ChipKit Pi is a powerful little controller, but it still needs better documentation and more examples - hopefully this will occur as more people start to use it.

 

ChipKit Pi Software

  Here is the software for the ChipKit Pi in case anyone wants to see how the triggered panning was done....

// Triggered SERVO Pan 2

// by Doug Wong   2014

// all rights reserved

 

const int triggerPin = 8;     // the number of the trigger pin

const int servoPin = 9;       // servo output pin number

const int maxp = 1000;        // maximum servo high period

const int minp = 500;         // minimum servo high period

const int dwellhome = 100;    // servo periods to dwell before returning

const int dwellfirst = 400;   // servo periods to dwell before returning

const int stepsize = 4;       // servo period step size

int period = 500;             // variable to store the servo position (half period in microseconds)

int triggerState = 0;         // trigger status variable

int dwell;                    // servo periods to dwell before returning

 

void setup()

{

  pinMode(servoPin,OUTPUT);    // initialize the servo pin as an output

  pinMode(PIN_LED1, OUTPUT);   // initialize the digital LED1 pin as an output

  pinMode(triggerPin, INPUT);  // initialize the trigger pin as an input

}

 

void loop()

{

  triggerState = digitalRead(triggerPin); // read the state of the trigger pin

  if (triggerState == LOW)                // if the state of trigger is low, perform a pan cycle

  {

    dwell = dwellhome;                    // set dwell time at home plate

      while(dwell>0)

      {

        dwell--;                          //decrement dwell

        digitalWrite(servoPin, HIGH);     // set the servo output high

        delayMicroseconds(period);        // waits half of servo high period

        delayMicroseconds(period);        // waits half of servo high period

        digitalWrite(servoPin, LOW);      // set the servo output low

        digitalWrite(PIN_LED1, HIGH);     // set the LED off

        delay(10);                        // wait for servo low period

        digitalWrite(PIN_LED1, LOW);      // set the LED on

        delay(10);                        // wait for servo low period

      }

    digitalWrite(PIN_LED1, LOW);          // set the LED on

      while(period<maxp)

      {

        period = period + stepsize;       // increase servo angle

        digitalWrite(servoPin, HIGH);     // set the servo output high

        delayMicroseconds(period);        // waits half of servo high period

        delayMicroseconds(period);        // waits half of servo high period

        digitalWrite(servoPin, LOW);      // set the servo output low

        delay(20);                        // wait for servo low period

      }

      dwell = dwellhome;                  // set dwell time at first base

      while(dwell>0)

      {

        dwell--;                          //decrement dwell

        digitalWrite(servoPin, HIGH);     // set the servo output high

        delayMicroseconds(period);        // waits half of servo high period

        delayMicroseconds(period);        // waits half of servo high period

        digitalWrite(servoPin, LOW);      // set the servo output low

        digitalWrite(PIN_LED1, HIGH);     // set the LED off

        delay(10);                        // wait for servo low period

        digitalWrite(PIN_LED1, LOW);      // set the LED on

        delay(10);                        // wait for servo low period

      }

      while(period>minp)

      {

        period = period - stepsize;       // decrease servo angle

        digitalWrite(servoPin, HIGH);     // set the servo output high

        delayMicroseconds(period);        // waits half of servo high period

        delayMicroseconds(period);        // waits half of servo high period

        digitalWrite(servoPin, LOW);      // set the servo output low

        delay(20);                        // wait for servo low period

      }

    digitalWrite(PIN_LED1, HIGH);         // set the LED off

  }

  digitalWrite(servoPin, HIGH);           // set the servo output high

  delayMicroseconds(period);              // waits half of servo high period

  delayMicroseconds(period);              // waits half of servo high period

  digitalWrite(servoPin, LOW);            // set the servo output low

  delay(20);                              // wait for servo low period

}


Video Demo

In this demo, the Rasperry Pi is displaying the PiCam on the small monitor and the ChipKit Pi is running the servo panning cycle in response to microphone events. The software waits a short time after a microphone event (bat hitting the ball) to allow the batter to start running, before panning to first base. The software keeps the camera on first base for a short time before returning to home plate. The first base dwell time is short in the video, just to make the video shorter. I can't take this to a ball diamond yet because we still have a couple of feet of snow on the ground.

The servo pulses are being displayed on the oscilloscope - which is just a troubleshooting aide and not part of the end project.

The video capture is done from a simple command line such as this:

raspivid -o video.h264 -t 60000

  Which would capture 60 seconds of video.




Summary

The Raspberry Pi and ChipKit Pi are powerful and complex systems which have simplified user interfaces that allow some impressive capabilities to be programmed without much investment in time. For example the video recording function is built-in. However, when trying to do something that is not built-in, it often becomes necessary to dive into the underlying complexity and the documentation can be pretty weak which can make the task very difficult and searching for answers may take significant time. For example, I wanted to make use of a 5 volt tolerant input for the microphone trigger signal, but could not figure out how to connect to these pins nor how to access them from the MPIDE programming environment. I ended up using a hardware voltage divider after extensive but unsuccessful searching for appropriate documentation.

I had fun implementing the SoftballCam functionality and gained a much better understanding of what is involved in doing projects with the Raspberry Pi.

 

Other posts about the SoftballCam:

  http://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2014/02/20/the-ultimate-raspberry-pi-bundle--softballcam--1