Tag Archives: raspberry

Playing with lasercutter steppermotors

Busy day: I’ve airbrushed some 3D pieces a few days ago, but i need 50 or so more.
Meanwhile is was reinstalling octoprint, and making a new version of my Bluetooth page flipper. (Android Music Sheet Pedal Thingy. Which i also didn’t post apparently)
But the main project was this:

I was curious how fast the stepper motors are on my laser cutter. And for what can we utilize this!

So I took a Raspberry Zero and some rotary encoders, lets make an etch-a-sketch like thingy.

Some rotary encoder modules I had.

Next to do: 3D print a pen holder, and alter the code to enable the laser when moving!


Below code uses a simple rotary class, and generates control GCodes for the steppers/Sculpfun

import time
import serial
import RPi.GPIO as GPIO
from encoder import Encoder

def valueChanged(value, direction):
    print("* New value: {}, Direction: {}".format(value, direction))


e1 = Encoder(20, 21, valueChanged)
e2 = Encoder(16, 12, valueChanged)

x = 0
y = 0
arduino = serial.Serial('/dev/ttyUSB0', 115200, timeout=.1)

newx = 0
mystringx = ""
newy = 0
mystringy = ""

arduino.write(str.encode("G00 G17 G40 G21 G54\r\n"))
arduino.write(str.encode('G0 X41.5Y36.05\r\n'))
arduino.write(str.encode('G1 X2.5F6000S0\r\n'))
arduino.write(str.encode('G1 X0\r\n'))
arduino.write(str.encode('G1 Y0\r\n'))

    while True:
        data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
        if data:
                print (data)
        arduino.write(str.encode("G1 F10000\r\n"))
        newx=e1.getValue() *5 + 100
        newy=e2.getValue() *5 + 100
        mystringx=f"G1 X{newx}\r\n"
        mystringy=f"G1 Y{newy}\r\n"
#        print(mystringx)

except Exception:


Mobile Raspberry Access Point with Mqtt and a display

UPDATE: 20230214 / 20230224

Install Bullseye on a SDCard

Enable wifi country code using raspi-conf
(While you at it, enable I2C for the display)

Install and configure an Access Point

# As root
apt update
apt upgrade
apt install hostapd
apt install dnsmasq
systemctl stop hostapd
systemctl stop dnsmasq

cat <<EOF > /etc/hostapd/hostapd.conf

cat <<EOF >> /etc/dnsmasq.conf

cat <<EOF >> /etc/dhcpcd.conf
interface wlan0
nohook wpa_supplicant
static ip_address=
static routers=
static domain_name_servers=

sed -i s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g /etc/sysctl.conf

mkdir /etc/nftables
cat <<EOF > /etc/nftables/nft-stat-ap.nft
flush ruleset

table inet ap {
        chain routethrough {
                type nat hook postrouting priority filter; policy accept;
                oifname "eth0" masquerade

        chain fward {
                type filter hook forward priority filter; policy accept;
                iifname "eth0" oifname "wlan0" ct state established,related accept
                iifname "wlan0" oifname "eth0" accept

chmod +x /etc/nftables/nft-stat-ap.nft
cat /etc/nftables.conf | grep nft-stat-ap.nft || echo 'include "/etc/nftables/nft-stat-ap.nft"' >> /etc/nftables.conf

systemctl unmask hostapd
systemctl enable hostapd
systemctl enable nftables


UPDATE: 20230214

Now in its case, added two buttons and one led.

UPDATE : 20230224 mqtt config

apt-get install mosquitto mosquitto-clients

vi /etc/mosquitto/conf.d/remotemqtt.conf
per_listener_settings true
# internal mqtt
listener 1883
allow_anonymous true
# connection over the internet
connection bridge-01
address remoteserver:8883
bridge_cafile /etc/mosquitto/certs/ca.crt
bridge_keyfile /etc/mosquitto/certs/remoteaccesspoint.key
bridge_certfile /etc/mosquitto/certs/remoteaccesspoint.crt
topic escape/# both 0
remote_username remoteuser
remote_password remotepass

########## remote server config

cd /etc/mosquitto
mosquitto_passwd passwords remoteuser

cd /etc/mosquitto/certs
./generate-CA.sh client remoteaccesspoint

copy ca.crt remoteaccesspoint.key and remoteaccesspoint.crt to accesspoint

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
#per_listener_settings true
# Plain MQTT protocol
listener 1883
allow_anonymous true
# End of plain MQTT configuration
listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/webserver.fash.lab.crt
keyfile /etc/mosquitto/certs/webserver.fash.lab.key
allow_anonymous false
password_file /etc/mosquitto/passwords
# End of MQTT over TLS/SLL configuration
listener 9001
protocol websockets
# End of plain Websockets configuration
# WebSockets over TLS/SSL
listener 9883
protocol websockets
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/webserver.fash.lab.crt
keyfile /etc/mosquitto/certs/webserver.fash.lab.key
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
connection bridge-01
address extramqttserver:1883
topic lscspm1/# both 0
topic owntracks/# both 0
topic escape/# both 0

log_type all

Controlling Display and MQTT messages examples

apt-get install python3-smbus

python3 printline.py -1 "line 1" -2 "line 2"

wget https://github.com/emcniece/rpi-lcd/blob/master/RPi_I2C_driver.py

cat printline.py
# requires RPi_I2C_driver.py
import RPi_I2C_driver
from time import *
import sys, getopt

#python3 fix
unichr = chr 

mylcd = RPi_I2C_driver.lcd()
# test 2                  1234567812345678

def main(argv):
   line1 = ''
   line2 = ''
      opts, args = getopt.getopt(argv,"h1:2:",["txt1=","txt2="])
   except getopt.GetoptError:
      print ('printline.py -1 <line1> -2 <line2>')
   for opt, arg in opts:
      if opt == '-h':
         print ('printline.py -1 <line1> -2 <line2>')
      elif opt in ("-1", "--txt1"):
         line1 = arg
      elif opt in ("-2", "--txt2"):
         line2 = arg

   mylcd.lcd_display_string(line1, 1)
   mylcd.lcd_display_string(line2, 2)
if __name__ == "__main__":

Print internal and external ip

myip=$(/usr/sbin/ifconfig eth0 | grep "inet " | awk '{ print $2 }')
extip=$(curl -s http://whatismyip.akamai.com/)
python3 printline.py -1 "i $myip" -2 "e $extip"

mosquitto health tester

timeout 1 mosquitto_sub -t '$SYS/#' -C 1 | grep -v Error || exit 1

Button press shutdown

raspi-gpio get 27  | grep level=0 >/dev/null 
if [ $? == 0 ] ; then

python3 printline.py -1 "shutting" -2 "down"
/usr/sbin/halt -p

Cleaned-up minimal mqtt poster

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssidname";
const char* password = "ssidpass";
const char* mqttServer = "";

WiFiClient espClient;
PubSubClient client(espClient);

void initWiFi() {
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {

void setup() {
  Serial.print("RRSI: ");
 if (client.connect("testmodule")) {

 client.publish("escape/testclient", "connected");
    } else {
            Serial.println("Mqtt not connected");


void loop() {


Wanted to make a mini Sid Player, and failed

I’ve got an old Speaker Phat, and a Raspberry Zero

An audio add-on board for Raspberry ( same size as the Zero )

My initial idea was to have the “High Voltage Sid Collection” (Downloaded the 55000 pack)
On a mini device, battery operated and with a little keypad.

On the keypad i can select the Sidtune to play, or pressing
A and a number the Sids from a certain artist.

The display gives you information about the tune being played.
( The display has an I2C hat to convert 8bits to I2C )

See pinout phat above.
I’ve got three choices for I2C connection (green/blue to the Phat)

  • Direct connect and use different addresses
  • Use a I2C hub and different addresses
  • Define a secondary I2C on the raspberry

So I made the first test setup …

Underrun occurred .. So back to the drawingboard.
I probably need a better Audio Hat.
First to try .. Zero fast enough for sidplay2?
Maybe audio over hdmi works??

Shelly Flood Sensor

I’ve had this Shelly sensor for a long time. But never posted anything about this.
Last weekend we had a -situation- in our kitchen, so what better time to test this device again!

This little disc shaped device has three metal points on its bottom side, those are the flood (water) sensors.
It stay’s in sleep mode when all’s good.
It does several things when it detects water.

  • Emits a alarm signal
  • Wakes-up wifi
    • Sends a MQTT message (when not connected to the cloud like i have)
      MQTT is a alarm message AND it wil send the temperature of the device!
  • After a while (when dry) goes back to sleep

There are connection point on the print you can use .. happy hacking!

My node-red configuration

Above is the part where the mqtt messages gets processed by Node-Red
Sending it to PushOver and my little MqttLcdNotifier

Above is the MqttLcdNotifer .. there are several parts to this

  • Top line is from shelly flood and other notifications
  • Text input puts text from the NR GUI on my TV and the LCDDisplay
    • same parts are being used by my 3D printer when the print tool is getting TO hot, or printing is finished
  • Trigger at work WAS a notification for work .. nonfunc
  • mqttlcd-button is the mqtt message send from the display (the one that i was pushing) to stop the beeping and clears the display
  • Bash notify, is as previously posted a flow which i can control from my linux machines notify “compiling complete” for example.
    This is also being broadcast from my livingroom using speakers.
    (See separate post about this)

Wellll, put this in place 2 years ago, never looked at it again .. still works

Volume is low, due to alarm sounds 🙂

Generic matrix keyboard

In this case designed for my 6502, but it is a generic setup.

I it just a dual 16key matrix decoder merged together. You can probably use this with raspberries, arduinos etc.

I wanted to use 74C923 but these are nowhere to be found. And even then, the number of keys wil be 20.
So i am tying together two 74C922 using some logic in a PLD.

First draft

It wil be something like above. Using the data availabe signal i can combine both 16key matrixes. (In theory .. it is all untested)

PLD Code

Address Decoder

PHI2 DA0 DA1 D01 D02 D03 D04 D11 D12 D13 D14 GND

DA = DA0 + DA1
D0 = D01 & DA0 + D11 & DA1
D1 = D02 & DA0 + D12 & DA1
D2 = D03 & DA0 + D13 & DA1
D3 = D04 & DA0 + D14 & DA1
D4 = DA1 

Key matrix merger

I’ve got my new keys of the keyboard in today!

  • 0-F – hex keys
  • G = Go
  • R = Reset
  • S = Step
  • M = Memory
  • Cursor keys (up/down for memory locations)
  • ??? I’ve got room for 8 more keys

My inkscape template (keys are 10/10mm)

Printed on white and red paper


MCH2022 Badge

Almost … friday will be the day i’ll attend May Contain Hackers.
Besides the awesome villages and talks.

UPDATE: 20220727
UPDATE: 20220812

You get a hackable badge, this one is more amazing as previous versions.

I can’t wait to have a go at this cool gadget. I personally could do without the pcb fancy design.

  • Espressif ESP32 Wrover-E with 16MB of flash storage and paired with 8MB of PSRAM, for front-end badge computing and compatibility with the badge.team ecosystem back to the 2017 SHA badge.
  • Lattice ICE40UP5K FPGA for hardware-accelerated graphics and user FPGA hardware designs.
  • Raspberry Pi RP2040 for advanced USB communication and board management.
  • 2Ah LiPo battery to give you a full day of fun on a charge.
  • 16-bit DAC with stereo output to headphone socket, onboard mono speaker.
  • ILI9341 2.2 inch TFT display with a 240 by 320 pixel resolution.
  • Bosch BNO055 orientation sensor.
  • Bosch BME680 environmental sensor.
  • The usual array of addressable LEDs.
  • SAO and Qwiic expansion connectors, FPGA PMOD expansion, plus onboard prototyping area.

Downloadable apps, micro python, Arduino ide programming.
All kinds of GPIO pins, leds buttons, sound.
Check out https://hatchery.badge.team/

You can play with this virtually here!

So much potential! Great start for a DIY project.

I won’t post about the workings, thats all well documented online.
I shall post about the hacks/findings i personally did.

UPDATE: 20220727
Made a micropython program to keep your NameTag level to the ground (Better version)

UPDATE: 20220812

Someone made a 8bit logic analyser using the pmod connector !

Mini C64 for MCH2022

Cool little C64 gadget for MCH2022

Next week i’ll be going to May Contain Hackers 2022, what to bring?
My old friend Bigred will be there, many others couldn’t make it …

What to bring and do:

  • Laptops
  • Arduino touch project?
  • My new 6502 breadboard computer?
  • The DVB-T / DAB / FM stick
  • Besides the emulators on my laptop, maybe i’ll bring this little thing
    (Or a real C64?)

Booting in 4 seconds!
Running Vice in 50 or 60 Hz
Low latency video!
Can emulate cartrides, floppy’s
When you connect joysticks or a real C64 keyboard to the GPIO pins it will use that.
SID sound using ReSid
CRT emulation
(look for BMC64 or combian)

Screens and DIY projects

Below some examples and connection diagrams to control displays.
More code and complete schematics will be added on this page or on a separate projects page.

UPDATE 20230119 Cost of 20×4 display in 1998


I’ve used a LCD display like this (HITACHI HD44780) on my PC in the 90s, and also written code to use this as a monitoring device on my amiga.

On Linux i used LcdProc – This module also was equiped with a serial connector
Now (2023) it is 8 euros!
;LCD Display Module             Parallel port
;        1 Vss                  20 GND
;        2 Vdd                  14 +5V
;        3 Vlc                  20 GND (contrast LCD display)
;        4 RS (register select) 11 BUSY
;        5 R/W                  12 POUT
;        6 E (enable)           13 SEL
;        7 DB0                   2 D0
;        8 DB1                   3 D1
;        9 DB2                   4 D2
;       10 DB3                   5 D3
;       11 DB4                   6 D4
;       12 DB5                   7 D5
;       13 DB6                   8 D6
;       14 DB7                   9 D7
Amiga code part
        bsr     initprt         ; CIA 8520 init
        bsr     initlcd         ; init lcd display module
        move.l  #0,d0

initprt:move.b  #$ff,$bfe301    ; parallel port is output
        move.b  $bfd200,d0
        ori.b   #$07,d0         ; select, p-out and busy
        move.b  d0,$bfd200      

initlcd:move.w  #$38,d0         ; multiple reset
        bsr     send
        bsr     delay2
        move.w  #$38,d0
        bsr     send
        bsr     delay2
        move.w  #$38,d0         ; 2*8 lines
        bsr     send
        bsr     delay2
        move.w  #$01,d0         ; clear display
        bsr     send
        bsr     delay2          ; wait
        move.w  #$0c,d0         ; display on
        bsr     send
        move.w  #$06,d0         ; Entry Mode Set
        bsr     send

send:   bsr     delay
        btst    #8,d0           ; test rs bit
        beq     reg0
        bsr     rs1             ; select register 1
        bra     skip
reg0:   bsr     rs0             ; select register 0
        bsr     delay
        bsr     rw0             ; read/write=0 
        bsr     delay
        bsr     e1              ; enable = 1
        bsr     delay
        move.b  d0,$bfe101      ; push data
        bsr     delay
        bsr     e0              
        bsr     delay

delay:  move.w  #$20,d1
dloop:  subi    #1,d1
        bne     dloop

delay2: move.w  #$800,d1
dloop2: subi    #1,d1
        bne     dloop2
Part of my MQTT display alarm thingy
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>  
LiquidCrystal_I2C lcd(0x27, 20, 4);
const char* ssid = "MYACCESSPOINT";
const char* password = "MYPASSWORD";
const char* mqtt_server = "mymqttserver";
const byte ledRed = 12;
const byte horn = 13;
int button = 2;
int press = 0;
boolean buttonToggle = true;


WiFiClient espClient;
PubSubClient client(espClient);
bool toggle = false;
void setup_wifi() {

  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

void callback(char* topic, byte* payload, unsigned int length)
  if (length > 0) {
    toggle = true;

  if (length == 0) {
    toggle = false;

  Serial.print("Command from MQTT broker is : [");

  Serial.print(" publish data is:");
  lcd.backlight(); // turn off backlight

    for (int i = 0; i < length; i++)
      if (i < 16){
      lcd.setCursor(0, 0);
      lcd.setCursor(i, 0);
      } else {
      lcd.setCursor(0, 1);
      lcd.setCursor(i-16, 1);


void reconnect() {
  while (!client.connected())
    Serial.print("Attempting MQTT connection...");
    String clientId = "mqttlcd";
    clientId += String(random(0xffff), HEX);

    if (client.connect(clientId.c_str()))

    } else {
      Serial.print("failed, rc=");
      Serial.println(" try again in 5 seconds");

void setup() {
  pinMode(button, INPUT);
  digitalWrite(2, HIGH);
  pinMode(ledRed, OUTPUT);
  digitalWrite(ledRed, LOW);
  pinMode(horn, OUTPUT);
  digitalWrite(horn, LOW);
  client.setServer(mqtt_server, 1883);

void loop() {

  if (!client.connected()) {
  if (toggle == true) {
    digitalWrite(ledRed, HIGH);
    digitalWrite(horn, HIGH);
    digitalWrite(ledRed, LOW);
    digitalWrite(horn, LOW);
  if (toggle == false) {
    digitalWrite(ledRed, LOW);
    digitalWrite(horn, LOW);



  press = digitalRead(button);
  if (press == LOW)
    if (buttonToggle)
      digitalWrite(ledRed, HIGH);
      digitalWrite(horn, HIGH);
      buttonToggle = !buttonToggle;
      digitalWrite(ledRed, LOW); 
      digitalWrite(horn, LOW);
      buttonToggle = !buttonToggle;
      toggle = false;
      lcd.noBacklight(); // turn off backlight
  delay(500);  //delay for debounce


There are several oled displays, mostly controllable with i2c but some of them are SPI

SSD1306 – I2c connected

Using a wemos – Octoprint project for example
Octoprint (Note: this is NOT a multicolor display 1/4 of the display is yellow. )
My notification watch. Runs on a ESP12F connects to Wifi, has a piezo sound element
Using a raspberry (Part of my Lab Sensors Project)
pip3 install adafruit-circuitpython-ssd1306
git clone https://github.com/adafruit/Adafruit_Python_SSD1306 (old)
Edit file - comment SPI section

Some arduino’s have embedded displays like those i’ve used for a Lora project.

Other means of connecting : SPI

SPI connected display


Nextion is a Human Machine Interface (HMI) solution combining an onboard processor and memory touch display with Nextion Editor software for HMI GUI project development.

Using the Nextion Editor software, you can quickly develop the HMI GUI by drag-and-drop components (graphics, text, button, slider, etc.) and ASCII text-based instructions for coding how components interact on the display side.

Nextion HMI display connects to peripheral MCU via TTL Serial (5V, TX, RX, GND) to provide event notifications that peripheral MCU can act on, the peripheral MCU can easily update progress, and status back to Nextion display utilizing simple ASCII text-based instructions.

My nextion domoticz box, tilt to wakeup
Domoticz controller

My biltong box using a Nextion

Raspberry displays

 3.5inch RPi Display – 480×320 Pixel – XPT2046 Touch Controller
edit cmdline.txt
add "fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo"
at the end
edit config.txt
add between custom comments at the bottom
# Or check http://www.lcdwiki.com/3.5inch_RPi_Display

Above display’s i’ve used for Picore Players and the Lidar POC

To try: Getting above display running with a arduino

Raspberry HDMI display

Easiest of them all, just connect with HDMI, there is a adaptor for hdmi-hdmi (versions 1,2,3) and hdmi-mini-hdmi for RPi4 variants.

Epaper and 7-Segment displays

Other means of displaying information are for example


ESP with epaper module, disconnected power for a while, artifacts appear.

7 Segment displays

I used a lot of 7-Segment display’s in the past. They look cool and are hardcore.

My homebrew computer uses this

Nixie tubes!

And there are https://en.wikipedia.org/wiki/Nixie_tube .. I’ve never had those

Above bigger 2D display i used with Wled and a digital microphone, so its sound reactive. The lower part i got in recently .

inmp441 digital microphone

Using OSB to record screens

While you can use screencapture to record virtual machines, to real machines it is a different story.

Virtual machines running locally or remote can be accessed with spice/vnc or rdesktop.
So you have a window displaying the remote screen, which you can capture using window capture.

There are also emulators which you can window-capture. But i want the real thing when available. Emulators give a too crisp screen output. And you want to have the real SID chip sound.

Hardware capturing:

I’ve got two capturing usb sticks:

Camlink 4K for hdmi capturing (Which i use mainly for my nikon)

Basetech BR116 RCA and S-Video capture (NTSC 720 x 480 , 30 FPS/PAL 720 x 576 , 25 FPS)

Devices and recording:

  • C64 – Use Basetech, and the DIN to RCA cable
  • Vic-20 – same as above
  • Raspberry – Use a HDMI and Camlink
  • Amiga – I use the basetech and grab the composite signal from the Scart connector, another solution is to use a A520 Modulator, which has Composite out. (There are schematics on the internet to connect hdmi to your amiga)
Amiga A520 Modulator

The 520 Modulator connects to the amiga using a DB23 connector, and a Y cable for the 2 rca audio jacks.
It outputs a composite video signal, and RF modulated signal to connect to a old Tube/Crt monitor

When recording video from those screens, i configure my OBS file format to MP4. This makes it easier to embed into websites. Only downside on writing to MP4 instead of mkv is the fact that the file probably isn’t recoverable when something crashes.

Audio capturing :

When capturing your movie don’t forget to add a audio source to your OBS sources.
Use Audio input capture, or you can use Audio output capture when sound is playing by your system.

Demo a friend made using a demomaker (Music starts half way)

Flightsim on a Amiga (See more on flightsims)
C64 Hellraiser (part 1) no de-comb/de-interlace filter

Note: check your output/cables

Portable Logitech Media Server again

See post: https://www.henriaanstoot.nl/2014/04/10/portable-squeeze-server/

In the past i’ve used a home build Logitech Squeezebox server (as it was called then), Picore player and tried volumio.
Picore player has been sitting in my livingroom for ages, but was converted to a Node-Red Dashboard and recently Home Assistant Dashboard. (Has been a dasticz daskboard also)

Today i build another version, smaller and with a screen.
Why? .. because of being ‘offline’ or ‘offgrid’ on our holidays.
The car we are driving only has a Aux input.

Most of the installation is as mentioned on:

I edited  /opt/bootsync.sh
to get /dev/sda1 mounted persistent
use pcp br after editing.

Default user/pass : tc piCore

Controlling the thing is via touch or a app on my phone using wifi hotspot.

  • Audio cable 3.5mm
  • Raspberry 3
  • Large usb thumbdrive
  • 3.5inch RPi Display – 480×320 Pixel – XPT2046 Touch Controller
  • car cigarette lighter adapter for power

PiCore uses below alliases

ceChange directory to /mnt/mmcblk0p2/tce
ceoChange directory to /mnt/mmcblk0p2/tce/optional
m1Mount the boot partition /mnt/mmcblk0p1
m2Mount the second partition /mnt/mmcblk0p2
c1Change directory to /mnt/mmcblk0p1
c2Change directory to /mnt/mmcblk0p2
vicfgEdit configuration file config.txt using vi
vicmdEdit boot file cmdline.txt using vi
u1Unmount the boot partition /mnt/mmcblk0p1
u2Unmount the second partition /mnt/mmcblk0p2

Shutting down piCore is done by cutting the power, due to everything being mounted readonly. EXEPT
When you are using LMS server installation, which uses a database.
But there is a tweak for a shutdown button.

I’m using GPIO 16 because i’ve got a screen connected.
Active LOW, means you have to connect a pushbutton/switch between GND and GPIO pin. (nearest Vcc OR Gnd)