Skip to content

Instantly share code, notes, and snippets.

@stecman
stecman / STM8S_programming_examples.md
Last active April 3, 2025 10:41
STM8S code examples

This is a collection of code snippets for various features on the STM8S family microcontrollers (specifically the STM8S003F3). These are written against the STM8S/A SPL headers and compiled using SDCC.

Some of this controller's functions aren't particularly intuitive to program, so I'm dumping samples for future reference here. These are based on the STM8S documentation:

Run at 16MHz

@ItKindaWorks
ItKindaWorks / serialRelayTest.ino
Created July 2, 2018 16:29
A simple Arduino program for controlling an LC Tech serial relay board
/*
serialRelayTest.ino
*/
byte relON[] = {0xA0, 0x01, 0x01, 0xA2}; //Hex command to send to serial for open relay
byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1}; //Hex command to send to serial for close relay
void setup(void){
Serial.begin(9600);
@JamesNewton
JamesNewton / MassMind.org ENC1 3Wire ReadAngle Arduino
Created May 8, 2017 19:13
Arduino code to read the angle register from the MassMind.org ENC1 via 3 wire read only mode.
/*
Source from
http://forum.arduino.cc/index.php?topic=78881.msg1375885#msg1375885
* Ahmad Byagowi ([email protected])
* Date : Aug 31, 2013
* All code (c)2013 Ahmad Byagowi Consultant. all rights reserved
20170508 Minor edits to improve clarity by James Newton.
*/
//c2 pin tied to ground for 3 wire mode
@gbaman
gbaman / HowToOTGFast.md
Last active April 11, 2025 22:53
Simple guide for setting up OTG modes on the Raspberry Pi Zero, the fast way!

Setting up Pi Zero OTG - The quick way (No USB keyboard, mouse, HDMI monitor needed)

More details - http://blog.gbaman.info/?p=791

For this method, alongside your Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh in the SD card as well. By default SSH i

@kraftb
kraftb / I2C_Adapter.ino
Created May 19, 2015 15:31
USB to I2C Adapter using Arduino
// I2C to USB Adapter using Arduino
// by Bernhard Kraft <[email protected]>
/**
* This sketch can get loaded onto an Arduino to use it as USB to I2C Adapter.
* It uses the Wire library. So take a look at the documentation of the Wire
* libarary about the pins being used as SDA/SCL. For most Arduino boards this
* will be analog input pin 4 for SDA and analog input pin 5 for SCL.
*
* On the USB side the default serial link of the Arduino is used. A protocol
#include "mbed.h"
#include "SLCD.h"
#include "MAG3110.h"
#include "fft4g.h"
#include "aqm1248a_lcd.h"
#define NMAX 256
#define NMAXSQRT 32
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "..............";
const char* password = "................";
String form = "<form action='led'><input type='radio' name='state' value='1' checked>On<input type='radio' name='state' value='0'>Off<input type='submit' value='Submit'></form>";
String imagepage = "<img src='/led.png'>";
@ivanseidel
ivanseidel / PID.ino
Last active March 29, 2024 07:15
Simple PID Class for Arduino Projects
// (Really Simple) PID Class by Ivan Seidel
// GitHub.com/ivanseidel
// Use as you want. Leave credits
class PID{
public:
double error;
double sample;
double lastSample;