My parents have always been adventurous but not in the traditional sense! They have always managed to find adventures with everything they do. No one would think about building their retirement home in a remote location in Pakistan, yet here they are in the middle of no where, with the most scenic views, they have built one of the most beautiful houses of Pakistan! With opposition from almost everyone in the family, they still travelled around 150 kms 3 to 4 times a week for a year to build their dream house!
Thursday, July 12, 2018
Home at Kallar Kahar
Labels:
DJI,
Drone,
Kallar Kahar,
Pakistan,
Scenery
Location:
Unnamed Road, Chakwal, Punjab, Pakistan
Wednesday, July 11, 2018
Playing with e-Paper
Like all other technologies ePaper fascinated me when it was first launched. As part of my first startup failure, I tried developing a product using ePaper, turns out what I was trying to build was already there in the form of Yota phone by a Russian company. While trying to build a similar product I tried to work with ePaper however the original inventors had pretty close IP and would not work with small startups and the Chinese versions that I tried working with were without any proper documentation.
Finally after years I can now play with ePaper by buying cheap off the shelf displays by waveshare configured to work for the Raspberry PI as a HAT. So let's see this cool display technology! I was inspired by the instructable to get started with my experiment.
Required Hardware:
- Raspberry PI (I worked with Raspberry PI Zero W)
- 2.7 or any other size Waveshare ePaper HAT display
Step 1: Install the required libraries
Step 1 is to install the required libraries for the Raspberry PI using the steps on the link
You will need to install
- C library for bcm2835
- Python libraries for Raspbian
- RPI.GPO and spidev
- In the case of these libraries a simple pip install RPI.GPO / pip install spidev should work
- python-smbus
- python-serial
- python-imaging
Step 2: Configuring the interfaces
On the same link you will need to configure the interfaces I2C, serial and SPI. You can use the steps mentioned above or simply use the start menu->Raspberry Pi Configuration -> Interfaces
Step 3: Run the demo code
Download the demo code and run using Python.
import epd2in7b
import Image
import ImageFont
import ImageDraw
#import imagedata
COLORED = 1
UNCOLORED = 0
def main():
epd = epd2in7b.EPD()
epd.init()
# clear the frame buffer
frame_black = [0] * (epd.width * epd.height / 8)
frame_red = [0] * (epd.width * epd.height / 8)
# For simplicity, the arguments are explicit numerical coordinates
epd.draw_rectangle(frame_black, 10, 130, 50, 180, COLORED);
epd.draw_line(frame_black, 10, 130, 50, 180, COLORED);
epd.draw_line(frame_black, 50, 130, 10, 180, COLORED);
epd.draw_circle(frame_black, 120, 150, 30, COLORED);
epd.draw_filled_rectangle(frame_red, 10, 200, 50, 250, COLORED);
epd.draw_filled_rectangle(frame_red, 0, 76, 176, 96, COLORED);
epd.draw_filled_circle(frame_red, 120, 220, 30, COLORED);
# draw strings to the buffer
font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18)
epd.draw_string_at(frame_black, 4, 50, "e-Paper Demo", font, COLORED)
epd.draw_string_at(frame_red, 18, 80, "Hello world!", font, UNCOLORED)
# display the frames
epd.display_frame(frame_black, frame_red)
# display images
frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
frame_red = epd.get_frame_buffer(Image.open('red.bmp'))
epd.display_frame(frame_black, frame_red)
# You can get frame buffer from an image or import the buffer directly:
epd.display_frame(imagedata.IMAGE_BLACK, imagedata.IMAGE_RED)
if __name__ == '__main__':
main()
import epd2in7b
import Image
import ImageFont
import ImageDraw
#import imagedata
COLORED = 1
UNCOLORED = 0
def main():
epd = epd2in7b.EPD()
epd.init()
# clear the frame buffer
frame_black = [0] * (epd.width * epd.height / 8)
frame_red = [0] * (epd.width * epd.height / 8)
# For simplicity, the arguments are explicit numerical coordinates
epd.draw_rectangle(frame_black, 10, 130, 50, 180, COLORED);
epd.draw_line(frame_black, 10, 130, 50, 180, COLORED);
epd.draw_line(frame_black, 50, 130, 10, 180, COLORED);
epd.draw_circle(frame_black, 120, 150, 30, COLORED);
epd.draw_filled_rectangle(frame_red, 10, 200, 50, 250, COLORED);
epd.draw_filled_rectangle(frame_red, 0, 76, 176, 96, COLORED);
epd.draw_filled_circle(frame_red, 120, 220, 30, COLORED);
# draw strings to the buffer
font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18)
epd.draw_string_at(frame_black, 4, 50, "e-Paper Demo", font, COLORED)
epd.draw_string_at(frame_red, 18, 80, "Hello world!", font, UNCOLORED)
# display the frames
epd.display_frame(frame_black, frame_red)
# display images
frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
frame_red = epd.get_frame_buffer(Image.open('red.bmp'))
epd.display_frame(frame_black, frame_red)
# You can get frame buffer from an image or import the buffer directly:
epd.display_frame(imagedata.IMAGE_BLACK, imagedata.IMAGE_RED)
if __name__ == '__main__':
main()
Unzip the demo code, locate the python folder and in the terminal run python main.py. If all the libraries installed successfully, you should be able to see the display refresh and display demo text and shapes.
Tuesday, June 26, 2018
Setting up Django Project: Part 1
Environment:
Frameworks:
Preset:
Step 1: Create a new folder
Step 2: Install miniconda for setting up the virtual environment
Step 3: Install and Test Conda
Step 4 : Create a virtual environment with Django
Step 5: Activate / Deactivate virtual environment
base * /Users/shamyl/miniconda3
SLS /Users/shamyl/miniconda3/envs/SLS
/anaconda3/envs/myEnv
Step 6: Create first Django Project
Step 7: Create an app within your django project
- Visual Studio Code
- MAC OSX
Frameworks:
- Django
- Bootstrap (UI)
- Python 3.6
- CondaMini for Virtual Environment
- Github for version control
Preset:
- Visual Studio Code already installed
Step 1: Create a new folder
Step 2: Install miniconda for setting up the virtual environment
- https://conda.io/miniconda.html
Step 3: Install and Test Conda
- Open Terminal in VS Code and run conda --version
- Re-start Terminal by typing exit whether you are using builtin VS Code terminal or regular terminal window
- Type conda --version to verify conda installed
- If you see conda 4.5.4 or something similar, conda is working
- Getting started guide with conda https://conda.io/docs/user-guide/getting-started.html
Step 4 : Create a virtual environment with Django
- conda create --name [envName] django
- Select yes to download and create the virtual environment
Step 5: Activate / Deactivate virtual environment
- Once the virtual environment is created use
- source activate [envName]
- to deactivate: source deactivate
- the keyword source is required on MAC OS
- conda info --env
- You can see which virtual environments have been created using the above command. We can see two
- The one with the * is the active one
base * /Users/shamyl/miniconda3
SLS /Users/shamyl/miniconda3/envs/SLS
/anaconda3/envs/myEnv
Step 6: Create first Django Project
- django-admin startproject [projectName]
Step 7: Create an app within your django project
- python mange.py stratapp [appName]
Step 8: Run your server and test it out
- python manage.py runserver
Step 9: Create GIT Repository and commit to Master
- I'm using GitHub Desktop
- Created a new repository
- Gave it a name and pointed it to the local directory where the project is saved
- Gave a summary and description and pressed the commit to master button to create the first master
Thursday, June 14, 2018
Flying DJI Tello with GO Programming Language
I recently bought DJI Tello which is essentially a DJI technology based drone developed by Ryze Tech a Schenzen based Company. The idea behind buying this drone was to explore how to use it in LearnOBots sessions where I teach kids about coding and technology. One of the first things I did was to fly the drone using it's android app. The second thing I did was to fly it by writing a program in the Go programming language.
According to its website Go is an open source programming language that makes it easy to build simple, reliable and efficient software. I chose it as GoBot can be used to easily program the DJI Tello. GoBot is a framework for robotics, physical computing and IoT writing in the Go programming language. GoBot supports a wide variety of devices including Arduino, BeagleBone, CHIP, DJI Spark and Tello, ESP8266, OpenCV, Raspberry PO, Sphero BB-8 and many many more.
So let's get started with this blog post about programming my DJI Tello with GoBot.
Step 1: Install Go:
You first need to install Go from the following link
Step 2: Installing GoBot
Then open up a command prompt or Terminal and type the following command to install GoBot tools
$ go get -d -u gobot.io/x/gobot/
Step 3: Connect to Tello
Turn on your Tello and connect to its WiFi. The WiFi will be named like TELLO-XXXX.
Step 4: Write your program
You can run the following example taken from the GoBot site. I use the Atom editor and save the file as tello.go. You can give it any name or extension. As long as you have Go installed, you should be able to run the Go program from the command line Terminal.
package main import ( "time" "gobot.io/x/gobot" "gobot.io/x/gobot/platforms/dji/tello" ) func main() { drone := tello.NewDriver("8888") work := func() { drone.TakeOff() gobot.After(5*time.Second, func() { drone.Land() }) } robot := gobot.NewRobot("tello", []gobot.Connection{}, []gobot.Device{drone}, work, ) robot.Start() }
Step 5: Run your program and fly the drone
Then go back to your Terminal (command prompt on windows) and run your Go Program by typing
Go run tello.py
Here is a video of the Test Flight
For full API reference you can visit
Hope you can buy and enjoy programming and flying your own Drone!
References:
Tuesday, June 12, 2018
Full Stack Developer in a couple of weeks
Image source: http://www.sparity.com/services/full-stack-engineering/
Recently I've shifted from full time teaching to full time at my company. One of the differences that I've felt is that I have more time for my own learning. In my previous role as a University teacher, I needed to learn things and then figure out a way to explain them as well. Whereas in my new role as CTO, I can spend more time on learning for myself and not worry about figuring out the best way to teach others. Since my early days in CS, I've never felt comfortable as a web programmer or a designer. I've been mostly involved in embedded programming. Therefore, this was one area that I always felt uncomfortable in. However in my new role, I had to be up to speed with web application development, in order to work on some new products. Just like I always do, I tried to find the shortest way possible to get up to speed with full stack development. I searched around a bit for MOOCs on Coursera, Udacity, Udemy read some tutorials, downloaded a few free ebooks.
After searching around for a few weeks, I finally landed on this udemy course Python and Django full stack Web developer bootcamp which I felt met my requirements of getting started with Full Stack development. The course is pretty well organized and there are a number of components, that I'm already pretty good at, however the organization of the course makes it a very good reference to get started with Full stack web development. It covers, both front end and back end frameworks and also teaches the basics of code maintenance, deployment and some great sample projects. In the course, you can also very easily follow the author's way of setting up your PC for working on different web projects. For example, he makes great use Atom, GitHub, Chrome as well as other tools like the virtual environment. The course covers basics of HTML, CSS, Javascript, Bootsrap, jQuery for front end; Python and Django for back end. The full curriculum can be seen here.
The best part is I purchased it for a mere $10 which is a little more than Rs 1000 and I believe that it has turned out to be great value for money. I would highly recommend this course for someone who is a beginner or would like to quickly get up to speed with Full Stack web development.
Friday, June 1, 2018
Reviewing my DJI Mavic Pro!
Made a short review and unboxing of my DJI Mavic Pro! The quality is not so great, but then again, I'm a totally noob video editor!
Wednesday, September 27, 2017
Word Cloud with R and Twitter
I'm teaching R in the morning to my Advanced Programming class. So I thought let's do some exploration with Twitter and show the power of R and its packages! In this example which I've used from another source (links at the bottom) I plot word clouds by searching for trends on twitter using hashtags. The tutorial I followed led me into a number of problems which I had to solve eventually to get my word clouds!
Step 1: Installation using github instead of CRAN
https://cran.r-project.org/web/packages/twitteR/README.html
In this step we use the installation through github method as using install.packages("twitteR") was causing authorization errors with Twitter. The following paragraph is copied from the README.html paged referenced above.
"twitteR is an R package which provides access to the Twitter API. Most functionality of the API is supported, with a bias towards API calls that are more useful in data analysis as opposed to daily interaction.
Getting Started
- Please read the user vignette, which admittedly can get a bit out of date
- Create a Twitter application at http://dev.twitter.com. Make sure to give the app read, write and direct message authority.
- Take note of the following values from the Twitter app page: "API key", "API secret", "Access token", and "Access token secret".
- You can use the CRAN version (stable) via the standard
install.packages("twitteR")
or use the github version. To do the latter: install.packages(c("devtools", "rjson", "bit64", "httr"))
- Make sure to restart your R session at this point
library(devtools)
install_github("geoffjentry/twitteR")
- At this point you should have
twitteR
installed and can proceed: library(twitteR)
setup_twitter_oauth("API key", "API secret")
- The
API key
andAPI secret
are from the Twitter app page above. This will lead you throughhttr
's OAuth authentication process. I recommend you look at the man page forToken
inhttr
for an explanation of how it handles caching.
- The
- You should be ready to go!
- If you have any questions or issues, check out the mailing list "
Step2: Get your Twitter API key and API secret
Create a new App
Add application name, some dummy URL agree to the terms and create your application.
Once it is created you can find the API key and API secret in the menu in blue. You can use these in your R script to authorize this app to be used from your account.
Step 3: Install required packages
#install the necessary packages
install.packages("wordcloud")
install.packages("tm")
Step 4: Load the required libraries
library("twitteR")
library("wordcloud")
library("tm")
Step 5: Run the following lines
#necessary file for Windows
#to get your consumerKey and consumerSecret see the twitteR documentation for instructions
consumer_key <-
'your key'
consumer_secret <-
'your secret'
access_token <-
'your access token'
access_secret <-
'your access secret'
setup_twitter_oauth
(consumer_key,
consumer_secret,
access_token,
access_secret)
Step 6: Start your analysis
You can experiment by replacing the hashtag in the following function. n=500 means to bring the first 500 tweets from Twitter with hashtag #MUFC
r_stats <- searchTwitter("#MUFC", n=500)
#should get 1500
length(r_stats)
#[1] 1500
#save text
r_stats_text <- sapply(r_stats, function(x) x$getText())
Step 7: Fixing the emoticons problem
twitteR package seems a little old so I was having trouble with emoticons in the tweets that were being returned with the searchTwitter querry. Some functions of R were not able to handle the encoding of the emoticons so I found a solution on
The solution is not neat, as it simply converts these emoticons into HEX values which the twitteR functions can handle, although they are being printed in the word cloud. So need more work on that. It would be interesting to plot an 'emoticloud' instead of a word cloud using twitter hashtags. Maybe an assignment for the students 😈! Notice the use of "emoticon" in discussing a problem with emoticons !
#Fixing the emoticons problem
r_stats_text <- data.frame(text = iconv(r_stats_text, "latin1", "ASCII", "byte"),
stringsAsFactors = FALSE)
Step 8: Clean up and Create the Word Cloud
#create corpus
r_stats_text_corpus <- Corpus(VectorSource(r_stats_text))
#clean up
r_stats_text_corpus <- tm_map(r_stats_text_corpus, content_transformer(tolower) )
r_stats_text_corpus <- tm_map(r_stats_text_corpus, removePunctuation)
r_stats_text_corpus <- tm_map(r_stats_text_corpus, function(x)removeWords(x,stopwords()))
wordcloud(r_stats_text_corpus)
Here is the result of my query. You can see some garbage as the emoticons are being showed as hex numbers. That's just a small workaround. Need to explore more to completely remove them.
Another Result. Searching with the hashtag #muhammad reveals Love and prophet as the two most used words!
This is a lot of fun! Going to experiment some more later! Now gtg as I have a lecture 9am in the morning and its 4:30 am right now!
References:
Subscribe to:
Comments (Atom)