Thursday, November 28, 2019

Kivy - a Python based cross-platform framework

Kivy is a python based library for development of mobile apps including the natural user interface (NUI). It is cross platform library that can run on iOS, Android, Linus, Windows, OSX and Raspberry Pi with distribution protocol under free and open source software. It has been developed and is distributed by the Kivy Organisation.

Features :

  1. Supports multiple inputs including the mouse, WM_Touch, WN_Pen, Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID (Human Interface Device) and TUIO (Tangible User Interface Objects).
  2. Powerful, Stable and well documented API with programming guide to get started.
  3. It is business friendly, 100% free to use under MIT license
  4. Support for lot of widgets.
  5. Good Documentation.
  6. It is GPU accelerated as the graphics engine is built over OpenGL ES 2, using a modern and fast graphics pipeline.
Installation and Configuration of Kivy

Kivy can be installed on any Operating System without any compatibility issues. It can be downloaded from https://kivy.org/#download, and once it is done, the installation instructions are provided on the download page.


$ python -m pip install kivy


$ python -m pip install ffpyplayer

Configuring Kivy :

MacOS : /Users/Username/.kivy/config.ini

Windows : C:\Users\Username\.kivy\config.ini

Linux: /home/user/.kivy/config.ini


Architecture of Kivy :





  1. Core Providers and Inputs This allows user to open a window, displaying images and text, playing audio, getting images from a camera, spelling correction etc
  2. Graphics Kivy’s graphics API is our abstraction of OpenGL. Kivy provide the graphics API that lets you draw things using simple metaphors that do not exist as such in OpenGL (e.g. Canvas, Rectangle, etc.).
  3. Core The code in the core package provides commonly used features such as Clock : You can use the clock to schedule timer events. Both one-shot timers and periodic timers are supported. Cache : If you need to cache something that you use often, you can use inbuilt class. Gesture Detection : It provides a simple gesture recognizer that you can use to detect various kinds of strokes, such as circles or rectangles. You can train it to detect your own strokes. Kivy Language : The kivy language is used to easily and efficiently describe user interfaces. Properties : Kivy provides property classes that links the widget code with the user interface description.
  4. UIX Widget : Widgets are user interface elements that you add to your program to provide some kind of functionality. They may or may not be visible. Eg: Buttons, Label etc Layouts : User can use layouts to arrange the widgets. Eg: Grid layout, Box layout, Relative layout etc
  5. Widgets and Event Dispatching In Kivy, a widget is an object that receives input events. It does not necessarily have to have a visible representation on the screen. All widgets are arranged in a widget tree (which is a tree data structure as known from computer science classes). One widget can have any number of child widgets or none.
Kivy App Life Cycle :






Running the Application :

Linux : $ python main.py

Windows :


$ python main.py

or

C:\appdir>kivy.bat main.py

Mac OS X :

$ kivy main.py

Sunday, November 17, 2019

Creating FM Radio Station using Raspberry Pi

This tutorial is for creating your own FM Radio station using FM Transmitter code and a copper wire.

Equipments Required

  • Raspberry Pi 2/3/4
  • Micro SD Card (minimum 16 GB)
  • Standard Power supply
  • A copper wire (1 metre long)
  • Internet connectivity (Wifi/ Ethernet cable)
Before starting the tutorial, you'll need to understand Copper wire will be hooked up in GPIO pin no 4.
Below diagram will help you identifying the pin.



or you can read about it thoroughly with this link.


The wire will act as an antenna. But please note that the sound quality and frequency range will not be best. It'll work in small range like a small office or home


Starting up

  1. Update your Raspberry Pi

    sudo apt-get update

    sudo apt-get upgrade
  2. Installing package for setting up the Radio Station

    sudo apt-get install -y sox make gcc g++ git alsa-utils libmp3lame-dev
  3. Now, once this package is installed, we can clone FM Transmitter library. This uses the general clock output to produce frequency modulated radio communication. It reads mono and stereo files, data from stdin.
    To clone this, use following commands

    cd ~

    git clone https://github.com/somu1795/fm_transmitter.git
  4. Now moving to the directory and running make command

    cd ~/fm_transmitter

    make
  5. Now running this

    sox /home/pi/fm_transmitter/star-wars.wav -r 22050 -c 1 -b 16 -t wav - | sudo ./fm_transmitter -f 100.3 -

    Defining the above arguments
    -c : Defining number of channels
    -b : Bit rate of output

    You can change this frequency according to your requirement.
Adding Support for MP3 files

  1. Clone x264 support. This will be required to compile FFmpeg (command line tool will converts audio and video formats)

    cd /usr/src

    sudo git clone git://git.videolan.org/x264

    cd x264

    sudo ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl

    sudo make

    sudo make install
  2. Once the above commands are run, we will run following commands for compiling FFmpeg

    cd /usr/src

    sudo git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

    cd ffmpeg
  3. Version specific commands ( Please see which version of Pi you have and install the command as per your requirement )

    Raspberry Pi 3 and later

    sudo ./configure --arch=armv7-a --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --extra-cflags='-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard'

    Raspberry Pi 2 and before

    sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
  4. Now running below commands

    sudo make -j4

    sudo make install
  5. As FFmpeg is now compiled and setup we can now run MP3 files.

    cd ~/fm_transmitter

    sudo python ./PiStation.py -f 100.3 bahubali.mp3






Please note there are rules and regulations for broadcasting FM Frequencies. Please check the laws of your country before transmitting the signal to any frequency.