Samiad Designs

keep it simple

Breakslights

19th August 2017

I've been working on a compact field deployable lighting effects rig. Based on bike brake discs makes them really tough and easy to attach to ropes and cable ties. They can be daisy chained with a single IP68 connector providing both power and data.

A layer of clay between the WS2812 PCB and the brake disc allows the disc to act as a heatsink.

An incomplete ring on the left and an early prototype on the right.
An incomplete ring on the left and an early prototype on the right.

The control model is loosely based on an audio synthesizer - in the sense that there are various properties to change live that interact to produce different effects.

Screenshot
Screenshot



Small thermal printers commonly used for printing receipts have become more affordable and can be useful for all sorts of projects like interactive exhibits, custom Point Of Sale system or just printing notes.

The ESC/POS specification can be found in this document from EPSON however the functionality actually implemented in each model of printer varies.

This ZJ-5802LD printer from ebay can be connected with USB, serial or Bluetooth and contains a lithium battery allowing printing from mobile phones or tablets in the field.

Output from Example
Output from Example

This example implements all the text functionality of the ZJ-5802LD printer and produces the output shown above. We are connecting the printer using the USB port which is presented as /dev/usb/lp0 in Linux.

In a future post I will cover printing barcodes and images.


#!/usr/bin/env python

NUL = 0x00 # null
LF = 0x0a  # line feed
ESC = 0x1b # escape
GS = 0x1d  # group selector

FONTA = 0x00 # normal
FONTB = 0x01 # small
EMPHASIS = 0x08
DOUBLE_HEIGHT = 0x10
DOUBLE_WIDTH = 0x20
UNDERLINE = 0x80

NORMAL = 0
SMALL = 1

LEFT = 0
CENTRE = 1
RIGHT = 2

def reset(stream):
    stream.write(chr(ESC))
    stream.write("@")

def mode(stream, value):
    stream.write(chr(ESC))
    stream.write("!%s" % chr(value))

def emphasis(stream, value):
    stream.write(chr(ESC))
    stream.write("E%d" % (0, 1)[value])

def underline(stream, value):
    stream.write(chr(ESC))
    stream.write("-%d" % (0, 1)[value])

def font(stream, value):
    assert value >= 0 and value <= 2
    stream.write(chr(ESC))
    stream.write("M%d" % value)

def justification(stream, value):
    assert value >= 0 and value <= 2
    stream.write(chr(ESC))
    stream.write("a%d" % value)

def inverted(stream, value):
    stream.write(chr(GS))
    stream.write("B%d" % (0, 1)[value])

def main():
    stream = open("/dev/usb/lp0", "wb")

    try:
        reset(stream)
        stream.write("normal text\n")

        emphasis(stream, True)
        stream.write("with emphasis\n")
        emphasis(stream, False)

        underline(stream, True)
        stream.write("and underlined\n")
        underline(stream, False)

        font(stream, SMALL)
        stream.write("getting smaller\n")
        font(stream, NORMAL)

        justification(stream, LEFT)
        stream.write("left\n")
        justification(stream, CENTRE)
        stream.write("centre\n")
        justification(stream, RIGHT)
        stream.write("right\n")

        inverted(stream, True)
        stream.write("all inverted\n")
        inverted(stream, False)

        reset(stream)
        mode(stream, DOUBLE_WIDTH | DOUBLE_HEIGHT)
        stream.write("bigger\n")

        stream.flush()

    finally:
        stream.close()

if __name__ == "__main__":
    main()


Raspberry Pi Relay

21st July 2014

I purchased this relay from eBay intending to use it with a Raspberry Pi. I connected this up to 5V, GND and Pin 12 on the Pi and switched pin 12 on and off but nothing happened.

I checked the signal pin with an oscilloscope and it was alternating between 3.3V and 0V expected but the relay (and the LED on the relay board) would not switch.

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)


while True:
    GPIO.setup(12, GPIO.OUT)
    time.sleep(1)
    GPIO.output(12, GPIO.LOW)
    time.sleep(1)

Then I pulled out the signal wire and the relay switched! So the Raspberry Pi has no problems providing the current to drive the relay.


New Boat Design

11th January 2014

This is an early stage of a boat design. It mixes ideas from both kayaks with outriggers and from sailing catamarans. The idea is to make a boat that is good for both paddling and sailing and can be packed up to the size of a very large suitcase.

The two outriggers provide all the buoyancy and the tiny cabin in the middle fits one person with their legs stretched out.

The sparse connection between the cabin and outriggers is to allow decent room for paddling (the red stick).

More details to follow at a later date.