Skip to content

Instantly share code, notes, and snippets.

@olgierd
olgierd / source.c
Last active December 5, 2023 12:43
A visual surprise
// usage: gcc source.c -lm && ./a.out | paplay --rate=5161 --format=float32le --channels=1 --raw
#include <stdio.h>
#include <math.h>
int main() {
float x=0,y=0, o=0, os;
for(x=-1.12;x<1.12;x+=0.0187) {
for(int q=0;q<36;q++) { o = fmod(o + 2*1200*M_PI/5161, 2*M_PI); os = sin(o); fwrite(&os, sizeof(float), 1, stdout); }
for(y=-2;y<0.5;y+=0.0157) {
float c=0, xt, ax=y, ay=x; while (ax*ax+ay*ay<=4 && c<100) { xt=ax*ax-ay*ay+y; ay=2*ax*ay+x; ax=xt; c++; }
@olgierd
olgierd / aioc.md
Last active October 28, 2023 13:59
AIOC - uwagi praktyczne

AIOC - uwagi praktyczne

Montaż

Kluczową sprawą jest przylutowanie wtyczek Jack prosto, tzn. równolegle względem siebie, a także zachowanie odpowiedniego dystansu.

  1. Wtyczkę Jack rozkręcamy, plastikową obudowę niestety wywalamy.
  2. Złącze masy skracamy o poszerzony element przeznaczony do zaciskania (najlepiej nożycami do blachy albo solidnymi obcinaczkami).

Bez odpowiedniego wzornika dobre przylutowanie wtyczek jest prawie niemożliwe, można więc:

@olgierd
olgierd / streamaudio.py
Created April 7, 2023 19:54
Stream audio from trusdx over serial port
#!/usr/bin/env python3
import serial
import time
import pyaudio
import threading
import time
ser = serial.Serial("/dev/ttyUSB0", 115200)
stream = pyaudio.PyAudio().open(format = pyaudio.paInt8, channels = 1, rate = 7820, output = True)
@olgierd
olgierd / ender_3_4.2.7_laser.md
Last active March 28, 2023 18:55
How to turn Ender 3 (Pro) with 32-bit board (4.2.7) into a Laser engraver.

I bought 20W (12V@1.6A - so probably ~4W optical power) laser module and wanted to control it using Ender 3 Pro equipped with "silent" 32 bit board - V4.2.7 from Creality.

Usually, laser is controlled by utilizing Ender's fan control output, which utilizes PWM.

Unfortunately, turns out the frequency of PWM signal is ~8 Hz by default, which may be fine for controlling DC motors in the fans, but surely is too low to control a laser.

Github user "cbagwell" proposed a way to modify Marlin firmware to increase PWM frequency to 1 kHz:

@olgierd
olgierd / compute.py
Created December 8, 2022 20:27
Peak-n-hold on FFT for IQ data
import scipy.io
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fft, fftshift
path = '/home/oli/baseband_144288239Hz_17-59-43_08-12-2022.wav'
sr, d = scipy.io.wavfile.read(path)
d = d[...,0] + 1j * d[...,1] # convert to complex array
sta, stop = 30, 60 # time of sweep beginning and end in .wav file