Skip to content

Instantly share code, notes, and snippets.

View SweiLz's full-sized avatar
🏠
Working from home

Liews Wuttipat SweiLz

🏠
Working from home
View GitHub Profile

Install Google Fonts

Download desired fonts

https://fonts.google.com/?selection.family=Open+Sans

Install Google Fonts on Ubuntu

cd /usr/share/fonts
sudo mkdir googlefonts
cd googlefonts
sudo unzip -d . ~/Downloads/Open_Sans.zip

@SweiLz
SweiLz / PythonSoftwareRestart.py
Created March 28, 2022 03:17
Software Restart in Python
import sys
import os
import time
def restart():
print(f"Restart >> argv:{sys.argv} executable:{sys.executable}")
os.execv(sys.executable, ['python'] + sys.argv)
try:
for i in range(5, 0, -1):
#include <mbed.h>
#include <math.h>
#include "QEI.h"
#define SEP_DIST 0.6
#define RATIO 3926.991 // 2 * PI / (1600, 400) * 1000000 * ratio gear
#define WHEEL_RADIUS 0.05
Timer tt;
Serial pc(PB_10, PB_11);
QEI enc_right(PA_9, PA_10, NC, 400, QEI::X4_ENCODING);
@SweiLz
SweiLz / calculate_electric_used_unit.py
Created April 22, 2020 14:59
ฟังก์ชั่นคำนวณค่าไฟออกมาเป็นหน่วยบาท
def calUnit(unit,Ft = -11.6):
total = 0
temp_unit = unit
if unit <= 150:
print("Case: ","1.1")
else:
print("Case: ","1.2")
if temp_unit > 400:
total += ((temp_unit-400) * 4.4217)
temp_unit = 400
@SweiLz
SweiLz / calculate_crc16.py
Created April 22, 2020 14:44
Function to calculate CRC16 Checksum in python
def updateCRC(crc_accum, data_blk_ptr, data_blk_size):
crc_table = [0x0000,
0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027,
0x0022, 0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D,
0x8077, 0x0072, 0x0050, 0x8055, 0x805F, 0x005A, 0x804B,
0x004E, 0x0044, 0x8041, 0x80C3, 0x00C6, 0x00CC, 0x80C9,
0x00D8, 0x80DD, 0x80D7, 0x00D2, 0x00F0, 0x80F5, 0x80FF,
0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1, 0x00A0, 0x80A5,
0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1, 0x8093,
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStep = Stepper(stepsPerRevolution,8,10,9,11);
void setup() {
myStep.setSpeed(15); // speed in rpm
Serial.begin(9600);
}
@SweiLz
SweiLz / mbed_i2c_scanner.cpp
Last active June 4, 2020 12:55
I2C address scanner for mbed os
#include <mbed.h>
I2C i2c(PB_11, PB_10); // SDA pin, SCL pin
Serial pc(PB_6, PB_7); // TX pin, RX pin
int main()
{
pc.baud(115200);
wait_ms(2000);
pc.printf("Hello World!\n");
@SweiLz
SweiLz / arduino_SoftwareSerial.ino
Created September 1, 2019 08:29
Arduino Software Serail testcode
#include <SoftwareSerial.h>
SoftwareSerial ss(8, 2); // RX, TX
void setup() {
Serial.begin(115200);
Serial.println("Goodnight moon!");
ss.begin(115200);
ss.println("Hello, world?");
#! /usr/bin/env python
import math
import sys
import rospy
import serial
import tf
from geometry_msgs.msg import Twist, Pose2D
from nav_msgs.msg import Odometry
#include "ros/ros.h"
#include <diagnostic_msgs/DiagnosticArray.h>
#include <diagnostic_msgs/DiagnosticStatus.h>
#include <diagnostic_msgs/KeyValue.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "diagnostics");
ros::NodeHandle nh;