Skip to content

Instantly share code, notes, and snippets.

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

Sergey Royz zjor

🏠
Working from home
View GitHub Profile
@zjor
zjor / nano_rp2040_hue_rotation.ino
Created August 23, 2022 17:01
Arduino Nano RP 2040: performs hue rotation
#include <WiFiNINA.h>
typedef struct {
unsigned char r;
unsigned char g;
unsigned char b;
} RGB;
typedef struct {
unsigned char h;
@zjor
zjor / eeprom_wifi_creds_esp32.cpp
Created August 9, 2022 18:54
Store and load WiFi credentials to EEPROM with Arduino framework on ESP32
#include <Arduino.h>
#include <EEPROM.h>
#define EEPROM_SIZE 64
bool has_credentials() {
return EEPROM.read(0) == 0x42 /* credentials marker */;
}
void save_credentials(char *ssid, char *pass) {
@zjor
zjor / esp32_hue_rotation.cpp
Created November 1, 2021 18:07
Controls an RGB LED with ESP32 WROOM
#include <Arduino.h>
#define R_LED_PIN 32
#define G_LED_PIN 33
#define B_LED_PIN 25
#define R_CH 0
#define G_CH 1
#define B_CH 2
@zjor
zjor / suicide_node_server.js
Created October 19, 2021 14:53
NodeJS server which opens the URL in the browser and stops itself once the request has been processed
const express = require('express')
const open = require('open');
const app = express()
const port = 3000
const log = console.log;
let started = true;
@zjor
zjor / create_sns_sqs_subscription.cfn.yaml
Created August 14, 2021 15:19
[AWS] Creates an SNS topic and an SQS queue. Subscribes the queue to the created topic
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Creates an SNS topic and an SQS queue. Subscribes the queue to the created topic
Parameters:
Environment:
Default: dev
Type: String
AllowedPattern: "(dev|stage|local-[0-9a-zA-Z]*)"
Resources:
@zjor
zjor / blackpill_stlink_platformio.ini
Created June 25, 2021 18:53
ST-link V2 + BlackPill F411CE build configuration
@zjor
zjor / smt32_blackpill_timer_interrupt.cpp
Created June 12, 2021 14:59
STM32F411CE blinking led with timer interrupts
#include <Arduino.h>
HardwareTimer *timer;
volatile int state = LOW;
void isr() {
digitalWrite(PC13, state);
state = !state;
}
@zjor
zjor / esc_arduino.ino
Created May 27, 2021 15:43
Control brushless motor with Arduino and quadrature encoder
#include <Encoder.h>
#include <Servo.h>
Encoder encoder(2, 3);
long last_postition;
Servo esc;
void setup() {
Serial.begin(115200);
@zjor
zjor / low_pass_filter.py
Created May 17, 2021 18:35
Simple low-pass digital filter
# https://en.wikipedia.org/wiki/Low-pass_filter
import numpy as np
import matplotlib.pyplot as plt
N = 1000
t = np.linspace(0, 10, N)
x = np.sin(t) + np.cos(100 * t + np.random.normal(0, 1, N))
@zjor
zjor / esp32_stepper_control_timer_interrupt.cpp
Created May 9, 2021 13:31
Control stepper motor speed with ESP32 using timer interrupt
#include <Arduino.h>
#define STEP_PIN 21
#define DIR_PIN 17
#define PPR 400
#define TICKS_PER_SECOND 200000
hw_timer_t * timer = NULL;
volatile uint32_t ticksPerPulse = TICKS_PER_SECOND;