Skip to content

Instantly share code, notes, and snippets.

View michalmonday's full-sized avatar

Michal Borowski michalmonday

  • Colchester, UK
View GitHub Profile
@michalmonday
michalmonday / copy_bsp.py
Last active October 28, 2024 15:13
Script that copies BSP and Utilities from ST repository to STM32F412G-Disovery project
'''
Usage: py -3 copy_bsp.py project_name
This script copies BSP files and Utilities to specified project.
This script should be placed in the workspace folder of STM32CubeIDE.
In the same directory where project folders are created.
REPOSITORY_PATH must be manually modified in this script in order to work.
Whenever "Project -> Generate Code" option is used, the Utilities folder
@michalmonday
michalmonday / float_to_concise_str.py
Created February 6, 2023 14:16
Neat rounding function.
import numpy as np
def float_to_concise_str(f):
''' turns 0.0012345678 into 0.0012 '''
f = float(f)
if len(str(f).split('.')[1]) < 2 or f >= 1.0:
return str(round(f, 2))
return np.format_float_positional( float(f'{f:.2}'), trim='-')
@michalmonday
michalmonday / pyqt6_workflow.md
Created January 24, 2023 11:06
How to create and use Qt Designer or Qt Creator to create a GUI for python.
  • Create "ui" file in Qt Designer or Qt Creator.
  • Run update_MainWindow.py which runs pyuic6 -o my_file.py <file>.ui and moves imports from the bottom to the top of the file, because promoted classes happen to be imported at the bottom for some reason which was causing an error.
  • See files in this folder (e.g. file_loader.py) to see how to create/connect signals and slots.
@michalmonday
michalmonday / python_speed_check.md
Last active January 24, 2023 11:08
A command to profile a python script
# py -3 -m pip install snakeviz

# on Windows:
py -3 -m cProfile -o my_script.profile my_script.py && snakeviz.exe my_script.profile
#include "mbed.h"
Serial serial(USBTX, USBRX);
DigitalOut led(LED1);
//void onReceive() {
// char c = serial.getc();
// led = !led;
// serial.putc(c+1);
//}
@michalmonday
michalmonday / keys.cpp
Created November 25, 2022 17:54
Mbed extension board alternative keypad reading.
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
BusOut cols_out(p26, p25, p24);
// Checking extension board with multimeter shows that p14,p13,p12,p11 are connected
// to row indicating pins of the keypad. The extension board schematic is incorrect.
BusIn rows_in(p14, p13, p12, p11);
@michalmonday
michalmonday / fix.cpp
Last active November 25, 2022 17:13
Extension board LEDs wiring fix
#include "mbed.h"
// mosi, miso (unused really), sclk
SPI sw(p5, p6, p7);
// lat (latch) pin of TLC59281 as shown in extension board schematic
DigitalOut lat(p8);
/* The extension board wiring from TLC59281 to 3 LEDs pairs are not consistent with
remaining 5 LEDs pairs (green is wired as red, red is wired as green).
#!/usr/bin/python3
'''
This script can be replaced by simply using:
python3 -m serial.tools.list_ports -v
'''
import serial # pip install pyserial
import serial.tools.list_ports as list_ports
@michalmonday
michalmonday / dma_receiver.py
Last active August 6, 2022 11:11
Efficient (hopefully) pynq dma receiver with multiple buffers that allows to get the data as a list.
''' Example usage with dma.sendchannel supplying the data:
import os, subprocess, sys, re, time
from pathlib import Path
from pynq import Overlay
from pynq import allocate
from threading import Thread
from dma_receiver import DmaReceiver
@michalmonday
michalmonday / copy_to_pynq.py
Created July 30, 2022 22:21
Copies .bit and .hwh files from Vivado output directories to pynq.
#!py -3
'''
After using Vivado block design, creating a HDL wrapper for it,
and generating bitstream, this script can be used to move the
"_wrapper.bit" and ".hwh" files to pynq.
Tested on Windows only.
'''
import shutil