Category Archives: 3dprinting

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!

CODE

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))

GPIO.setmode(GPIO.BCM)

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('G90\r\n'))
arduino.write(str.encode('M4\r\n'))
arduino.write(str.encode('M8\r\n'))
arduino.write(str.encode('G0 X41.5Y36.05\r\n'))
arduino.write(str.encode('M3\r\n'))
#arduino.write(str.encode('G91\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'))

try:
    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)
        arduino.write(str.encode(mystringx))
        arduino.write(str.encode(mystringy))

except Exception:
    pass

GPIO.cleanup()

SG90 servo Arm generator in OpenScad

SG90 Servo
Adjust the arm lenght using the slider, export to STL and print!

Openscad can be found here https://openscad.org/

Openscad source

sliderWithMax =40;  // [80]

	difference() {
		union() {
			linear_extrude(height=1.4)
				difference() {

					hull() {
						circle(d=6,$fn = 100);
						translate([sliderWithMax-2,0]) circle(d=4,$fn = 100);
					}

					translate([4,0]) for (i=[0:sliderWithMax/2-3]) translate([i*2,0]) circle(d=1,$fn = 100);
				}
			cylinder(d=6.7, h=3.8, $fn=100);
		}
		translate([0,0,-1]) cylinder(d=2.5, h=3.8+2, $fn=100);
		translate([0,0,-1]) cylinder(d=4.7, h=1+1, $fn=100);	
		translate([0,0,3.8-2+1]) cylinder(d=4.7, h=2+1);	
	}

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

LCD

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
        rts

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      
        rts

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
        rts

send:   bsr     delay
        btst    #8,d0           ; test rs bit
        beq     reg0
        bsr     rs1             ; select register 1
        bra     skip
reg0:   bsr     rs0             ; select register 0
skip:
        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
        rts

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

delay2: move.w  #$800,d1
dloop2: subi    #1,d1
        bne     dloop2
        rts
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;


// Todo : DISPLAY 2ND LINE, DISPLAY SILENT, ...

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

  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

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(topic);

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

  {
  
    for (int i = 0; i < length; i++)
    {
      Serial.print((char)payload[i]);
      if (i < 16){
      lcd.setCursor(0, 0);
      lcd.setCursor(i, 0);
      } else {
      lcd.setCursor(0, 1);
      lcd.setCursor(i-16, 1);
      }
      lcd.write((char)payload[i]);
    }
  }


  Serial.println();
} 

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

    if (client.connect(clientId.c_str()))
    {
      Serial.println("connected");

      client.subscribe("mqttlcd/message");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(6000);
    }
  }
} 

void setup() {
  Serial.begin(115200);
  pinMode(button, INPUT);
  digitalWrite(2, HIGH);
  pinMode(ledRed, OUTPUT);
  digitalWrite(ledRed, LOW);
  pinMode(horn, OUTPUT);
  digitalWrite(horn, LOW);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  lcd.init(); 
  lcd.backlight();
}

void loop() {

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

  }

  client.setCallback(callback);
  client.loop();

  press = digitalRead(button);
  if (press == LOW)
  {
    if (buttonToggle)
    {
      digitalWrite(ledRed, HIGH);
      digitalWrite(horn, HIGH);
      buttonToggle = !buttonToggle;
    }
    else
    {
      digitalWrite(ledRed, LOW); 
      digitalWrite(horn, LOW);
      buttonToggle = !buttonToggle;
      toggle = false;
      client.publish("mqttlcd/button","pressed");
      lcd.clear();
      lcd.noBacklight(); // turn off backlight
    }
  }
  delay(500);  //delay for debounce
}

Oled

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

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
dtoverlay=piscreen,speed=24000000,rotate=90
# 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
https://github.com/PaulStoffregen/XPT2046_Touchscreen

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

Epaper

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

PCB Holder, flashing door sensors

A while back i printed a PCB holder, perfect for accessing contacts on a print, without the need for soldering.

Flashed a doorsensor with Tasmota.

esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 tasmota.bin

Keep GND and VCC connected, to keep device awake. Else it’s going into sleep mode.

Pull GPio0 to GND @ boottime, to get into flash mode.

3v3 + GND to keep device alive for configuring.

TTL Uart with 3V3

A sms gateway

Sms form

Made a generic sms sender, for check_mk monitoring + sending password of accounts.
You can send sms by filling in a form, or using a url like:

http://smsgateway.local:8080/sms/0612341234/Message%20met%20spaties

It uses a Raspberry and a sim800L module.

Fritzing schematic
At work in a corner near a window (3d printed case)

Remove pin from simcard fix:

sudo minicom -b 115000 -o -D /dev/serial0

 AT+CPIN?
+CPIN: SIM PIN

AT+CPIN=0000
OK

AT+CLCK=”SC”,0,”0000″
OK

AT+CPIN?
+CPIN: READY 

Cron

@reboot sh /home/pi/launcher.sh 

Launcher

cat /home/pi/launcher.sh
#!/bin/bash
cd /home/pi
while true; do
/usr/bin/python newapi.py
done

newapi.py (uses flask)

import serial
import RPi.GPIO as GPIO     
import os, time
import sys

from flask import Flask, render_template, request
app = Flask(__name__)

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField
from wtforms.validators import DataRequired

from flask import render_template

app.config['SECRET_KEY'] = 'you-will-never-guess'

class FormForm(FlaskForm):
    telnumber = StringField('telnumber', validators=[DataRequired()])
    messagepart = TextAreaField('Text', render_kw={"rows": 5, "cols": 20})
    submit = SubmitField('Send Sms')
 
@app.route("/sms/<number>/<message>")
def action(number, message):
        num = number.encode() 
        mes = message.encode() 
	GPIO.setmode(GPIO.BOARD)   
	# Enable Serial Communication
	port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1)

	# Transmitting AT Commands to the Modem
	# '\r\n' indicates the Enter key
	port.write('AT'+'\r\n')
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	#port.write('ATE0'+'\r\n')      # Disable the Echo
	#rcv = port.read(10)
	#print rcv
	#time.sleep(1)
	port.write('AT+CMGF=1'+'\r\n')  # Select Message format as Text mode
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write('AT+CNMI=2,1,0,0,0'+'\r\n')   # New SMS Message Indications
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write('AT+CSCS="GSM"'+'\r\n')   
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	# Sending a message to a particular Number
	port.write('AT+CMGS="'+num+'"\r\n')
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write(mes+'\r\n')  # Message
	rcv = port.read(10)
	print rcv
	port.write("\x1A") # Enable to send SMS
	for i in range(10):
	    rcv = port.read(10)
	    print rcv
        return 'OK'
@app.route("/form")
def form():
    form = FormForm()
    return render_template('web.html', title='Web Sms', form=form)
@app.route('/data', methods = ['POST', 'GET'])
def data():
    if request.method == 'GET':
        return "The URL /data is accessed directly. Try going to '/form' to submit form"
    if request.method == 'POST':
  
        telnumber = request.form['telnumber']
        messagepart = request.form['messagepart']
        num = telnumber.encode() 
        mes = messagepart.encode()
	GPIO.setmode(GPIO.BOARD)   
	# Enable Serial Communication
	port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1)
	# Transmitting AT Commands to the Modem
	# '\r\n' indicates the Enter key
	port.write('AT'+'\r\n')
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	#port.write('ATE0'+'\r\n')      # Disable the Echo
	#rcv = port.read(10)
	#print rcv
	#time.sleep(1)
	port.write('AT+CMGF=1'+'\r\n')  # Select Message format as Text mode
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write('AT+CNMI=2,1,0,0,0'+'\r\n')   # New SMS Message Indications
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write('AT+CSCS="GSM"'+'\r\n')   
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	# Sending a message to a particular Number
	port.write('AT+CMGS="'+num+'"\r\n')
	rcv = port.read(10)
	print rcv
	time.sleep(1)
	port.write(mes+'\r\n')  # Message
	rcv = port.read(10)
	print rcv
	port.write("\x1A") # Enable to send SMS
	for i in range(10):
	    rcv = port.read(10)
	    print rcv
       
        return '<a href="/form">Nog een SMS sturen</a>'
@app.route("/checkmk")
def checkmk():
        # Enable Serial Communication
        port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1)
   
        port.write('AT'+'\r\n')
        rcv1 = port.read(30)
        time.sleep(1)

        port.write('AT+CPAS'+'\r\n')
        rcv2 = port.read(30)        
        time.sleep(1)
    
        port.write('AT+CGREG?'+'\r\n')
        rcv3 = port.read(30)
        time.sleep(1)
    
        port.write('AT+CGATT?'+'\r\n')
        rcv4 = port.read(30)
        time.sleep(1)
    
        port.write('AT+CSQ'+'\r\n')
        rcv5 = port.read(30)
        time.sleep(1)

        return 'OK of niet' + rcv1 + rcv2 + rcv3 + rcv4 + rcv5
if __name__ == "__main__":
   app.run(host='0.0.0.0', port=8080, debug=True)

Winecellar – rack

Winerack finished .. at last, with laser engraved labels. (See 3D printer posts)
Enough space for 160 bottles.

No glue, only tacks.

Een eerste design in sketchup
1st design in sketchup (old)

Engraving using a laser engraver on my 3D printer

Laser engrave tools

For my winerack i engraved some wooden panels.

When doing so, i needed to fix the height of the engraver to get the focus of the beam right.

At start i removed all Z positions from the GCODE file after calibrating. Later i used a script wrote that fixed the height setting to 110.

#!/bin/bash
# Usage: confirm height focus at 110
# ./scriptname filetofix.gcode
myz=110
cat "$1" | sed s/Z1/Z${myz}/g | sed s/Z6/Z${myz}/g > "fixed.$1"

Another tool i made is the one below, it takes a GCODE file, calulates where the borders are (min/max x and y)
And sets the FAN2 (laser intensity to a minimum)
After that it generates GCODE to draw a box wherein the to be engraved object is made

Now you can run the GCODE file multiple times to position it on the wood to you can get the minimum of spoils.

#!/bin/bash
# Usage: scriptname file.gcode 
# It wil create a pointtest file for test running
myz=110
MAXX=$(cat "$1" | grep "G0 X" | awk '{ print $2 }' | cut -c2- | sort -n | tail -1)
MINX=$(cat "$1" | grep "G0 X" | awk '{ print $2 }' | cut -c2- | sort -n | head -1)
MAXY=$(cat "$1" | grep "G0 X" | awk '{ print $3 }' | cut -c2- | sort -n | tail -1)
MINY=$(cat "$1" | grep "G0 X" | awk '{ print $3 }' | cut -c2- | sort -n | head -1)

cat > "pointtest - $1" << EOF
;BingoStart
G90
M17 Z
G0 F3000
G0 Z${myz} F3000
M18 Z
G0 X${MINX} Y${MINY}
M106 S2
G0 F3000
G0 X${MINX} Y${MAXY}
M106 S2
G0 F3000
G0 X${MAXX} Y${MAXY}
M106 S2
G0 F3000
G0 X${MAXX} Y${MINY}
M106 S2
G0 F3000
G0 X${MINX} Y${MINY}
M106 S2
G0 F3000
G0 X${MINX} Y${MAXY}
M106 S2
G0 F3000
G0 X${MAXX} Y${MAXY}
M106 S2
G0 F3000
G0 X${MAXX} Y${MINY}
M106 S2
G0 F3000
G0 X${MINX} Y${MINY}
M106 S2
M107
;end
EOF

GCODES

  • M17 Z – disable Z movement
  • G0 – rapid move
    G0 X100 Y100 (Goto 100,100)
    G0 F3000 (speed)
  • M106 – set fan speed (I my case, this is laser intensity)
    M106 – S2
  • G90 – set absolute coordinates
  • M107 – fan off

More info about gcodes: http://www.science.smith.edu/cdf/pdf_files/Techno_GCODE%20Commands.pdf