Monday, September 4, 2017

Tutorial: Building Your First Drone

Developing Your First Robot


Develop a remote-controlled Drone with a camera feed. Requirement sparks from the need to investigate in small tight places. This is to help inspect specific environments that might prove difficult to reach without causing break and tear. Control is meant to be conducted through a laptop, mobile or tablet.



  • Small flathead screwdriver (small electric testing screw driver will do the trick)
  • Glue Gun


  • Raspberry PI running the Raspbian OS (Follow NOOBs tutorial for setup [1])
  • Mobile Battery Pack
  • 2-Wheel chassis (will be used for prototype purpose but can be switched based on application)
  • L298N board (for a 2 DC motor chassis, might be required to swap out if chassis is changed)
  • USB WiFi adapter
  • Raspberry PI camera (using 5MP standard camera, can be changed in the event of application change)
  • LED (using a 3 color LED)
  • 9v Battery (connector might be useful but unnecessary)
  • Relevant jumper cables to connect it all together
  • 5V Battery Pack (To power the Raspberry PI, if Possible identify one with a 2mA current as it will affect the performance of the PI)


Assembel It

  1. Connect the camera to its designated location on the raspberry pi
  2. LED has 4 connectors, Left to Right:
    1. Red
    2. Green
    3. Blue
    4. Ground
        using 4 female-to-female jumper cable, connect the 4 pins of the LED to the following pins in the same order as above, 3, 5, 7, 9 (where 9 is for ground)
  3. Connect the L298N board: the L298N board is split into 4 sections:
  4. Section on the left to control the left wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the left DC wheel (on the chassis) and the bottom slot to the negative slot of the left DC wheel.
  5. Section on the right to control the right wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the right DC wheel (on the chassis) and the bottom slot to the negative slot of the right DC wheel.
  6. On the top left slot, there are 4 pins that should be connected to the raspberry pi. The two on the left will control the left wheel, and the 2 on the right will control the right wheel. From Left to Right, connect the Pins in the following order 35, 37, 36, 38.
  7. On the top right side of the L298N board, there are three slot:
    1. using a male-to-male jumper cable, connect the right slot to the positive side of the 9V battery
    2. Using to jumper cables, connect the middle slot to the negative side of the 9V battery using a male-to-male jumper cable and to pin 39 using a male-to-female jumper cable
    3. leave the right left slot empty (you can potentially connect it to Pin 2 of the Raspberry PI but concern is that it will not be capable of providing the PI with a steady current which in turn will impact the stability of the PI.
  8. Connect the USB WiFi adapter to one of the USB slots on the raspberry PI
  9. Using a glue gun, fix everything in place to ensure it stays in place. ensure to fix the camera and the LED in place.

Configuring the Raspberry PI

  1. Run 'sudo apt-get update' and once completes, 'sudo apt-get upgrade' to ensure all dependencies have been applied
  2. using 'sudo apt-get install xxx' to install the following components where 'xxx' will be replaced by the component name:
    • 'hostapd' to enable the raspberry pi to act like a WiFi hotspot
    • 'dhcpd' to allow the pi to issue IP addresses for connectivity
    • 'oracle-java8-jdk' to get the latest Java Development Kit (can be replaced with ‘java’ in case of applying the solution)
    • 'vncserver' to enable remote desktop to Raspberry PI (Useful to run NetBeans, if using command line compiling, unneccesary)
  3. Install RPI Webcam (based on reference3)
  4. setup 'hostapd' and 'dhcpd' based on reference 2
  5. Download the latest "Netbeans" from 'http://' and extract it. it might be useful to create a shortcut on the desktop.



  1. Install Visual Studio. Ensure to select Windows Desktop, .NET Framework 4.5 (or the latest) and Web components
  2. Connect to the Raspberry PI WiFi network you setup, I am using the SID "Drone"
  3. using putty, connect to the raspberry PI and ensure connectivity (I am using IP '')
  4. Run 'vncserver :1' to enable X-Terminal
  5. using VNC client, connect to the PIs X Terminal using ''
  6. Now you can directly configure the PI through the GUI interface or the Command Prompt as required.


Connection to the Drone will be connected through WiFi as it:
  • Helps with the distance that can be covered in contrast to bluetooth and infrared,
  • In addition, with WiFi, we can configure a Wireless LAN that is hosted from the PI which would simplify the development of a TCP/IP application,
  • Tutorials are readily available
  • Both Java and .NET cover it as part of their standard Framework.
  • Messages can be passed between client and server in ASCII format


Writing the Raspberry PI code (Server)


 Setup TCP Listener
 Listen: Establish Connection
 Case to received command
  Light: Toggle Light 'On' or 'Off'
  Forward: Move Forward by setting pins 35 and 36 to true for 0.5 Secs
  Backward: Move Backward by Setting pins 37 and 38 to true for 0.25 Secs
  Left: In-Spot turn Left by switching pins 35 and 38 to true for 0.10 secs
  Right: In-Spot turn Right by switching pins 36 and 37 to true for 0.10 secs
  Default: Do nothing
 Terminate Connection
 Goto Listen


Writing the Client Code


 MainFrame: Execute Command
 Connect to Server on Listening Port
 Case to selected command
  Light: Send Light Command to Server
  Forward: Send Move Forward to Server
  Backward: Send Move Backward to Server
  Left: Send Turn Left to Server
  Right: Send Turn Right to Server
  Default: Do nothing
 Terminate Connection
 Goto MainFrame


Camera Feed

On Server: Modify main page of web page on PI to only display the webcam picture (continuously refreshed picture). This can be identified by going through the PHP page as downloaded by the RPI webcam solution and clearing everything that is not related to the <div> for the camera shot. Your new PHP file should be reduced to fit in a page or slightly over.

On Client: Using a web control, point the URI to the webcam page on the PI (can test URI using any browser)


After Closure, what was developed was a base product of a remote controlled drone with a camera feed. The idea is to be able to investigate locations that are difficult to reach. Based on the applications (highlighted below), the drone can be customized further to be built for a specific need. The above details the implementation which covers details of the development of the base product. A good step forward might be to try to deploy it as a live solution and omitting out all development steps.


  1. Installing Raspbian with NOOBS (19-Dec-2016)
  2. Setting Up a Raspberry Pi as a WiFi Access Point (19-Dec-2016)
  3. RPI-Webcam-Interface (24-Nov-2016)

Friday, December 13, 2013

Multi-Lingual JSF

The default answer to having a multilingual page when developing an application is to develop two pages. This will usually add the complexity of managing the pages by resulting in the added effort of maintaining both pages/forms when having adding/amending a function. A simple solution to the problem is by considering the language to be as a separate function and manage it accordingly.

In-line with the function of multi-lingual, let us use the terminology of Function-Oriented application (as a sub-level of OO) where the function of presentation is isolated from the function of language and, as such, is isolated from the core function of the application. Within JSF, you can easily isolate the functionality of a multi lingual application. Let us start by a bundle two bundle files (This can be in a database if you prefer). Here I will use Arabic and English





Then Create a Managed Bean with the scope set as Session Scoped (This is to ensure you maintain the selected language)

public class UserSession implements Serializable{
      private String lang;   
     FacesContext ctx;     
     public void setAr(){   
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
    public void setEn(){  
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
    public String getLabel(String label){  
            return ResourceBundle.getBundle("/Bundle"+lang).getString(label);  
        } catch (Exception e){  
            return "No Label for " + label;  
    public String getLang() {  
        return lang;  
    public void setLang(String lang) {  
        this.lang = lang;  

Finally, your JSF page. Depending on the label you need to retrieve, you may use the expression language in the following form:
<h:form dir="#{userSession.getLabel('dir')}">  
    <p:commandLink value="English" action="#{userSession.setEn()}" />  
    <p:commandLink value="عربي" action="#{userSession.setAr()}"  />  
    <h:outputText value="#{userSession.getLabel('next')}"/>  
    <h:outputText value="#{userSession.getLabel('Previous')}"/>  

where dir while define the orientation of the page (left to right or right to left), next and previous will refer to the label title next and Previous respectively in the bundle bundle file based on the selected language. By implementing you code in the above manner, you open the opportunity to configure new languages as you feel free and it will require minimum maintenance from a technical perspective.

Friday, May 3, 2013

Education of Trust in Saudi

Before acknowledging or denying the story, let me tell it to the end.  This is a story of how trust is educated in Saudi.  And although it may sound extreme, I myself would not have believed it if it was not for experiencing it first-hand.  Although the tale might be old, this is the case till today, and it pains me to realize that a country that claims to rule by the Islamic doctrine had failed to create a culture based on common trust between the individuals of its own public and, worse still, between the common public and the governmental.

Our story begins with the academic year of 95/96.  By "chance" our Religious Studies teacher was a fundamental Saudi traditionalist during that year, the same year in which around 75% of students in our school where failed in Religious Studies of which I escaped and my brother fell victim to.  Naturally Students and parents all complained due to the injustice that befell the students.  However, the school's headmaster refused to take a stance.  When we started to request our papers, all requests were rejected and at the start of the new academic year our papers were burnt for all to see in the school's playground.  This situation re-occurred the following year (my final year in intermediate school) in which (thankfully) both my brother and myself escaped failure.  Sadly the Ministry of Education and the school never issued any investigation into the issue.

Think of the implication the above story would have on a student as he is coming of age.  How can he grow to trust anyone?  Better yet, whether it is by chance or not, this happens to many in Saudi (maybe not to the extreme of burning the papers) especially those finalizing their education in institutes of higher education.  Students are failed due to a grudge by the educator, and the educator is rewarded while the student in question is penalized when attempting to expose the corrupt educator.  As such, students graduating into Saudi's growing job market (and new adults into the Saudi Community) are taught not in the best methods of being devious.  They are raised to lie and cheat.  Further yet, they are lectured on truth and honesty and trained on deceit and dishonesty.  Let me take this one step further.  If such tales happen in governmental educational facilities in Saudi, how do we expect to have a generation that truly trust the government official publication or, potentially, any governmental reports and claims?

So how do we fix the issue?  It all starts with the up-bringing.  Students need to be treated with trust (i.e. trust should be practiced not spoken about).  Once we have a good platform to start from, we start punishing the deceitful (regardless of rank).  So a teacher intentionally failing his students, should be punished accordingly.   This will give raise to a culture that believes and understands that lying and cheating is frowned upon by a system that is trying to build trust between its players.

It is not all lost on Saudi culture.  There is still hope to create a community based on trust and loyalty.  A culture that functions correctly and, in accordance, functions on the basis of Islamic values.  But we do need to action this now.  It is time to acknowledge that we. as a Saudi Muslim public, are flawed, that our social values need visiting and that we can potentially progress.  We need to step out of this persona that we have our unique situation (different from any other community) and are perfect in every way.  Once we step away from such arrogance and into a more modest lifestyle and by realistic with ourselves, we will have a chance to truly prevail.

Tuesday, May 1, 2012

My Saudi Identity

During the past several years, Saudi Rights Activists have been propagating the idea of a Saudi Identity shared amongst the people of Saudi Arabia.  Such an identity has been sponsored by King Abdullah since he has consumed kinghood.  This was displayed in the national dialogue and has also been re-emphasized in both the Janadriya festival and the Saudi National Day.   These events have celebrated the diversity of the Saudi Kingdom, which gives us a notion that a Saudi Identity emphasizes on the diversity of Saudi culture, tradition and even faith.  But if that is the case, why is diversity attacked in the kingdom? And why is it that the system does not prosecute against prejudices of all its forms?

When the king sponsored and organized a national dialogue, he tried to emphasize on the aspect of the diversity of the religious faiths within the kingdom.  Yet when it comes to practice, it seems that such a diversity has yet to be recognized.  When a new law is to be studied and implemented, it is considered only within the scope of the Wahhabi School.  Also, the Supreme Court in Saudi Arabia only rules according to interpretation of the Wahhabi school.  In addition, religious education in the kingdom does not tolerate any other faith but the Wahhabi interpretation of Islam.  All other faiths have been deemed as insignificant and, according to some, heretic.  With this in mind, how can my Saudi Identity represent the diversity in Islamic faiths in accordance with the national dialogue?

Another national celebration in Saudi Arabia is the Janadriya festival, a festival that celebrates the cultural diversity of Saudi Arabia and is organized annually by the government.  When visiting the Janadriya festival, the diverse cultures within Saudi Arabia is quite astonishing.  Not only that, but each culture has its own set of convictions, traditions and even local folklore.  Yet, these traditions in Saudi Arabia are only remembered for the ten days of the festival.  As soon as it is over, their history is forgotten and their traditions are ridiculed.  In fact, if it is not a tradition of the Royal Family, it will be considered as valueless and alien.  Therefore, when I start to consider my Saudi Identity within this context, I fail to realize how it can represent my cultural values.

Another potential element of a Saudi identity is the notion of unity which is celebrated during the Saudi National Day, which is held on the 23rd of September.  A “celebration” that has been sponsored by the King used to enforce a sensation of an identity that is unique to the Saudi people.   However, I still cannot identify what I am celebrating.  It cannot be the unity of the Kingdom as my government has not shown a sign of respect towards the different communities that are bound by the borders of this nation.  In fact, it has not tackled those that are seeking to separate the community.  Other than the Saudi National Day, to me, it seems that there is no real attempt to encourage the development of a sense of unity in Saudi Arabia.

With the failure to identify faith, culture and unity as symbols of my Saudi identity, I thought I would seek a sense of equality in how I am viewed by the representatives of the law.  This means that I should be treated as an equal in the land of Saudi Arabia (according to the law).  This also means that the ruling system should also automatically prosecute those that discriminate against me due to tribe, region or faith.  If my Saudi Identity represents my geographical belonging and, in turn, a legal representation of my identity, it means that this system should protect my right as a partial owner of this Saudi land.  Sadly, while considering this particular notion, I feel as if I am journeying through a wonderful pipe dream waiting to wake up.   When considering this aspect of my Saudi identity, whether it is a lack of laws or un-implemented laws, it does not seem that the law is protecting me as a Saudi individual living within the Saudi borders.

What does my Saudi identity mean to me? It has not respected my choice of faith because I am not a Wahhabi (the official faith of the Kingdom).  It has not respected my culture as it has slandered it in any possible way it can.  It has disrespected my right to think freely and has attempted to set an example to me by imprisoning free thinkers from my community and other communities.  It has tried to convince me of the luxurious life a Saudi lives and attempted to hide away the poverty of most Saudis.  It has disrespected my intelligence by propagating its version of Islamic faith as the only true faith and attacking all other faiths including mine.

After discussing the issue of my Saudi identity with colleagues and friends, they usually fail to give me an answer to what this identity means to them.  Given their backgrounds, their identity is usually defined by their family, tribe or city/region.  It is never defined by a united nation that maintains their rights.  It is not the religious values that govern them and it is not a common set of traditional values that are, assumingly, shared between the communities.  One even dared to describe it as a “shameful origin”.  Through my discussions, I did hope to arrive at a justifiable reason to why I should fight for this identity and therefore be proud of.  Sadly, the only conclusion I arrived at is that a Saudi identity, to me, represents the disrespected diversity exemplified by living a lie.