Skip navigation

Raspberry Pi Projects

5 Posts authored by: cmelement14

Unfortunately I couldn't finish the project before Halloween because I moved recently and didn't bring the right tools with me. However, I will continue the build and blogs. Different from my last blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #4 - LED blink test, GUI Interface, today I will blog the build of audio amplifier.



Usually the sequence when I manually solder components is from low profile parts to high profile parts. To get a good sense of the soldering sequence, I temporarily placed all parts on the board without soldering.



Starting from low profile parts such as resistor, diode and ceramic capacitors. Pay attention to the diode's polarity.



Soldering the low profile parts and cut their extra leads.




Next, solder the switch.



Then solder the terminals and the amplifier IC. Pay attention the orientation of the IC.



Next, solder the volume control rotary switch.



Next solder three elec. capacitors. Pay attention to their polarity.



Finally, solder the LED. Pay attention to the LED polarity.



The back side of the completed board.


While I am waiting for answers about starting Python interpreter in privilege mode mentioned in my previous blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #3, I'd like to continue my journey. This is going to be a short blog about how I work on LED blink.


I wrote a small piece code which blinks LED(toggling red/green LEDs every second) until I hit the enter key. It works as expected.

import RPi.GPIO as GPIO
import time
import sys
import select

GPIO.setup(26, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)

state = True

def toggle_leds():
  global state
  if state:
  GPIO.output(26, True)
  GPIO.output(19, False)
  state = False
  GPIO.output(26, False)
  GPIO.output(19, True)
  state = True

# endless loop until enter key is stroked, green & red LEDs alternately on/off for 1 second
while True:
  while sys.stdin in[sys.stdin], [], [], 0)[0]:
  line = sys.stdin.readline()
  if line:


I used the same pins to drive LEDs as Charles Gantt used in his blog, but I didn't directly connect LEDs to those pins. The reason for it because each pin will consume more than 25mA if they are directly driven by pins. I am not very comfortable to pull such a big current from an I/O pin unless I see it's specified in its datasheet. Some kind of current limit is required. I don't have appropriate resistors to limit the current to 5 to 10mA per pin, however, the kit includes a few diodes, so I put two diodes in serie to limit the current to about 3mA. The LED isn't super bright, but definitely visible when it lights up.




Make sure you run Python in privilege sudo python Otherwise, you will have run-time problem.

Screen Shot 2015-10-25 at 11.49.19 AM.png

To check the GUI interface, I have to comment out all GPIO related statements. Then run python and GUI shows up like this:

Screen Shot 2015-10-25 at 12.39.36 PM.png

Stay tune for the next blog.

Following my previous blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #2, I will start with the Python GUI in this blog.


I got the LCD display work and I can SSH to my Pi 2 in the last two blogs, so I decided to try out Python GUI code in the SSH session. However, it didn't work. I thought I could create a widget on the LCD by typing Python code root=TK() in SSH session. Obviously, I was wrong.

pi@candydispenser1 ~ $ 
pi@candydispenser1 ~ $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
>>> root=Tk()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/lib-tk/", line 1712, in __init__ = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

It seems I have to use GUI desktop to get the widget shown up. However, I don't have a keyboard to connect my Pi, so I decided to use remote desktop. I used VNC. On the Pi 2, I installed TightVNC server and on my Mac computer, I installed VNC viewer. As described in, I used the following command to install VNC server on Pi 2.

sudo apt-get install tightvncserver

However, I didn't install xtightvncviewer because it isn't free. Instead, I installed VNC Viewer for Mac ( Now I am ready to use Tkinter for Python GUI programming.


Next, I will check out the control of Pi's GPIO pins. I typed the following statements in Python

import RPi.GPIO as GPIO
GPIO.setup(26, GPIO.OUT)

and it got runtime error and we need root access. Then I restarted Python interpreter with root privilege: sudo python and it worked. No runtime error anymore.

Screen Shot 2015-10-24 at 10.00.56 PM.png

Now, I am ready to follow Charles_Gantt's blog Trick or Trivia Halloween Candy Dispenser #002 - Building The Trivia Interface.

I created the file containing the whole program(Charles Gantt's code in Put it all together section in his blog#2 mentioned above), then ran the program as shown below. Unfortunately, it gave me errors no matter I ran Python interpreter in privilege mode or not. I posted my question in the comments of Charles Gantt's blog and hopefully he can answer my questions soon.

I will continue this series of blogs and stay tune for the next oneStep by Step Build Trick or Trivia Halloween Candy Dispenser #4 - LED blink test.

Following the previous blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #1, I will start from configuring WiFi. I used a couple of links to help me set up Wifi: and How-To: Add WiFi to the Raspberry Pi | Raspberry Pi HQ. Basically you need add a new network in /etc/wpa_supplicant/wpa_supplicant.conf file like this

    ssid="your router ssid"
    psk="wifi password"


After configuring Wifi, I rebooted Pi 2 and unplugged the Ethernet cable. I opened my router's website and found the new IP address(e.g., assigned to Pi's wifi interface. Then SSH to the Pi 2 using command

ssh pi@


And Pi 2 accepted the connection as expected

$ ssh pi@
pi@'s password: 
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Oct 18 13:37:31 2015 from lianhongs-air

NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'


and Pi 2 had no abnormal behavior

Pi 2 Wifi connection


After you have the network connection, you need make sure you have the latest Raspbian OS (you can download from installed. Otherwise, you need run the following update and upgrade commands:

$sudo apt-get update
$sudo apt-get upgrade -y

Now, it's the time to mount Pi 2 on the LCD panel. The picture below shows the parts to mount together.


If you haven't used LCD flexi cable before, please note that the latch on the connector is usually closed when it arrives. You need open it before you insert the flexi cable into the connector as shown below. The first pic shows close state while the second shows it in open state. To open it, just pull the latch from the two ends simultaneously.


Next insert the flexi cable to the connector on the LCD driver board through the bottom of the latch (shown below). After the cable is inserted, remember to close latches by pushing two ends back.


Then connector the other cable to the driver board as well. Also screw in the four standoffs as shown below.


Next, we connect driver board with the Pi 2. Please note that the flexi cable needs to insert into the connector through the top of the latch this time rather than through the bottom.



Next, connect the other end of the flexi cable to Pi 2's display port. Also connect two wires from the driver board to Pi 2's GPIO pin#2 & #6 as shown below.


Now time to power up the Pi & LCD. You cannot use the power adapter came with the kit as described in my previous blog (Step by Step Build Trick or Trivia Halloween Candy Dispenser #1). You have to use a 5V, 2A adapter. If everything goes well so far, you should be able to see Desktop on the LCD display as shown below. I assume you have completed the OS configuration using command sudo rasp-config and configured the automatic startup of desktop.



In summary, I got wifi and LCD work in this blog. I will continue my work and stay tune for the next blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #3.

This series of blogs will show how I build theTrick or Trivia Halloween Candy Dispenser project step by step following Charles_Gantt's series of blogs Trick or Trivia Halloween Candy Dispenser #001 - Project Introduction.


First of all, thank element14Dave & element14 for giving me this opportunity. I received my kit a few days ago. Below is what in the box.



I noticed that the kit includes a 4GB SD card instead of microSD card, so I have to find myself a 8GB micro SD card as shown in the right hand side of the picture below.


I recently moved to U.S. and I don't have HD TV in my apartment, so I have to figure out how to use Raspberry Pi without HD TV. After a quick google search, I found a forum post Headless setup: no keyboard, display or frustration which is the exact guide I am looking for. Before I mount my Pi on the back of 7" LCD panel, I'd like to have the OS (Raspbian based on Debian Wheezy) running first, so I followed the post mentioned previously.

After the OS is written to the microSD card, I plugged it into the slot and connected the power to Raspberry Pi 2 board with the wall adapter (shown below) included in the kit (black color), and also connected Ethernet cable to my router. The first thing I noticed is that the LED on the power adapter took about 3~5 seconds to light up after I plugged it into the wall outlet. Secondly, the two LEDs on the Pi were solid on. It's reasonable the power red LED is solid on, but the green LED should flash when it reads SD card. I waited about 10 minutes and still couldn't see Pi on my router's connected device list. I thought the power adapter might be the problem.

Bad power adapter

Fortunately, I have another 5V power adapter in white color (shown below). I changed power adapter and this time the green LED started flashing. However, after a few seconds, the green LED started doing some weird thing: stay in solid green for about 10 seconds and then off for a second and repeat this cycle forever until I unplugged the power. I suspect that the first power-up with the black adapter might corrupt the SD card, so I rewrite the OS, then powered up with the white power adapter. This time, everything works as expected. I can do SSH to the Pi.

Good power adapter

At this point, I am sure the black power adapter is NO good for Pi 2. I checked the label on the black power adapter, it says "O/P 5.25V 1A". No wonder it doesn't work - it cannot provide the max. current Pi 2 requires which is 2A. Update: after a quick google search, I am not sure the previous statement is correct.

I will continue my work and stay tune for the next blog(Step by Step Build Trick or Trivia Halloween Candy Dispenser #2).

Filter Blog

By date: By tag: