Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
neosarchizo / main.py
Created Aug 5, 2022
MicroPython - ESP32 PWM 제어
View main.py
from machine import Pin, PWM
from time import sleep
while True:
pwm = PWM(Pin(25), freq=200, duty=512)
sleep(1)
pwm.freq(400)
sleep(1)
@neosarchizo
neosarchizo / main.py
Created Aug 4, 2022
MicroPython - ESP32 ADC 제어
View main.py
from machine import Pin, SoftI2C,ADC,Timer
from ssd1306 import SSD1306_I2C
i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
display = SSD1306_I2C(128, 64, i2c, addr=0x3C)
adc = ADC(Pin(36))
def on_timeout(_):
display.fill(0)
display.text('DeviceMart', 0, 0)
@neosarchizo
neosarchizo / main.py
Last active Aug 2, 2022
MicroPython - ESP32 RTC 제어
View main.py
from machine import Pin, SoftI2C, RTC, Timer
from ssd1306 import SSD1306_I2C
week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
# MON ~ SUN : 0 ~ 6
time = ['', '', '']
i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
display = SSD1306_I2C(128, 64, i2c, addr=0x3C)
rtc = RTC()
@neosarchizo
neosarchizo / main.py
Last active Aug 2, 2022
MicroPython - ESP32 I2C OLED 디스플레이 제어
View main.py
from machine import SoftI2C, Pin
from ssd1306 import SSD1306_I2C
i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
display = SSD1306_I2C(128, 64, i2c, addr=0x3C)
display.fill(0)
display.show()
display.pixel(5, 5, 1)
@neosarchizo
neosarchizo / main.py
Last active Jul 29, 2022
MicroPython - ESP32 하드웨어 타이머 제어하기
View main.py
from machine import Pin, Timer
led=Pin(2, Pin.OUT)
counter = 0
def on_timeout(_):
global counter
counter = counter + 1
print(counter)
led.value(counter % 2)
@neosarchizo
neosarchizo / main.py
Created Jul 26, 2022
MicroPython - ESP32 인터럽트 제어하기
View main.py
from machine import Pin
from time import sleep_ms
led = Pin(2, Pin.OUT)
key = Pin(0, Pin.IN, Pin.PULL_UP)
state = 0
def on_falling(_):
global state
sleep_ms(10)
@neosarchizo
neosarchizo / main.py
Created Jul 25, 2022
MicroPython - STM32 W5500 이더넷 모듈 MQTT 통신 : subscribe
View main.py
from network import WIZNET5K
from pyb import SPI
from mqttclient import MQTTClient
from time import sleep
SERVER = 'broker.mqttdashboard.com'
PORT = 1883
CLIENT_ID = 'stm32'
TOPIC = 'devicemart'
@neosarchizo
neosarchizo / main.py
Created Jul 6, 2022
MicroPython - STM32 W5500 이더넷 모듈 MQTT 통신
View main.py
from network import WIZNET5K
from pyb import SPI
from mqttclient import MQTTClient
from time import sleep
SERVER = 'broker.mqttdashboard.com'
PORT = 1883
CLIENT_ID = 'stm32'
TOPIC = 'devicemart'
@neosarchizo
neosarchizo / main.py
Last active Jul 5, 2022
MicroPython - STM32 W5500 이더넷 모듈 소켓 통신
View main.py
from pyb import SPI, Timer
from network import WIZNET5K
from usocket import socket
nic = WIZNET5K(SPI(2), 'Y5', 'Y4')
nic.active(True)
nic.ifconfig('dhcp')
if nic.isconnected():
config = nic.ifconfig()
@neosarchizo
neosarchizo / main.py
Created Jul 3, 2022
MicroPython - STM32 W5500 이더넷 모듈 제어
View main.py
from pyb import SPI
from network import WIZNET5K
nic = WIZNET5K(SPI(2), 'Y5', 'Y4')
nic.active(True)
nic.ifconfig('dhcp')
# ip, subnet, gateway, dns
# nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))