My first experience with the ZedBoard SoC board.

I recently registered my masters with the Central Peninsula University of Technology in Cape Town, and part of my research with include the use of a FPGA for real-time network communications between smart grids. So I am faced with 2 things – learning a new environment as well as a different field(Power Systems) coming from an Electronics and Computer engineering background.

I am the type of person that is always eager to learn new things, so being thrown into the deep end is nothing foreign to me, sounds like something I took from my resume.

After I registered for the MEng, I was given this board – and I needed to familiarise myself with it.

This blog will detail my experiences and hacks.

zedboard-2zedboard box

Getting started with the ZedBoard SoC

Firstly, we will need to download Xilinx Vivado suite, in order to do this we go to the Xilinx Downloads page to obtain the installer.
Select version 2017.2 or later on the left sidebar. I used the “Single File Download” option and chose “Vivado HLx 2017.2: All OS installer Single-File Download”. It is a tarball that is 22Gigs, yes there was no typo – 22Gigs large.
Note: You have to be a registered user to download it.

Once the download is completed, untar the tarball, cd into the extracted directory, and execute the GUI installer.

# Confirm the file is valid by checking the md5 hash
# MD5 SUM Value: 958f190a089ad3f39d327d972c7dcf35
$ md5sum Xilinx_Vivado_SDK_2017.2_0616_1.tar.gz
# Once that is confirmed untar and install
$ tar -zxvf Xilinx_Vivado_SDK_2017.2_0616_1.tar.gz
$ cd Xilinx_Vivado_SDK_2017.2_0616_1
$ sudo ./xsetup

Agree to the terms of use and select “Vivado HL WebPACK Edition”. Next, tick also Xilinx Software Development Kit (SDK) on the next page, since it’s free and very useful.

Note: by default, Vivado is installed into the /opt/Xilinx/Vivado/2017.2 directory.

At the end of the installation, the license manager will ask for a license. The “Obtain a license” button in the license manager if that does not work, just go to Xilinx Licensing site directly and get a WebPACK license and install it.

Once done with the installation, we need to install the JTAG cable drivers that are needed for many purposes e.g. programming the hardware.

cd
 /opt/Xilinx/Vivado/2017.2/data/xicom/cable_drivers/lin64/install_script/install_drivers
sudo ./install_drivers

Now, change the ownership of the ~/.Xilinx directory so that you may use Vivado without superuser privilege:
sudo chown -hR $USER:$USER $HOME/.Xilinx/

Every time you want to fire up Vivado, remember to source the “settings” scripts to have the right environment variables:

source /opt/Xilinx/Vivado/2017.2/settings64.sh
source /opt/Xilinx/SDK/2017.2/settings64.sh

Lazy people like myself prefer to uncomplicate the complicated, to avoid executing the above commands each and everytime one needs to start Vivado – do the following.

echo "source /opt/Xilinx/Vivado/2017.2/settings64.sh" >> ~/.bashrc
echo "source /opt/Xilinx/SDK/2017.2/settings64.sh" >> ~/.bashrc
source ~/.bashrc		

When done, start-up Vivado from the command line:
vivado
or SDK:
xsdk

Quoting Raymond Hettinger, While hitting the podium and “There must be a better way!”

Create a new file called vivado.desktop

sudo vim /usr/share/applications/vivado.desktop
# Copy the contents to the file

[Desktop Entry]
Type=Application
Version=1.0
GenericName=Vivado
Name=Vivado
Comment=Vivado
TryExec=/opt/Xilinx/Vivado/2017.2/bin/vivado
Exec=/opt/Xilinx/Vivado/2017.2/bin/vivado
Icon=
Terminal=false
Categories=Education;System
StartupNotify=false
X-GNOME-Autostart-Delay=5

When done, log out-in in order to refresh the systems settings.

Vivado should be available from start-menu and can be copied to the desktop for future executions.

Advertisements

Docker: Remove all images and containers

Problem:

You use Docker, but working with it created lots of images and containers. You want to remove all of them to save disk space.

Solution:

Warning: This will destroy all your images and containers. It will not be possible to restore them!

Run those commands in a shell:
# Delete all containers
sudo docker rm $(docker ps -a -q)
# Delete all images
sudo docker rmi $(docker images -q)

This solution has be proposed by GitHub user @crosbymichael in this issue

Create a global git commit hook

Recently found out about these git hooks and they work flawlessly but my only worry was that I had to copy all my hooks over every repo such that I could use them, which was a pain sometimes.

Then started reading about this so called global git hooks, and found a fix.

Usually the default template library is found at /usr/share/git-core/templates and we are going to use that directory for all our hooks.

1. Enable git templates:

git config --global init.templatedir '/usr/share/git-core/templates/'

This tells git to copy everything in /usr/share/git-core/templates/ to your per-project .git/ directory when you run git init

2. Write your hooks in /usr/share/git-core/templates/hooks.

For example, here’s an update hook (located in /usr/share/git-core/templates/hooks/update):

#!/bin/sh
# Prevent pushing changes to master branch
if [ $USER != "mmphego" ];
then
  if [ "$1" == refs/heads/master ];
  then
    echo "Manual pushing to this repo is restricted"
    exit 1
  fi
fi

4. Make sure the hook is executable.

chmod a+x /usr/share/git-core/templates/hooks/update

5. Re-initialize git in each existing repo you’d like to use this in:

git init

NOTE if you already have a hook defined in your local git repo, this will not overwrite it.

Allow users of a certain group to run a command without sudo passwd

Time to time I usually find myself typing sudo to execute commands requiring sudo rights, and this is repetitive which simply means one gets weary of typing sudo password every time, hence this blog post. Reason for this is to remind me how to do it the next time I am faced with such conundrum(s).

Suppose I wanted to add a group of users who are allowed to run mount and umount without passwords. So I first want to add a group called “staff”

sudo groupadd staff

Next we need to edit the /etc/group and add the users

staff:407:

will be present ,hence append users you want to add the users separated by commas.

staff:x:407:user1,user2,...

Now we need to configure sudo to allow members of the “staff” group to actually invoke the mount and umount commands.

You just need to add the following lines to /etc/sudoers or execute sudo visudo

%staff ALL=NOPASSWD: /sbin/mount, /sbin/umount

Now sudo mount won’t ask password but since it is a pain in the butt typing sudo all the time, we can avoid it by doing the following:

I can create the following script called “/usr/bin/mount” (and similar script for umount)

#! /bin/sh
sudo /sbin/mount $*

To make this slightly more secure, We might want to change the ownership of these scripts to the “staff” group.

chgrp staff /usr/bin/mount /usr/bin/umount

and then make them executable only for the group “staff”

chmod g+x /usr/bin/mount  /usr/bin/umount

Note:Depending on the OS you are using please check where mount and umount commands are located. It might be in /bin/ instead of /sbin.
So you might have to make necessary changes

 

Done

Smart Doorbell using Raspberry Pi

About a year ago, I had to do a project titled Smart Home Automation using a Raspberry Pi and Arduino, part of the project  incorporated a doorbell but not just any doorbell but a Smart doorbell.

Why do I call it a Smart Doorbell?

A classic doorbell can be defined as a signalling device typically placed near an entry door to a building. When a visitor presses a button the bell rings inside the building, alerting the occupant to the presence of the visitor.

The smart doorbell, works in that manner however when a visitor presses the doorbell button it notifies the occupant with an images of the visitor and also sends an email, sms and push notification (to an smart device) to the occupant in case they are not able to hear the bell ringing.

If the button is pressed a pre-recorded voice notification is played for the occupant to check the door as there might be someone, this happens concurrently with an sms notification while a picture of the visitor is captured and sent to both email and push notification. Initially there was a feature to enable 2-way real-time video communication but due to network latency and high resource usage the feature was deprecated.

Click For A Demo

Comment if you need the code

See code snippets(Initial Revision): https://mmphego.wordpress.com/2015/01/11/smart-doorbell-using-rpi-with-voice-and-email-notification/

Setting up an MQTT server on Debian Jessie

Jolabs Tech Blog

Intro

Today we`re going to be setting up our own home automation server in a dedicated linux server. It’s gonna host our platform using the the Node.Js environment. The different devices around the house are going to be speaking MQTT to this server. I’ve chosen MQTT because of it’s robustness and lightweightness allowing for easy deployment on my favourite controllers: ESP8266. The esp-01, still the cheapest to this date,only sports 4mb of flash, has no trouble at all controlling a couple of relay’s for now. In the future the newer/bigger boards can be used to get more IO and function, but for now I’m going to be using the esp-01’s extensively around the house flexibly (it’s wireless…).

Requirements

The idea is to have the server online 24/7, so consider a computer thats not to power-hungry; like a Raspberry Pi or a small embedded box computer. Alternatively you can boot up…

View original post 340 more words

Bash terminal prompt trick

This cool trick will transform one’s dull terminal to a fancy terminal with date + time and current Git branch if any.

Copy below code to your ~/.bashrc

export PS1='\[\033[0;32m\]\[\033[0m\033[0;38m\]\u\[\033[0;36m\]@\[\033[0;36m\]\h:\w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;31m\] [\D{%F %T}] \$\[\033[0m\033[0;32m\] >>>\[\033[0m\] '

When done, source the bashrc file and then voila!!!

$ source ~/.bashrc

Dull Terminal

screenshot_2016-12-13_10-08-28

Epic Terminal with date, time and current git branch

screenshot_2016-12-13_10-07-58