Tag Archives: PBPi

Raspberry Pi Controls the Cardboard Dog

This is a project for beginners using the Raspberry Pi (RBPi) single board computer. The RBPi is used to control a servo for turning the head of a cardboard dog away whenever a person is looking at it. This is to mimic a begging dog that seems ashamed of its begging nature.

This project requires the SBC RBPi, its power supply with the 5 V micro-USB cable, a USB keyboard and mouse, a display, and an HDMI cable. For storing the OS, an 8 GB micro SD card is also necessary. Another computer will be necessary to write the OS to the micro SD card and edit the files in it. The official PI camera will help to recognize the faces looking at the dog, and a micro servomotor is required to turning the head.

The RBPi will be controlling the servo through its GPIO pins. The servo has three wires that need to connect to the GPIO pins using female connectors. The camera has a ribbon cable, which goes into the port labeled camera on the RBPi. The HDMI cable goes into its port on the outside of the RBPi, and its other end goes to the HDMI-compatible TV or monitor.

Download and install the latest version of the Raspbian (with Pixel) from the official website of the RBPi. While installing the image on to the micro SD card, the process will destroy all data on the card, so be sure there is nothing of value before you begin.

Once the OS is installed on the micro SD card, insert it into the slot on the reverse side of the RBPi. If the power cord is now plugged into the RBPI socket and the power turned on, there should be some code running on the monitor screen, with the desktop showing up at the end. At this time, right click anywhere on the desktop and select “Create a New File.” Name the file Dog Turn.py, and select it to open with Python 2 IDLE.  Now open IDLE, and paste the code from here into it.

To make the code in the file to work, the RBPi will need additional Python modules to be installed. These are the libopencv-dev, python-opencv, python-dev, and you must use the sudo apt-get install command to download them.

The cardboard dog for this project uses four 9×6 inch cardboard rectangles, and two 6×6 inch squares, which form the main body. A hole at the top of the box allows the servo to go through. Another 5-inch cardboard cube forms the head, and attaches to the servo. Some cardboard legs make the dog look more realistic.

The entire electronic hardware can fit within the body of the dog. It may be necessary to use standoffs to hold the RBPi in place. The camera should look out from one of the eyeholes in the dog head. Fix it in place so that the cable has sufficient play when the servo moves the head. Simply running the python code should be enough to let the dog do its trick. To stop, turn off the power.

Let Raspberry Pi Automate those Snake Eyes

If you are looking for something to bring your cosplay masks, props, or other spooky sculptures to life for your robots, animatronics, or Halloween parties, you can use the snake eyes cowl as a pair of animated eyes. This is an accessory for operating two 128×128 pixel TFT LCD or OLED displays through a single board computer such as the Raspberry Pi (RBPi). It also has four analog sensor inputs.

The project started life as a project named Electronic Animated Eyes using the microcontroller Teensy 3.2. However, the author found the RBPi to be a better alternative as it offers some potential benefits, such as hardware-accelerated graphics, and includes antialiasing. With a faster CPU, dual SPI buses, and ample RAM, the RBPi offers faster frame rates. The RBPi does not require a preprocessing step to decode standard graphics formats such as SVG, PNG, and JPEG. The author has written the eye rendering code in a high-level language, Python, and that makes it easier to customize.

However, using RBPi for this project has some downsides as well. The RBPi usually takes a while to boot an operating system from an SD card. It also needs an explicit shutdown procedure. As the RBPi is large and uses more power, it is not very suitable for wearable applications. Moreover, the use of an SD card makes it less rugged.

The author recommends an RBPi model 2 or 3. Although the code runs fine on an RBPi Zero or another single-core RBPi board the performance will lag greatly. Make sure the RBPi board used for the project has a 40-oin GPIO header.

However, it is not necessary to connect both displays for the project, as a single eye can also produce a very creative effect. The author recommends OLED displays, as they have very wide viewing angle along with excellent contrast and color saturation. However, OLED is more expensive compared to TFT. TFTs are also acceptable as displays, although they may look somewhat washed out for this project. Users may need additional components if they plan on controlling the eyes with a joystick and buttons, and allowing them to react to light, rather than allowing them to run autonomously.

The author uses bonnet boards to wire up the breakout pins on each display board. The user must decide if the installation will be a temporary arrangement or a permanent one. Space for wiring may depend on the housing chosen for the installation, and these may influence the choice of connectors and wiring. Wiring has to be done carefully, following the instructions to avoid disappointment.

Preferably, solder a header at each end, and plug all the wires through. This is easier and less error-prone. Keeping the wiring short and tidy from the bonnet to display, ensures the display gets a clean signal, as electrical interference may lead to glitches in the animation.

Start the project by downloading the latest version of the Raspbian Lite operating system, and transfer it to an SD card of 2 Gb or larger size. Follow instructions here.

Audio HAT for the Raspberry Pi Zero

The Raspberry Pi Zero (RBPiZ) and its successor, the Raspberry Pi Zero Wireless (RBPiZW) are very small single board computers. The Pi Foundation wanted to keep their cost and size to the low side, so they did not include either a 3.5 mm audio jack or any other audio port. Although this may seem like a setback for many users, some of them were went ahead and figured out how to get audio out of the board with a little hacking.

Another reason for not including an audio port is the Broadcom chipset used for the RBPiZ and RBPiZW does not have a true analog output. Instead, there are two pulse width modulated (PWM) pins that spew out digital output at very high speeds. To get audio out of these two PWM output pins, one has to filter the signal to the audio frequency range. This allows one to fake an audio signal by adjusting the duty cycle of the PWM pins.

According to physicists, for simulating any analog frequency from a PWM signal, the PWM frequency should necessarily be at least ten times higher than the highest frequency to be replicated in the analog range. As the audio signals humans can hear range from 20 Hz to 20 KHz, the minimum PWM frequency should ideally be about 200 KHz. However, the PWM output from the two RBPis is 50 MHz, so we can comfortably filter out the audio part while suppressing the higher frequencies.

The schematic of the audio HAT for the RBPis shows that the two stereo audio channels, left and right, are designated as PWM0_OUT and PWM1_OUT. On the PWM0_OUT, R21 and R20 are two resistors acting as a voltage divider to bring down the 3.3 V signal to about 1.1 V peaks. The corresponding voltage divider on the PWM1_OUT is formed of R27 and R26. Therefore, the stereo audio line level can give an output of 1.1 V peak-to-peak.

The RC low-pass filter that prevents the high frequencies from passing through is made up of capacitors C20 and C26, working in conjunction with R21 and R27 respectively. With the values of the components used on the board, the cut-off frequency for this RC low-pass filter is 17865 Hz, which is very close to the upper limit of audio frequencies, or 20 KHz.

That still leaves the DC voltage part of the signal on the lines, and one must remove it to prevent damage to any speakers or headphones subsequently connected to them. This is done by capacitors C48 and C34, which allow only AC part of the signal to pass through, and block all DC voltages.

As the PWM pins are being taken to the outside of the board, one must also protect the RBPi from ElectroStatic Discharge (ESD), which can travel back and destroy the RBPi. This is taken care of by ESD protection diodes.

All the above sounds very good and simple, but on the RBPi, the actual PWM0 signal on pin #40, and the PWM1 signal on pin #45, are not available, as they have not been terminated into exposed pads. To circumvent this problem, the PWM0 signal has to be rerouted through software to GPIO pin #18, and the PWM1 signal to GPIO pin #19.

PiRyte Mini ATX PSU: Power Your Raspberry Pi

Powering the Single Board Computer, the Raspberry Pi (RBPi) is always simple using the wall-wart type power supply and the micro-USB cable. However, there is always the possibility of accidentally shutting off power to the RBPi without going through the proper shutdown sequence. As the RBPi relies on its micro SD card to store its Operating System and working files, a sudden loss of power is sure to corrupt them and render the RBPi incapable of rebooting in the next session.

Additionally, you may be powering other boards or HATs along with the RBPi. Having a wall-wart for each of your projects not only makes the arrangement look ugly, but it is also more prone to accidents. However, a PiRyte Mini ATX power supply unit can take care of powering your RBPi and other additional project boards. Apart from being an inexpensive desktop power supply, the ATX PSU sends out a controlled shutdown command, which the operating system of the RBPi understands, and it can close down without any damage to the disk files.

The inexpensive off the shelf ATX desktop power supply unit works with both 20 pin as well as 24 pin connectors, to enable operating systems to perform shutdowns and reboots under controlled conditions—this minimizes disk file corruption.

While offering a dedicated and regulated 5 VDC supply line for back powering the RBPi, the ATX PSU has screw terminals for +12 VDC and +5 VDC for powering external user projects. The tiny PSU also provides additional prototyping area and you can access +12 VDC, -12 VDC, +5 VDC, +3.3 VDC, and Ground for any circuit you may want to assemble there.

Most importantly, the PiRyte Mini ATX PSU conforms to the HAT footprint of the Raspberry Pi Foundation. What this means is you can simply plug it on the top of your RBPi, using the 40-pin GPIO stacking header to power your RBPi and, at the same time, use other HAT compliant boards as well. The ATX PSU comes as a DIY kit, so that costs remain low.

While operating, you can see the green LED on the ATX PSU pulsate slowly during power up and reboot. It continues to pulsate slowly until the boot up script ends. If you have shut down the RBPi from the operating system, the red LED will pulse rapidly for 10 seconds before the PSU shuts the power to the RBPi. A push button is available on the PSU for forcing a hard shutdown. The red LED dims for the entire time you keep the push button in depressed state, and turns off the power to the RBPi after 10 seconds.

Electronic projects often need multiple voltages in addition to the 5 VDC and the 3.3 VDC usually available for the RBPi. The PiRyte Mini ATX PSU supplies the type of power these project use. In addition, being a HAT compliant board, it is easy to build controller stacks using additional boards on top of the ATX PSU, as stacked configurations are physically and electrically more robust.