This page is an archive of iMAL's wiki that operated between 2012 and 2022. It documented projects, residencies and workshops mostly taking place at iMAL's Fablab.

Older & newer Fablab projects are now found at fablab.imal.org

Objets connectés / Raspbery Pi + Python

Notes et commentaires concernant l'atelier Objets connectés / Raspbery Pi + Python.

Tous les scripts sont disponibles dans le dépôt créé pour le cours: https://gitlab.com/frankiezafe/pyhon-iot

(adaptation du README.md du dépôt)

scripts

web

  • web00_server.py : basic file server (start it in the html folder with python ../web00_server.py to make visible the base root stuff)

GET requests

  • web01_server.py : parsing GET requests, and responding to the browser
  • web02_server.py : changing returned message depending on the get parameters
  • web03_server.py : adapting header to send images, big piece of code, go smoothly!
  • webserver.py : script developped during the workshop

POST requests

  • web04_server.py : parsing POST requests and saving files on drive
  • web05_server.py : listing files uploaded & providing links to files
  • webpubliser.py : script developped during the workshop

scrapping

  • beautifulsoup00.py : simple example on how to extract content from a webpage

requires the installation of python-bs4, on linux:

sudo apt install python-bs4
  • beautifulsoup01.py : advanced example using selenium's webdriver

requirements:

works on linux desktop 64 bits, for raspberry, see below

sudo apt install python-bs4
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
sudo apt-get install xvfb
sudo apt-get install unzip
wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
sudo -H python3 -m pip install pyvirtualdisplay selenium

on raspberry:

source: https://christopher.su/2015/selenium-chromedriver-ubuntu/

test your installation with the script selenium_chrome.py

  • tweetscrapper00.py : get all tweets from a user, depending on twitter definition of 'all'
  • tweetscrapper01.py : another script to get tweets form a specific user

source: https://stackoverflow.com/questions/42273089/scraping-number-of-retweets-using-beautifulsoup

  • twitter/get_tweets_by_hashtag.py: script developped by Amélie Dumont retrieving tweets by hashtag

flask

Flask is an advanced webserver, compare to SimpleHTTPServer used in the scripts above.

The folder app_flask contains a project of Amélie Dumont that controls the rotation of a servo motor via a web interface.

json

  • json_example.py : demo on how to serialise and deserialise python data using json

OSC

Open Sound Control demo in python, allows to send and receive data using UDP protocol.

  • osc_sender.py : how to send OSC messages
  • osc_receiver.py : how to receive OSC messages
  • osc_broadcaster.py : quick and dirty way to send messages to all computers in LAN

Threading

Multithreading designates the fact that several application runs simultaneously in a computer. The lastest Raspberry PI having a multicore CPU, threading allows to run several applications/scripts at the same time, without waiting for a process to complete to starts another one. This is an important topics to master when creating games, robots, or any other demanding application running in realtime, reacting to inputs or parsing live feeds.

  • threading_example.py : shows how to run several 'applications' within one script

subprocess

to launch programs with python, use subprocess.call, see documentation for more details

  • vlc_launcher.py : play a video in fullscreen with vlc

PIL

Pillow is a library to manipulate images in python.

  • image_manipulation.py : shows basic PIL functionalities

OpenCV

OpenCV is a powerful image processing library, massively used in computer vision. It is trickier to understand then PIL because it is based on matrix transformations.

  • motion_detection.py : detection of motions in live video (webcam in this case)
  • motion_detection_pi.py : adaptation of the script for picam, with desactivation of white balance and OSC emission of the anaylis.

PyGame

PyGame is a library containing all the required features to create games in python.

  • pygam/game.py : basic script to run a game with keyboard interactions
  • pygam/particles.py : a simple particles system interacting with the mouse (2D)
  • pygam/particles_3dgrid.py : 3D adaptation of the particles, using OpenGL
  • pygam/pygl.py : OpenGL demo using pygame by Bastiaan Zapf

note: tous les scripts développés par frankiezafe & Amélie sont diffusés sous license GNU LGPLv3

Gallery

Info

Animated by:

Date: 30 Jul 2019 - 2 Aug 2019

Participants