Skip navigation

Raspberry Pi Projects

2 Posts authored by: dougw Top Member

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

This blog is the first installment of a review of the Ultimate Raspberry Pi Bundle provided by element14. In this review I will focus mainly on the video application I proposed that prompted element14 to so generously provide the comprehensive bundle. This first picture just shows how comprehensive the bundle is.

PiBundle1.jpg

The Requirement

I play about 72 softball games every year (5 different leagues) and I take pictures of the action when I'm not on the field. These pictures get shown at banquets and sometimes on web sites. I try to take pictures of every player so nobody is left out when the slide shows are presented, but I cannot take pictures while I am batting or playing on the field, so I cannot take pictures of every play or every player.

 

The Solution Concept

This project involves building an automated video camera that can capture every player as they bat and the play at first base after a hit. To do this, the camera will be located over the fence half way between home plate and first base. The camera will be normally pointing at the batter's box and when the system detects a hit (by the sound of the bat hitting the ball) it will wait a short time for the batter to start running and then pan the camera to capture the play at first base. After 20 or 30 seconds the camera will return to capturing the action at home plate.

 

Primary Issues

Operating a servo motor and capturing video from the PiCam are nothing new for the Raspberry Pi and I don't expect too many issues getting these functions working. Mainly it will require learning how to use the existing resources available for Raspberry Pi. There are 2 significant challenges though:

  1. Unambiguously recognizing the sound of a bat hitting a ball and wirelessly sending a trigger signal to the camera module will require careful design and lots of experimentation because there are many different types of bat and a significant variety of hit sounds and of course there are many different sounds that need to be ignored as well.
  2. The camera system will need to be in a position where it could be hit by the ball so the system needs to be able to survive a massive impact. Protecting the electronics is plenty hard enough, but protecting the panning drive train may be even tougher. This is a difficult challenge, given that I do not have a large budget and I do not want to lug around a huge apparatus. The enclosure will not only need to protect from very high g accelerations, it will also need to prevent the electronics from getting wet when it rains. Solving these requirements may cause issues with heat build up as it will be hard to conduct heat away from the highly protected interior.

 

Given that the timeframe for publishing this review ends before the summer softball season starts, I will not be able to test the audio detection circuitry under all conditions, but I will try to get some representative sound triggers.

 

Design and Hardware Considerations

The system needs to be battery operated so I have procured a 5 volt, 3.2 AHr lithium battery. The Raspberry Pi really needs a display to show video, so I procured a 3.5 inch composite video LCD with a resolution of 640 x 480 for about $18. This display requires 9-15 volts to work, so I procured a DC-DC converter module to boost the battery voltage.

To provide the panning function I procured a high torque servo motor.

 

Progress and Status

By following the extensive on-line examples and literature, I have:

  • Installed and updated the Rasbian operating system
  • Tested the wireless keyboard/touchpad that came with the XBMC package with the RPi and a TV-android box - it worked great with both systems
  • Installed the Wi-Pi wireless module - it took a couple of attempts because I didn't remember that my wireless router uses WPA2 and PSK.
  • Installed the PiCam and took both stills and video - it is a pretty good little camera
  • Configured the composite output to work well with the 3.5 inch LCD. At 640 x 480 the text is just legible but I set it up for 440 x 300 to make it easier to read.
  • Assembled the 16x2 LCD Pi Plate Kit - I may not end up using this module on this project, but wanted to see if there were any issues with it. If I do use it, it will need to be mechanically robust, so I wanted to solder the LCD connector and mount the LCD on standoffs. The standoffs were not supplied, but I had some 3/16 inch standoffs that worked well. I used nylon washers on the underside of the Pi Plate for better insulation against the screw heads shorting traces that are underneath the screw heads. I tightened the standoffs with the connector loosely in place and soldered the connector after the LCD was locked in position to minimize stress on the connector solder joints.

 

This second picture shows the Pi Plate LCD assembled and mounted on the Raspberry Pi. It also shows the Wi-Pi module and the PiCam (in an anti-static dust-cover). Raspbian is running and displaying on the small monitor I purchased as a mobile display. The photo is not edited other than resizing, so you can see the small monitor has pretty good colours and at the chosen resolution is very readable. In the SoftballCam this monitor will be a video display (large by videocam standards) as well as an operating system display.

CompositeMonitor.jpg


Issues Encountered

  • I tried several different power supplies before I found one that would run the RPi plus peripherals plugged into the RPi USB ports. They all seem to run the CPU card okay, but wouldn't supply enough consistent power to run a mouse. I think it is an issue with instantaneous current - the average current drawn by the RPi is not large, but there seem to be peaks that can momentarily cause some power supplies to sag, particularly if the USB cable has significant impedance.
  • The display I bought was intended for vehicles and it only turns on when a valid composite signal is present. This is not a problem now that I know about it, but initially it didn't seem to be working, because the RPi wasn't generating composite video before the operating system was properly installed.

 

Next Steps

I am still waiting for the microphone I ordered to arrive and the associated wireless link.

I am designing the microphone signal processing circuit.

I have some of the packaging and mechanical configuration figured out, but still struggling to keep costs down.

I want to try making the servo program - it can be a completely separate task from the video capture.

 

Summary

So far, the Raspberry Pi eco system is proving to be a bit more complicated than I had expected and often the documentation is not robust enough to avoid a lot of auxiliary web researching and trial and error. However there is a lot of information available on the net and it is satisfying to continue up the learning curve towards a successful project.

Filter Blog

By date: By tag: