Make some noise

Adding a push-button and connecting it up the a GPIO port is as simple as writing a tiny pyhon script to initialize the IO port for input and utilizing a built-in pull-Up button. The Raspberry PI button is then capable to act as a Doorbell button.

After I connected the loudspeaker to the USB soundcard and soldered the USB connection from the Raspberry PI to the sound card I was then able to use alsaconfig to select it and then use:

speaker-test -c2 -twav

to actually hear some audio through the soundcard.

External USB sound card
External USB sound card

Now the next step was to connect GPIO port 17 to GND and use the built in bull-down-resistors to detect a button-press event.

Here is the push_button.py – python script which I use.

#!/usr/bin/python2.7

import time
import RPi.GPIO as GPIO
import subprocess

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def my_callback(channel):
    subprocess.call ( "/root/bin/ding_dong.sh" )

# add falling edge detection on a channel, ignoring further edges for 400ms for switch bounce handling
GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=400)

while True:
    # Loop once a day
    time.sleep(24*60*60)

GPIO.cleanup()

This script is straightforward and is simply waiting for a button press on GPIO pin 17 ( to GND ). The final loop is a forever loop with a one-day delay which will help keep the responsiveness of the Raspberry PI button at a good level. If during this time a button press was detected, then the ding_don.sh – script, which in turn plays a sound on the speaker.

I plugged it into /root/bin/push_button.py and made sure it is executable

sudo mkdir /root/bin
sudo vi /root/bin/push_button.py
sudo chmod +x /root/bin/push_button.py

Below is the pin-out of the Raspberry PI Zero W.

GPIO Ports
Raspberry PI Zero W
GPIO ports

In this case I connected GPIO17 ( orange wire ) and GND ( blue wire ) ( PIN 11, and PIN 14 ) to the doorbell button.

Video Doorbell
Video Doorbell wired up

Instead of packing all the functionality into one python script I decided to have python call a simple bash – script to do the actual work. Here is the ding_dong.sh script, which is called by the python script and also resides in /root/bin/

#!/bin/bash

mpg=`pidof mpg123`
if [ "x${mpg}" == "x" ];
then
  mpg123 /root/SoundHelix-Song-14.mp3 &
else
  killall -9 mpg123
fi
echo "Ding Dong"

sudo vi /root/bin/ding_dong.sh
sudo chmod +x /root/bin/ding_dong.sh

As the last step I wanted to have this script run all the time and to make sure it is started at startup of the PI :

[Unit]
Description=Push Button Service

[Service]
ExecStart=/root/bin/push_button.py
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=ipush_button.service
sudo vi /lib/systemd/system/push_button.service
sudo systemctl enable push_button

The Raspberry PI button is now all set to act as the Doorbell button for my Video-Doorbell project.

Words

Certain words in leadership indicate certain treats in a person, here are some to look for.

So I was watching a couple of youtube videos from James Randi and I was starting to wonder about Believe Systems and language.

https://www.youtube.com/watch?v=2MFAvH8m8aI

If there is one word I despise, it has to be the word “deserve“. Anytime you hear this word you should immediately raise an alarm bell. The other person is either trying to sell you an over priced item or is about to lie to you.

“You deserve a bigger kitchen”, “You deserve this vacation”, “You deserve that fast car” … “You deserve it”.
Well, really ? Interestingly why does my employer not think so ? Or if you believe I deserve it why don’t you go an talk with my boss ?

That leads me right into the next word I don’t particular like : “believe“. Now this is an interesting one.

When Einstein’s thought experiments overturned centuries of accepted physics, he changed the believe system of scientists single handedly ( or mindedly ). So from this analogy I conclude that a believe is a mental representation of reality based on insufficient information to support knowledge.

If you know something I can go and ask for proof, but if you believe something to be true I am stopped right there before the entrance of reason.

So here is the call to every one to stand up and know what you’re saying more often.

In general I believe that mankind would not be able to survive without a believe system. As an example: “There is movement in the bushes. I believe there is danger close, so I better run”. This believe may have saved some unwitting predecessors of yours and thus made it possible for you to read these lines today.

So the believe to know something based on insufficient information in itself is a useful tool. Whats wrong then ?

We live in a highly opinionated world and there are opinions flying around in every sentence spoken. This is directly reflected in our language and in our believe system and it is, after all what makes us individuals, and in greater terms human.

The trouble is that some believe without asking the tough questions they ought to.

Once a certain believe has been planted in our minds it is hard to regain objectivity and look at things the way they actually are. So look at it as a magic trick … or how I would see it as mind control, and look out for these two words deserve, and believe.

An opinion then is created and expressed directly from our believe system(s) and thus only as valid as our mental capability to reflect reality.

Ps. At least when expressing an opinion the other side will usually let you know : “in my opinion …” and what follows then is usually less than accurate otherwise the sentence would contain the word know.

Inspiring videos

Inspiring Videos

Motivational road
Motivational Road

YouTube can quite be a distraction from the daily chores you have to get done. However if you are down and you are looking for some inspiring videos it is good to spend a few minutes finding motivation.

I love the following motivational video from Mateus Z. :
Dream.

Now the other video I found very good is the following one.

 

Where Good Ideas Come From

I have ideas all the time. I am also amazed as to why I don’t have seen certain things yet.

Sometimes I just feel like doing it myself. Why ? Becaus I KNOW I can do it better. I KNOW what I know to be true and I KNOW if I will just invest the time and energy into it I will have made a difference.

— A journey of a thousand miles begins with a single step. —

Sometimes finding the required motivation is a mouse click away. Other Times it requires some soul searching. Whichever way you go it is important to keep your goals and dreams aligned. Finding motivation will then be a breeze.

Setting and achieving your personal and professional goals is as important as breathing and sleeping. Without a clear goal you will be living like a leaf falling from a tree, flowing wherever the wind carries you.

A goal has to be time bound.

As Milton H. Erickson said:
.

One of the lessons I have learned over the years is that you can set goals and you will miss goals. What is important is to be relentless and never give up. Don’t let the naysayers convince you that you should stop trying.

Wireless bridge with ASUS RT-N56U

I have had the ASUS RT-N56U for the past 4 years instyalled in my home and it is serving me very well. This is a dual-band wifi router which has been on the market since 2011. It offers a lot of things which go beyond the basic wi-fi functionality.

Wifi Router ASUS RT-N56U
Asus Dual-Band Wireless-N600 Gigabit Router (RT-N56U)

Original Firmware
Original Firmware for the RT-N56U

The configuration panel of the original bios on this device looks just gorgeous. The functionality which you have built into this device is amazing and Asus is still popping out some firmware and security updates once in a while.

last week I saw that some one in our neighbourhood gava away a free wi-fi router and as it turned out it was the same exact model. So I went ahead and recovered it to install as a wi-fi extender in our house.

Now configuring the second router to act as a wireless bridge was a snap. After I provided all the login information setup the second band to handle exclusively the relay traffic and … nothing.

Wireless Bridge setup
Wireless Bridge setup

I spent a few hour tinkering with the settings and ended up empty. I tried different channels, open wifi ( not recommended ) and more. My final thought on this was “At least I did not spend any money on it..

However that was not the end of it. I searched for alternate firmwares for this router and found the Padavan & N56U Firmware. So I went ahead and installed it onto the router. the worst that could happen was that I bricked a device which I had no other use for anyways.

Afterwards configuring the access point information was straight forward with one major difference. It actually worked without any issues right off the bat. So now thatnks to the two ASUS RT-N56U – units I have wifi connectivity throughout my house and into our backyard.

Padavan Firmware interface
Padavan Firmware interface

 

Does communication improve technology ?

Does communication improve technology or does technology improve communication ?

Communication
Communication

That’s a question I have been tossing in my mind for some time now. I came to the conclusion now that it is bi-directional, and that better communication will foster better technology which in turn will be the breeding ground for better communication.

If communication is the key to advances in technology, or at least a major component of it, how come we are still struggling with voip and video phones ? While this helps somewhat, the environment is not suited for most use case of ‘personal communication’

Think about it this way, why do business people travel that much ? Do they like to fly, or leave their family for weeks at a time ? No, the reason is that it is extremely difficult to communicate  complex matters remotely.

Back in 1995 / 1996 when I was briefly working at the ZGDV ( Frauenhofer Institute ) in Mannheim I saw virtual cubed environments which tried to achieve virtual immersion. The goal back then seemed so easy, and the outcome so close. What happened ? Where are the Holo-decks of the 21’th century ?

With the increase of computing power and the availability of technology and the Internet ( the Evernet really ) I am still stuck at looking at a 2D screen to interact with the computer, and with other people. Even though I now enjoy a 30 inch screen with an almost optimal resolution of 2560×1600.

We need better technology thus we need better communication. To get better communication I think we need better tools.

One of the main sticking point in recent computer science is the advance of multi core, multi cpu computers. But beyond that we now have heterogeneous computing environments. Ever wondered how much computing power is in your phone ? Why not leverage the CPU in your tablet together with the horsepower of your Laptop ?

The reason is that the available tools lack. Those tools have been designed decades ago and have not evolved at the speed required. If the programming language would adapt as fast as the web technology we would by now now look at Laptops with 2048 cores and more.

There are a multitude of attempts to invent better tools but their adoption rate is negligible. One prime example of a failed ‘better tool’ is Java. I liken it to the move from CVS to SVN. It does maintain most of the existing features and adds some bits and pieces to it but if you step back and take a look at it from a distance Java and C++ are really not that different. So why bother ?

Others attempt to modify existing languages. For me that is a much better way to go. After all, if it is done properly you can retain the billions of lines of code already written and you add functionality. Or you give a simple means of conversion.

I firmly believe we should look into adding communication into the core language itself. Design the runtime environment such that it can handle high latency or unreliable links and nodes. Maybe add some grains of auto adjustments ( Aka self healing or Learning ) to it and really re-think the paradigm of software developing, away from functional or OO to a distributed or universal ( I don’t like to use the buzz-word cloud ) based paradigm.

I am an optimist, and I see that we will eventually get there. I will try to play my part in it and while I may never get up to the ranks of true visionaries like Vint Cerf or Bjarn Stroustrup, I will never be content with the status-quo and always do what every geek should be doing.

Follow the pursuit of innovation.

Spam-Me-Not

Whow, I just started this blog and not even e week into it I saw my first wordpress spam.

On my article DyGraphs Pie Chart Plotter I received the following comment.

To mitigate errors in throw ratio calculations, projectors with zoom
capabilities and lens shift are highly recommended.
You will find the projector machines in any lead store.
You should also consider something which will support DVDs as well as Blu-rays since
few of you will have gotten around to rebuilding your film collection on Blu-ray.

This seems to be a wordpress spam but what does it mean ?I googled for the first sentence and I found 8 occurrences of the exact same sentence, followed by other sentences, which taken together made no sense.

For example the following nuget from a chinese forum:

An Analysis Of Foot Streaming Advice
Learn about Some of the Best Home Theater Seating Manufacturers
The late NFL Playoffs 2015 live stream and TV game time on Saturday will feature the first in the NFC Divisional matchups because Panthers vs. Seahawks is featured. Cam Newton attempt to steer his team to a major upset over Russell Wilson and also the defending Super Bowl champions. The winner moves on to experience either Dallas or Green Bay in the NFC Championship round. Which team are able to advance past this matchup within the latest live streaming and televised NFL playoff game?
Netflix was originally conceived like a DVD delivery and rental service that permitted you to order DVDs web you can keep them shipped to your property. You could easily mail them back, get more from your specified Queus list within a couple days, and make them being released and in a cycle. Then Netflix developed their Instant Watch feature, that has been a lot more movies and television shows that might be watched \"On Demand\" through their site as streaming video. Not only was the Netflix Instant Watch great for watching films from the computer, it could even be integrated on to your TV with gaming consoles and Apple TV and in many cases in your iPhone while using Netflix iPhone app. The Netflix service doesn't only have to watched through the website in any way and now you can even integrate it while using Windows Media Center as Microsoft has included it like a built in option.
BYU features Tanner Magnum, who spent his last two years with a mission in Chile. The 22-year-old stepped looking for injured starter Taysom Hill, when the quarterback suffered a season-ending foot injury. Magnum was the hero in the game, tossing a last-second touchdown to help you give his team the 33-28 miracle conquer Nebraska. Magnum delivered more magic last weekend against No. 20 Boise State, throwing a 'go-ahead scoring' pass to Mitchell Juergens with just 45 seconds to go. That pushed BY on the 35-24 victory over then-ranked Boise State.

The critical aspect in a ceiling mount video projector is positioning. Different projector designs include unique throw ratios, which is the relationship between projector distance and the width with the screen. Throw ratios are usually 1.8 or 2.1 to, which suggests 1.8 feet of throw distance for each foot of screen width. To mitigate errors in throw ratio calculations, projectors with zoom capabilities and lens shift are highly recommended.
1. Enroll yourself in an affiliate program determined by what you need. Affiliate marketers are among the high earners in terms of work from home jobs. You can earn approximately $5,000 to $10,000 or maybe more every month; you may want some serious working out for this. There's a lot of techinicality using this type of kind of position, but a great deal of risk of online marketing. There are training programs that you can enroll to online, with this particular you are able to enrich your understanding on your own niche and creating your blog post or site. Thus type of business is very technical, you have to learn SEO and increase your online skills to produce your website competitive; there isnrrrt a real have to devote to it. Before enrolling yourself into just as one online marketer, you must research about the companies; ask around for it's reputation if they are promptly whe it comes to paying. Analyze if your offers are reasonable or if it's too good really was.
Should you adored this article along with you would like to acquire guidance with regards to voir le match kindly go to our site

I believe the reason these comments are sent is so that the original poster creates a higher visibility to the search engines. I am not 100% certain but I may do some more research on this at some later point in time.

Custom Video Doorbell box

When I first <a href=”https://www.softwaresamurai.org/2017/10/10/raspberry-pi-video-doorbell/”>looked into adding a Video Doorbell</a> I was surprised by the lack of available choices ( thus far )

Our doorbell had to be slender which meant less than 2″ ( 50mm ) and could be 4.8″ tall ( 123mm ). None of the ones I saw met this criteria. I also required a little 5mm shim to handle the uneven surface.

Anyways long story short I decided to do a custom build of the chassis for the Doorbell.

Rough drawing of the chassis
Rough drawing of the chassis

Creating the Custom Video Doorbell:

To convert this image into a physical reality I had to use some tools and then see if all eventually fits in. To screw the top and the bottom together will be the very last step before painting, after I have places, screwed, soldered and glued all the pieces into their final place. This will allow me to adjust the height if needs be.

From the pictures below you can see that it is a tight fit with all the pieces in place. Unfortunately I can’t use the USB plugs. If I would connect them, then the PI Zero would no longer fit inside the box.

Since the PI Zero exposes the usb contacts on the bottom and I have to remove the USB plug from the soundcard anyways.

  • All pieces put tgether
    All pieces put tgether
    This is the assembled Raspberry PI with camera, the New doorbell button, the sound card, loudspeaker, as well as the original wireless doorbell button.
  • Side View
    Side View
    The assembled pieces from the side
  • top and bottom part of the doorbell
    top and bottom part of the doorbell
    Please note that the tape is just a temporary holder until I create all required holes, brakets etc.
  • The sound card fits in sidewards
    The sound card fits in sidewards
    After removing the USB plug and soldering on the wires, The sound card does now fit sidewards into the chassis.
  • Wireless Doorbell button
    Wireless Doorbell button
    Before cutting out the back to place the current wireless Doorbell Button into its socket.
  • Wireless Button integrated into back of Doorbell
    Wireless Button integrated into back of Doorbell
    All fits snug into their place.

 

Power

As power source we do have 24V AC coming out of the doorframe, which require a small power converter. Using the standard 7805 regulator brings this down to a few small pieces. Alternatively I can find the source fo the wiring and feed it directly with 5V DC to the door.

7805 voltage regulator
7805 voltage regulator schematic

Things are starting to come together. I still have to connect the loudspeaker, the microphone, and make sure that the original doorbell button gets some protection before connecting it up and closing the case.

Rpi WebRTC Streamer to Android WebRTC streaming

In this article I will setup Android WebRTC streaming to RPI-WebRTC-Streamer running on my Raspberry PI Zero W, to talk to each other.

Here is the architecture of RPI-WebRTC-Streamer.

Now why do we use WebRTC instead of directly streaming audio/video through a socket from the Raspberry PI to the Android device ?

It is helpful to understand how WebRTC works under the hood and how a connection is established.

The magic in WebRTC is the probing of the connection to allow two clients to talk P2P ( Peer-to-Peer ), even if they are behind a firewall or using NAT. There are plenty of online resources devoted to this complex topic ( E.g. https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/ )

The basic steps in establishing a WebRTC connection are:

  • Step 1: Signaling: both peers connect to a signaling server (using websockets over 80/443, comet, SIP,etc..) and exchange information (about their media capabilities, public IP:port pairs when they become available, etc.)
  • Step 2: Discovery: Devices connected to LAN or mobile networks are not aware of their public IP (and port) where they can be reached at so they use STUN servers located on the public Internet to discover their ip:port pair (ICE candidates). In the process they punch a hole through the NAT/router which is used in step3:
  • Step 3: P2P connection: once the ICE candidates are exchanged through the initial signaling channel each peer is aware of each other’s ip:port (and holes have been punched in NATs/routers) so a peer to peer UDP connection can be established.
  • Step 4: If a P2P connection can’t be established ( maybe through firewall rules or the usage of Symmetric NAT ) then TURN servers can be used, which will relay the data between the peers. Please note that this will require the TURN server to receive and send all video and audio and is the last resort in WebRTC.

Under normal circumstances you would establish the connection between two web-browser. However in this case I need to establish Android WebRTC streaming to the Raspberry PI Zero W. Fortunately we have the required tools and libraries available on both platforms and can take full advantage of this technology stack. This allows us to basically build a video conference similar to skype between the Raspberry PI and Android. As an aside, iOS can also handle WebRTC, which may be a project for later.

Android WebRTC Streaming:

  1. Lets first make sure you have the RPI WebRTC Streamer setup, as explained in my previous post.
  2. Then you have to install ADB onto your computer to be able to transfer the App to your Android phone.
  3. Connect your Android phone to your computer and make sure you have the developer option enabled
  4. Next get the source code for RPI WebRTC Streamer from github and install it onto your phone, like so.
    bash> git clone https://github.com/kclyu/rpi-webrtc-streamer.git
    bash> cd rpi-webrtc-streamer/misc
    bash> adb install AppRTCMobile.apk
    
  5. Next open the app on your Android phone
  6. Change settings of the Video encoder to H264 High
  7. Change the resolution to VGA(640 x 480)
  8. And then simply enter the IP address of your raspberry PI as the room number
Android WebRTC streaming in action
Android WebRTC streaming in action

Finally, here is the article from mpromonet if you ever feel like compiling rpi-webrtc-streamer https://www.raspberrypi.org/forums/viewtopic.php?t=186271.
You can even use docker containers to make things easier: https://hub.docker.com/r/mpromonet/webrtc-streamer/

As an aside, I found multiple Android app templates to use WebRTC

uv4l WebRTC vs rpi-webrtc-streamer

I have spent the past two days working with the uv4l driver to get WebRTC working. I eventually got everything to work with three major issues

  1. I could not get the transmitted quality to anything close to what I needed
  2. I could not get rid of the the watermark which was put over the video
  3. The complete CPU utilization for 640×480 was above 90% and caused issues.

Another slightly annoying issue was that I had to re-install Jessie after I found out that uv4l is currently not available for Raspbian stretch lite. I could only find the full version for Jessie, which requires at least a 8GB microSD card. And off I went to replace my 4GB microSD card.

On the positive side I installed rpi-webrtc-streamer from github and was able to look at the results in realtime right away.

Unlike uv4l, which is based off OpenWebRTC from Ericson, rpi-webrtc-streamer is based off the Native Code from www.WebRTC.org which seems to be a bit more responsive than uv4l.

Here are the steps I had to do to get things to work.

bash>  # First create a home for the code
bash>  mkdir utils && cd utils
bash>  git clone https://github.com/kclyu/rpi-webrtc-streamer.git

You can find the Android App under rpi-webrtc-streamer/misc/AppRTCMobile.apk
But first lets avoid the work and go straight to installing the software.

Go to https://github.com/kclyu/rpi-webrtc-streamer-deb and download the appropriate deb-package.

bash>  dpkg -i rws_xxx_armhf.deb
bash>  sudo systemctl start rws

Then simply point your browser at http://<IP Address>:8889/native-peerconnection/

Raspberry PI camera
Raspberry PI camera

I will be going through the setup and usage of the Android App which is part of rpi-webrtc-sstreamer in one of my next blog entries.

Cheap $7,- external usb sound card

I bought the following external usb sound card from Amazon for $7,- to integrate into my Video Doorbell project.

 

External USB sound card
External USB sound card

So why did I chose to go this route. Simple, I was looking at some audio pHATs  for the Raspberry PI and found that they will cost about $4,- a pop, then of course you also need a microphone, and bang you are at around $9,- to $10,-. So paying $7,- for a audio I/O ( 7.1 sound card ) is a smart choice. Another thing I saw which won me over was that the setup is quit simple.

Note: This link above will point to the same sound card for only $4,-.

In order to do the setup I connected a micro-USB male to USB female adapter to my PI zero and made two small changes.
Please note though that I do intend to remove the USB plug all together and solder things together in the final setup.

1: Find the US sound card number ( in my case the USB card is card # 1 )

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

2: create a file /etc/asound.conf with the following contents

pcm.!default {
        type hw
        card 1
}

ctl.!default {
        type hw
        card 1
}

3: and finally test the speaker :

  speaker-test -c2 -twav

This concluded the setup and testing. To use this external USB sound card in my project it had to fit tightly into the chassis which I built from scratch. So the USB plug had to come off and I had to solder some wires onto the card to connect t up to the Raspberry PI.

Video Doorbell assembly
external USB soundcard after removal of USB plug