Skip to content

Instantly share code, notes, and snippets.

View robinkrens's full-sized avatar

Robin Krens robinkrens

  • The Netherlands
  • 14:36 (UTC +01:00)
View GitHub Profile
@robinkrens
robinkrens / sensorpole.c
Last active September 8, 2021 11:07
Sensor Pole Code
void main(void)
{
switch(wakeup_cause()) {
case SHELF_MODE_WAKEUP:
init_peripherals(); /* enable all needed power domains */
set_tilt_trigger_intr(); /* (re)set tilt trigger again, kills ulp power domain */
ulp_load_program(&program); /* load program that periodically checks sensors */
ulp_set_wakeup_period(x);
ulp_run();
@robinkrens
robinkrens / sensorpole.dot
Last active September 8, 2021 11:14
Sensorpole firmware arch
/* Make pdf by running `dot -Tpng file.dot -o out.png`
* or check online at one of the many tools like webgraphviz.com */
digraph G {
A [label="Initializing"]
B [label="Communicating"]
C [label="Monitoring\n (ULP mode)"]
D [label="Sleeping\n (Shelf mode)"]
D -> A [label="Tilt trigger"]
@robinkrens
robinkrens / hx711_readforce.c
Created February 21, 2022 10:37
HX711 read force routine
static void read_force(void)
{
int count;
/* Offset and gain need to be calculated for each load cell */
int offset = 1234; /* calibration offset */
float gain = 1.818e-5; /* gain: convert output data to grams */
while(1) {
@robinkrens
robinkrens / beken_crc.py
Created February 23, 2024 00:37
beken bk3231 16-bit CRC add
# by mr_woggle - 2024 (c)
# free for all :D
import os
POLY = 0x8005
START_VAL = 0xFFFF
IN_FILE = "test.bin"
OUT_FILE = "test_encrypted.bin"
@robinkrens
robinkrens / stc32_hid_program.py
Created February 26, 2024 11:53
STC32 USB HID program ISP
# Example on how to use hid to write STC chip series: STC8H8K64U,STC32G12K128,STC32F12K54
# Opens USB HID device and programs flash. No error check. Use at own risk
# Only tested on STC32F12K54
import hid
import time
import struct
from intelhex import IntelHex
from tqdm import tqdm