Python snippets

print formatting
print "server said %s and %s" % (content, txt)

delay / sleep
import time

HTTP get / request
import httplib2
resp, content = httplib2.Http().request("")
except urllib2.HTTPError, exc:
except urllib2.URLError, exc:
print "Failed because:", exc.reason

Send email
import smtplib
"""this is some test documentation in the function"""
message = textwrap.dedent("""\
From: %s
To: %s
Subject: %s
# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)

Raspberry Pi Zero weight & power consumption

Measured weight:

Raspberry Pi Zero + SD card 8.8 grams
Raspberry Pi Zero + SD card + pin header 11.8 grams
Raspberry Pi Zero + SD card + USB wlan adapter (Asus USB-N10 without covers) 11.9 grams

Measured power consumption at 3.3V fed directly to header:

150mA without USB devices
350mA with Asus N10 during ping in weak network connection

Raspberry Pi camera still capture & HTTP upload

Write a bash script on Raspberry Pi:

raspistill -o vattu.jpg
curl --form "fileupload=@vattu.jpg"

and PHP at server side to process the upload:

$userfile_name = $_FILES['fileupload']['tmp_name'];

if (move_uploaded_file($_FILES['fileupload']['tmp_name'], "vattu.jpg"))
echo "ok";

Eagle PCB CAD BMP import

Confused how to make your BMP correct sized when converting it with import-bmp?

First of all:
– Make your image 2 colored BMP, great tool for Windows, Linux and OS X is the old classic XnView – For colored images I suggest dithering the image to 2 colored image
Make your graphics as library package (in Eagle), trust me, it’s worth it (you can make changes easily and don’t mess up your board since the graphic is a package)
– Use layer 25 (tNames) for your graphics. When you have added the package to your board, you can change it’s side by mirroring it.

Then the secret formula:

Scale factor for pixel = wanted graphic size / image size in pixels

For example if you want 204 pixel wide image to be 10mm, you enter 0.0490196078 as the scale. (10 / 204 = 0,0490196078).

Technology snippets