Composite video PCB working

Last Updated or created 2022-11-08

UPDATE 20221108

Soldered the components on the print
No more sync issues! (see post https://www.henriaanstoot.nl/2022/10/19/composite-video-with-atmega328p/ )

There are some duplicate characters, the input device below does not have a proper debounce method.

My temporary input device (note hex 21 is a “!” character)

No need to fix the debounce, the dipswitches are temporary. This will be controlled by the VIA 6522 chip.

UPDATE 20221108 (Connected to second VIA)

PORTB = $5000
PORTA = $5001
DDRB = $5002
DDRA = $5003
clock = $e0

E  = %10000000
RW = %01000000
RS = %00000000

  .org $0200

reset:
  ldx #$ff
  txs

  lda #%11111111 ; Set all pins on port B to output
  sta DDRB
  lda #%10000000 ; Set top pin on port A to output
  sta DDRA
  lda #$00  ; reset bit
  sta PORTA
  sta clock

  ldx #0
print:
  lda message,x
  beq printborder
  jsr print_char
  inx
  jmp print

loop:
  jmp loop

message:
        .db 0x01,0x04,0x0C,0x0E,0x10,0x0F,0x08
        .db 0x05,0x0a,0x0a
        .db 0x05,0x0b,0x0b
        .asc "Composite Video 6502 - 20221108"
        .db 0x0E,0x11,0x0F,0x0C
        .asciiz " With 2 pixels "

waitloop:
  pha
  tya
  pha
  ldy #$ff
back:
  dey
  bne back
  pla
  tay
  pla
  rts

print_char:
  sta PORTB
  jsr waitloop
  jsr waitloop
  lda clock
  eor #%10000000
  sta clock
  sta PORTA
  jsr waitloop
  lda clock
  eor #%10000000
  sta PORTA
  jsr waitloop
  rts

Control codes as from : http://searle.x10host.com/MonitorKeyboard/index.html

Video display control codes:
Hex (Decimal) and meaning
01 (01) - Cursor home (Standard ASCII)
02 (02) - Define cursor character (2nd byte is the curs character, or 00 to turn off) <--New for 3.0
03 (03) - Cursor blinking
04 (04) - Cursor solid
05 (05) - Set graphics pixel (next two bytes = x,y) <--New for 3.0
06 (06) - Reset graphics pixel (next two bytes = x,y) <--New for 3.0
08 (08) - Backspace (Standard ASCII)
09 (09) - Tab (Standard ASCII)
0A (11) - Linefeed (Standard ASCII)
0C (12) - Clear screen (Standard ASCII)
0D (13) - Carriage return (Standard ASCII)
0E (14) - Set column 0 to 79 (2nd byte is the column number) or 0 to 39 for a 40 char line
0F (16) - Set row 0 to 24 (2nd byte is the row number)
10 (16) - Delete start of line
11 (17) - Delete to end of line
12 (18) - Delete to start of screen
13 (19) - Delete to end of screen
14 (20) - Scroll up
15 (21) - Scroll down
16 (22) - Scroll left
17 (23) - Scroll right
18 (24) - Set font attribute for the current line (see elsewhere on this page for details) <--New for 3.0
1A (26) - Treat next byte as a character (to allow PC DOS char codes 1 to 31 to be displayed on screen)
1B (27) - ESC - reserved for ANSI sequences
1C (28) - Cursor right
1D (29) - Cursor Left
1E (30) - Cursor up
1F (31) - Cursor down
20 (32) to 7E (126) - Standard ASCII codes
7F (127) - Delete
80 (128) to FF (255) - PC (DOS) extended characters

Home Assistant/NodeRed update

Last Updated or created 2022-11-12

Upgraded the 2nd (Main) nodered machine to 3.0
Now the node-red-contrib-home-assistant-websocket nodes work again.

Also updated HA, and added some iframes using below.
The HA update broke my mqtt lighting due to changes in the code.

Below also in the example some iframe entries.
( When adding grafana, you need to change grafana.ini

allow_embedding = true

mqtt:
 broker: mqttbrokerserver <--- still errors on this part, 
 discovery: true   <--- but where to configure?
 light:                             <--- Moved this under mqtt
  - name: "KitchenOutside"          <--- added a dash
    payload_on: "99"
    payload_off: "0"
    unique_id: "KitchenOutside"
    brightness_scale: "99"
    brightness_state_topic: ha433/kitchenoutside/brightcontrol
    brightness_command_topic: ha433/kitchenoutside/brightcontrol
    state_topic: ha433/kitchenoutside/brightcontrol
    command_topic: ha433/kitchenoutside/control
    optimistic: false
    on_command_type: brightness

panel_iframe:                     <--- iframes added
  nodered:
    title: "NodeRed"
    url: "http://noderedserver:1880/"
    icon: si:nodered
    require_admin: true
  domoticz:
    title: "Domoticz"
    url: "http://domoticzserver:8080/"
    icon: si:homeadvisor
    require_admin: true
    
influxdb:
    host: influxserver
    port: 8086
    database: homeassistant
    max_retries: 3
    default_measurement: state <--- changed this
    

HomeAssistant add long-lived access token:

  • Click you profile icon bottom right
  • Scroll all the way down and press create token

Node-red

Add a HA node to a flow, double click and add a server with the little pencil

Base URL is important, you can’t just add http://internalip:port
Use a the URL configured in HA (config/network)

Hidden remotes

Last Updated or created 2022-11-05

While having a lot automated, and controllable via apps, we sometimes need the remotes (TV/Chromecast/Mediacenter/etc)

They are always … gone, lost.

So i made a little wooden thingamajig, which is hidden behind our couch.
Maybe an idea also useful for you?

The gap between, the couch and the wall is there because of airflow and the skirting boards.

When looking from a normal perspective, you can’t see them.
(I still have to paint them in the same color as our wall)

In the wooden compartments is some bubble wrap plastic.
It has long “feet” so i can position it anywhere.

On the sides are power outlets for laptops, and usb charging cables.

Automating the h*ll out of windows applications using linux

Last Updated or created 2023-02-07

I’m using a windows program for typesetting bagpipe music.
Luckily this runs on Linux using wine.

Sometimes i just want a PDF version of a tune, for example for my tunebook compiler. (Other post)
Or i want to batch convert a lot of bww files.

A long time ago i used a virtual machine with automation software for this.
Why not automate the process on my Laptop?

So i made this script, with a workaround for the xdotool wine problem.
(wine window needs to be active to accept key strokes, other linux xwindows you can use the ID of the window)

#!/bin/bash
# use c for close at the end, without c bgplayer wont be shut down
# bww2pdf path/to/music.bww c
# make tmp file
cat "$1" > /tmp/deze.bww
# start bgplayer if not started .. if not started wait 3 secs
slp=0
pgrep BGPlayer.exe >/dev/null || slp=3
pgrep BGPlayer.exe  >/dev/null|| ( nohup wine ~/.wine/dosdevices/c\:/Program\ Files\ \(x86\)/Bagpipe\ Player/BGPlayer.exe & )
sleep $slp
# get program id
pid=$(pgrep BGPlayer.exe)
# get xwindow id using pid
winid=$(xdotool search --limit 1 --all --pid $pid)
# activate window
xdotool search --desktop 0 --class "BGPlayer.exe" windowactivate
# open file menu and Open file
xdotool key --window $winid "alt+f"
xdotool key --window $winid "o"
# give program time to execute
sleep 1
# open our tmp file
xdotool type '\tmp\deze.bww'
xdotool key KP_Enter
sleep 2
# open file menu select Print and PDF as output
xdotool key "alt+f"
xdotool key "p"
xdotool key "P"
sleep 2
# execute
xdotool key KP_Enter
sleep 1
# File close
xdotool key "alt+f"
xdotool key "c"
sleep 2
# close program when c was added to commandline
mv ~/PDF/deze* "$1.pdf"
if [ "$2" == "c" ] ; then 
	xdotool key "alt+f"
	xdotool key "x"
fi
I’m not touching the keyboard when the program is running, all handled by the script

Prints from China

Last Updated or created 2022-11-04

A few weeks ago i designed a print using Kicad.

Today they have arrived!

Now I have to wait a little more .. A 74HTC166 and a straightup RCA connector.

I the past, a long time ago i made my own single side pcb’s using acids.
A messy job, often gone wrong.

Old skool example https://www.youtube.com/watch?v=_PwCp3A3RSk

Or https://www.circuitsonline.net/artikelen/view/1/print

Home Assistant and 433 Dimmers

Last Updated or created 2022-11-17

Getting 433Mhz dimmers working under HA is a pain in the *ss.

After moving my Rfxcom from domoticz to HA, there was still no good way to add dimmers.
I’ve tried adding switches and migrating them to lights, but it didn’t work.

So i took another approach.

Domoticz has a good 433 to mqtt plugin. So i used NodeRed to talk to HA and Domoticz via MQTT.

Rfxcom 433Mhz

Domoticz

MQTT gateway setup

Home Assistant

/config/configuration.yaml

light:    
  - platform: mqtt
    name: "KitchenOutside"
    payload_on: "99"
    payload_off: "0"
    unique_id: "KitchenOutside"
    brightness_scale: "99"
    brightness_state_topic: ha433/kitchenoutside/brightcontrol
    brightness_command_topic: ha433/kitchenoutside/brightcontrol
    state_topic: ha433/kitchenoutside/brightcontrol
    command_topic: ha433/kitchenoutside/control
    optimistic: false
    on_command_type: brightness
  - platform: mqtt
    name: "Living5Spots"
    payload_on: "30"
    payload_off: "0"
    unique_id: "Living5Spots"
    brightness_scale: "30"
    brightness_state_topic: ha433/Living5Spots/brightcontrol
    brightness_command_topic: ha433/Living5Spots/brightcontrol
    state_topic: ha433/Living5Spots/brightcontrol
    command_topic: ha433/Living5Spots/control
    optimistic: false
    on_command_type: brightness

Node Red

Flow

Node-RED Deploy
Search flows
Node	
"d4aab6722750908c"
Type	function
show more 
Export nodes
Export
[
    {
        "id": "31dba0859e04acb4",
        "type": "mqtt in",
        "z": "a49c5bcd66c12a46",
        "name": "",
        "topic": "ha433/kitchenoutside/brightcontrol",
        "qos": "2",
        "datatype": "auto",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 330,
        "y": 160,
        "wires": [
            [
                "e2501f2b6e2ab43d"
            ]
        ]
    },
    {
        "id": "e2501f2b6e2ab43d",
        "type": "function",
        "z": "a49c5bcd66c12a46",
        "name": "Dimmer function",
        "func": "var idx = 9735;\nvar bright = msg.payload;\nmsg.payload = {};\nmsg.payload = {\"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"Set Level\", \"level\": bright};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 160,
        "wires": [
            [
                "5f0314b0950d24c0"
            ]
        ]
    },
    {
        "id": "5f0314b0950d24c0",
        "type": "mqtt out",
        "z": "a49c5bcd66c12a46",
        "name": "",
        "topic": "domoticz2/in",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 970,
        "y": 160,
        "wires": []
    },
    {
        "id": "95eb4d0ed97fdefb",
        "type": "mqtt in",
        "z": "a49c5bcd66c12a46",
        "name": "",
        "topic": "ha433/kitchenoutside/control",
        "qos": "2",
        "datatype": "auto",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 320,
        "y": 220,
        "wires": [
            [
                "d4aab6722750908c"
            ]
        ]
    },
    {
        "id": "d4aab6722750908c",
        "type": "function",
        "z": "a49c5bcd66c12a46",
        "name": "Off function",
        "func": "var idx = 9735;\nvar bright = 0;\nmsg.payload = {};\nmsg.payload = {\"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"Set Level\", \"level\": bright};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 670,
        "y": 220,
        "wires": [
            [
                "5f0314b0950d24c0"
            ]
        ]
    },
    {
        "id": "8c74c5f6.9a7a48",
        "type": "mqtt-broker",
        "name": "mqttserver",
        "broker": "mqttserver",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "15",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]
Mqtt Broker output

So …. this works, and i have now a generic mqtt “router”

Update: Below works now

Streaming, recording, videocall and more

Last Updated or created 2022-11-25

I use a bunch of different tools to create video’s or stream stuff.
Below is some info about those tools.

Software:

  • Kdenlive – Linear video editor (Adding text, transitions, etc)
  • VLC media player – For example to embed video in OBS
  • OBS – Opensource Broadcast software, i use this also to record my screen – You can use this as a virtual webcam, so you can fool around with the image.
  • Audacity – For editing audio
  • QPrompt – Teleprompter

For OBS i made a shortcut/macro keyboard thingy. Based on an arduino pro mini. (Which can connect to a computer acting like a HID, for example a keyboard or mouse)
I use this one to emulate keystrokes which i’ve configured in OBS to do:

  • Switch to scene 1
  • Switch to scene 2
  • Transition from scene to scene
  • Start streaming
  • Start recording
  • Mute
  • [empty] – sometimes used as “start virtual webcam”
  • Slow transition
  • Blank screen
  • Display overlay text

(Originally i planned to do this with a Nextion Display)

Mobile Phone holder, like a third hand

Sometimes a Nikon on a tripod is better.

I don’t have a dedicated webcam for my battlestation. So i mainly use a Actioncam (4k) which can be connected via USB. Or i use a Nikon together with the Camlink.

So i record using my mobile, webcam, screen record
Edit using Audacity and Kdenlive.

When recording with OBS i use MP4 as a container, this is a no-brainer to embed in websites. Use mkv when recording long shots, or when connections can break. (A mp4 will be corrupted)

ffmpeg -i streamrecord.mkv -codec copy putinmp4container.mp4

I’ve played around with StreamFX which gives you some nice extra tools.
(There are loads of plugins to download)
Using websockets is on my todolist.

A little OBS trick without green screen

StreamFX example

Working on a blender animation.
Realtime screen grab, which gets 3D placed in a scene.