Introduction
I didn’t like Python when I was first introduced to it a couple of years ago. Since that time I’ve learned that it is a great quick-n-dirty language that can be used to build an app or what we used to call a “hack”. The extent of its built-in features and the enormous amount of open source code makes it a natural do-it-yourself language.
Install Tool Chain or Installation Scripts
The first step is to install several tools to facilitate installation of Python modules.
sudo apt-get install -y python-pip git
sudo apt-get install -y build-essential python-dev python-smbus
sudo apt-get install i2c-tools
I like to use Flask so install the following for a basic environment.
sudo pip install flask
sudo pip install requests
sudo pip install flask-httpauth
My do-it-yourself home automation system uses MQTT for messaging. My Python apps subscribe and publish using the Paho implementation.
sudo pip install paho-mqtt
I like to use Adafruit’s I2C backpack for LED and OLED devices. Their libraries usually require the Python imaging module.
sudo apt-get -y install python-imaging python-pil
Add Adafruit libraries for the most common devices. I like to use the GPIO, LED backpack and OLED displays for almost every project. Upgrade pip to use setup wheel
sudo python -m pip install --upgrade pip setuptools wheel
Start with the GPIO stuff. I like to use a directory called /home/pi/systemd.
mkdir systemd
cd systemed
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
sudo python setup.py install
Add OLED python class:
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
sudo python setup.py install
Add the LED backpack class:
git clone https://github.com/adafruit/Adafruit_Python_LED_Backpack.git
cd Adafruit_Python_LED_Backpack
sudo python setup.py install
Sync and reboot. The next step depends on your project device.