Tuesday, July 31 2018

Very simple way of accessing PiTFT 240x320 display from python with cairo

I used to use pygame, but outdated SDL problems resulting in malfunctioning touchscreen forced me to use a different solution. Touchscreen works with python-evdev and I needed graphics. Cairo is the obvious choice for 2D and after a few days of playing with different solutions I came up with this:

#Very simple way of accessing PiTFT 240x320 display from python with cairo

import mmap
import cairo

# 320 * 240 * 2 bytes per pixel = 153600
PiTFT_mem_size = 153600

# Framebuffer file, might be /dev/fb0
fb_fd  = open("/dev/fb1", "r+")

#Map the framebuffer to memory
fb_map = mmap.mmap(fb_fd.fileno(), PiTFT_mem_size)

#Create cairo surface. If you get "Function not implemented" error, you need a newer cairo
surface = cairo.ImageSurface.create_for_data(fb_map, cairo.FORMAT_RGB16_565, 240, 320)

#Create cairo context
cr = cairo.Context(surface)

# Paint the surface black
cr.set_source_rgba (0.0, 0.0, 0.0, 1.);
cr.paint_with_alpha (1.0);

for i in range(0, 10):
    c = i / 10.0
    cr.set_source_rgb (1.0 - c, 1.0 - c, 1.0)
    cr.rectangle(15 * i + 10, 15 * i + 20, 100, 100)
    cr.fill ()

#Close the mapped framebuffer
fb_map.close()

That's how it looks on the piTFT:

piTFT_and_cairo.jpg
piTFT_and_cairo.jpg, Jul 2018

 

Friday, March 31 2017

Open Cycling Computer will be Pi Zero W based

Pi Zero W is the new brain of the Open Cycling Computer. PiTFT 2.8" capacitive dosn't work out-of-the-box, but required modification are very simple.Modifications required in /boot/config.txt1. Uncomment dtparam=spi=on2. Add  […]

Continue reading

Friday, February 10 2017

Lezyna Speed & Cadence sensor: Lezyne S&C 249 and btle.py

$ ./btle.py fd:df:0e:4e:76:cf random Connecting to: fd:df:0e:4e:76:cf, address type: random Service <uuid=Generic Access handleStart=1 handleEnd=7> :     Characteristic <Device Name>, hnd=0x2, supports READ WRITE      -> 'Lezyne S&C 249'     Characteristic <Appearance>,  […]

Continue reading

Sunday, September 13 2015

Nautilus: batch thumbnail generation for remote location

I have a fairly large photo collection on a raspberry pi based NAS. Unfortunately RPI ethernet port is not fast enough (100MB/s) for comfortable remote operation, so to be able to use that collection I have to keep local thumbnail directory on my linux box. Gnome nautilus is my tool of choice, but  […]

Continue reading

Sunday, March 8 2015

Raspberry Pi model A+ high resolution photos and 3D model

Raspberry_Pi_model_A__front.png

Raspberry Pi Model A+  […]

Continue reading

Sunday, February 8 2015

Bluetooth BLE, gatttool and (almost) all those numbers .... explained

It's a short guide to practical side of bluetooth LE using gatttool. How to read characteristics, turn on notifications and where to find more info about all those BLE numbers. I was strugging for a while to read data from a BLE heart rate strap. It was working flawlessly with android apps, but I  […]

Continue reading

Wednesday, December 17 2014

How to make MMA8451 working with raspberry pi over I2C

MMA88451 doesn't work with raspbterry pi out of the box. It needs I2C with repeated start. Test program in python: import smbus DEVICE_ADDRESS = 0x1d MMA8451_REG_WHOAMI = 0x0D bus = smbus.SMBus(1) ret = bus.read_byte_data(DEVICE_ADDRESS, MMA8451_REG_WHOAMI) print ret Shows zero instead of expected  […]

Continue reading

Sunday, December 7 2014

Python library for Raspberry PI for Ultimate GPS based on MTK3339 with serial interface as sold by Adafruit

https://github.com/PrzemoF/mtk3339 Python library for Raspberry PI for Ultimate GPS based on MTK3339 with serial interface as sold by Adafruit. The library helps to set different chip parameters in a sane way. Currently supports minimum functional set of commands: CMD_HOT_START - hot_start()  […]

Continue reading

Wednesday, November 12 2014

Battery backup for Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates - Version 3

I was testing that [1] gps chip for a last few weeks - it was great, but it was preforming "cold start" every time it was turned on. Today I finally soldiered the battery holder and slided a CR1220 battery in. If you're using the same board without the battery get one immediately. Time to  […]

Continue reading

Wednesday, October 15 2014

PiTFT capacitive calibration for vertical layout

pointercal_equation.png

PiTFT capacitive doesn't require calibration according to Adafruit, but for some reason I couldn't make it work properly with vertical layout and the default values suggsted here [1]. The default values are: 320 65536 0 -65536 0 15728640 65536 I needed to use the screen with Adafruit logo at the  […]

Continue reading

Friday, August 22 2014

Bosch BMP183 with SPI by Adafruit in python on Raspberry PI

rpi_a_and_bmp183.jpg

How to measure temperature and pressure with raspberry pi and BMP183 Requirements: - raspberry Pi - BMP183 with SPI by Adafruit - 6 wire female-to-female cable or any other to connect 6 pins between RPI and BMP183 Results: Temperature: 18.9 deg C Pressure: 1013.39 hPa RPI + BMP183: Schematic (png):  […]

Continue reading

Thursday, April 17 2014

i4oled-gui is ready!

Now there is a way of setting OLED icons on Wacom Intuos4 tablets using simple GUI: Your browser does not support the video tag. The source code can be downloaded from GitHub. It requires gnome & dconf, but it doesn't require root access rights as it works by writing to dconf. I hope that some  […]

Continue reading

Tuesday, March 11 2014

OLEDs-over-bluetooth are on the way to gnome

Hopefully soon gnome users will be able to fully utilise OLED displays on wacom Intuos4 wireless tables. More (technical) details here: https://bugzilla.gnome.org/show_bug.cgi?id=724955

Friday, February 28 2014

i4oled v1.2 is out

Version 1.2 of OLED handling tool for Wacom Intuos4 Wireless is out! Most important changes are that now i4oled allows to use base64 encoded strings as input or output and it allows multiple outputs at the same time. The base64 strings can be used with gnome dconf-editor to show an icon instead of  […]

Continue reading

Thursday, February 27 2014

Using Wacom Intuos4 Wireless in unusual way

IMG_20140226_215357.jpg

How to make clock out of your wacom tablet (with OLEDs obviously)? There is one thing required - it's i4oled The "clock" can be set up over usb or bluetooth link. The example below uses bluetooth 1. Connect tablet. 2. Change permissions for OLEDs as we want to use i4oled without root  […]

Continue reading

Monday, February 17 2014

How to change OLED label on Intuos4 tablets on gnome

Screenshot_from_2014-02-17_21_52_17.png

If you have that tablet you probably want to have full control of what is being displayed on those little OLED screens on the tablet. Currently gnome doesn't give option to change it - you just have to accept whatever was generated for you. Or, do you? This is a workaround and I hope in long run we  […]

Continue reading

Tuesday, June 25 2013

i4oled - bluetooth support

Wacom OLEDs ovet bluetooth

i4oled just got bluetooth support. Wacom Intuos4 WL supports 4-bit images over USB connection, but only 1-bit when connected over bluetooth. i4oled now supports both with --bluetooth switch. Example usage: i4oled -d /sys/class/hidraw/hidraw0/device/oled5_img -t "Alt+Ctrl" --bluetooth     […]

Continue reading

Sunday, June 23 2013

Galaxy S4 3D printed car holder

S4 holder

The cradle for S4 is based on an old S2 car holder: All designed using FreeCAD and Blender 3D. S4 holder.blend The model _will_ require some cutting after printing otherwise it won't fit the phone. Additional cutting might be required if battery cover has been replaced.  […]

Continue reading

Friday, May 31 2013

OpenSCAD - first battle

Honeycomb - blender render

My first attempts to use OpenSCAD: module hc_hexagon(size, height) { box_width = size/1.75; for (r = [-60, 0, 60]) rotate([0,0,r]) cube([box_width, size, height], true); } module hc_column(length, height, cell_size, wall_thickness) { no_of_cells = floor(1 + length / (cell_size + wall_thickness)) ;  […]

Continue reading

Friday, April 26 2013

Gnome and Intuos4 OLEDs

Another day, another patch. Gnome will be getting wacom intuos4 OLEDs support. It's going to look like this: Wacom OLEDs in action in gnome More details here: Light up the OLEDsHopefully those patches will land in gnome 3.10. Things that are waiting to be implemented:bluetooth support for status led  […]

Continue reading

- page 1 of 2