Thursday, July 12, 2018

Home at Kallar Kahar


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!

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:
  1. Raspberry PI (I worked with Raspberry PI Zero W)
  2. 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()

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.