Skip to content

Instantly share code, notes, and snippets.

Avatar

Toshihiko Arai araemon

View GitHub Profile
View OledTest.py
import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
i2c = board.I2C()
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
# Clear display.
oled.fill(0)
View relay.py
import RPi.GPIO as GPIO
from time import sleep
RELAY_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
while True:
View dht11_test.ino
#include "DHT.h"
#define DATA_PIN 1 // D1
DHT dht(DATA_PIN, DHT11);
void setup() {
Serial.begin(9600);
dht.begin();
}
View distance_meter.ino
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
#define TrigPin 1 // D1
#define EchoPin 2 // D2
double speedSound = 331.5 + 0.61 * 20; // 20は現在の気温
View hc-sr04-test.ino
#define TrigPin 1 // D1
#define EchoPin 2 // D2
double speedSound = 331.5 + 0.61 * 20; // 20は現在の気温
double distance = 0;
void setup() {
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
@araemon
araemon / oled_test.ino
Last active Dec 11, 2020
DSD TECH OLED 0.91 display TEST with U8g2lib library on Arduino -> https://101010.fun/iot/arduino-oled-display.html
View oled_test.ino
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void setup(void) {
u8g2.begin();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_8x13_tf);
u8g2.drawStr(0, 10, "Hello world!");
u8g2.drawStr(0, 21, "OLED screen TEST");
View blink_builtin_led.ino
@araemon
araemon / MOSFET_LED.py
Last active Dec 7, 2020
Raspberry PiとMOSFETを使ったPWM制御でLEDの調光 -> https://101010.fun/iot/raspi-mosfet-led.html
View MOSFET_LED.py
# -*- coding: utf-8 -*-
from gpiozero import PWMLED
from time import sleep
import numpy as np
LED = PWMLED(14)
LED.value = 0
View WaterTmpSensor.py
from w1thermsensor import W1ThermSensor, Unit
import time
sensor = W1ThermSensor()
while True:
temperature_in_celsius = sensor.get_temperature()
temperature_in_fahrenheit = sensor.get_temperature(Unit.DEGREES_F)
print("celsius: {0:.3f}".format(temperature_in_celsius))
print("fahrenheit: {0:.3f}".format(temperature_in_fahrenheit))
View hls.sh
#!/bin/sh
python3 server.py > /dev/null 2>&1 &
cd www
rm -Rf *.m3u8 *.ts
ffmpeg -f v4l2 -thread_queue_size 16384 -s 640x480 -vsync -1 -i /dev/video0 \
-c:v libx264 -b:v 1000k -bufsize 1000k \
-flags +cgop+loop-global_header \
-bsf:v h264_mp4toannexb \