260131_artnet
This commit is contained in:
parent
9981ffbaf8
commit
2c5fec829d
@ -2,7 +2,8 @@ from machine import Pin, PWM
|
||||
import time
|
||||
|
||||
|
||||
ir_led = PWM(Pin("GP18"))
|
||||
#ir_led = PWM(Pin("GP18"))
|
||||
ir_led = PWM(Pin(6))
|
||||
ir_led.freq(38000)
|
||||
ir_led.duty_u16(0)
|
||||
|
||||
@ -51,11 +52,11 @@ try:
|
||||
#xmit_bin(0b010101, 6)
|
||||
#xmit_bin(7774, 16, 1)
|
||||
xmit_fx(0, 6, 0, repeat=1)
|
||||
time.sleep_ms(10000)
|
||||
time.sleep_ms(1000)
|
||||
|
||||
#xmit_bin(15964, 16, 1)
|
||||
xmit_fx(8, 2, 0, repeat=1)
|
||||
time.sleep_ms(10000)
|
||||
time.sleep_ms(3000)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
ir_led.deinit()
|
||||
|
||||
3
xmit/pixmod_xmit_1v2_ethernet/.gitignore
vendored
Normal file
3
xmit/pixmod_xmit_1v2_ethernet/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
5
xmit/pixmod_xmit_1v2_ethernet/.micropython
Normal file
5
xmit/pixmod_xmit_1v2_ethernet/.micropython
Normal file
@ -0,0 +1,5 @@
|
||||
# MicroPython project configuration
|
||||
# PORT can be: auto, /dev/ttyUSB0, /dev/ttyACM0, id:<serial>, etc.
|
||||
PORT=auto
|
||||
# BAUD is optional - mpremote auto-detects, but can be set for edge cases
|
||||
BAUD=115200
|
||||
49
xmit/pixmod_xmit_1v2_ethernet/lib_artnet.py
Normal file
49
xmit/pixmod_xmit_1v2_ethernet/lib_artnet.py
Normal file
@ -0,0 +1,49 @@
|
||||
import machine
|
||||
import network
|
||||
import socket
|
||||
import struct
|
||||
|
||||
|
||||
class ArtNet():
|
||||
def __init__(self, id_universe, id_ch_start, id_ch_end):
|
||||
self.id_universe = id_universe
|
||||
self.id_ch_start = id_ch_start
|
||||
self.id_ch_end = id_ch_end
|
||||
|
||||
self.channels = [0]*(id_ch_end-id_ch_start+1)
|
||||
self.clbk = None
|
||||
|
||||
spi = machine.SPI(0, baudrate=20000000, polarity=0, phase=0,
|
||||
sck=machine.Pin(18), mosi=machine.Pin(19), miso=machine.Pin(16))
|
||||
nic = network.WIZNET5K(spi, machine.Pin(17), machine.Pin(20))
|
||||
nic.active(True)
|
||||
|
||||
while not nic.isconnected():
|
||||
pass
|
||||
|
||||
print('Art-Net Node IP:', nic.ifconfig()[0])
|
||||
|
||||
ARTNET_PORT = 6454
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.s.bind(('0.0.0.0', ARTNET_PORT))
|
||||
|
||||
def tick(self):
|
||||
data, addr = self.s.recvfrom(1024)
|
||||
|
||||
# packets start with 'Art-Net' + null byte
|
||||
if len(data) > 18 and data[0:8] == b'Art-Net\x00':
|
||||
opcode = struct.unpack('<H', data[8:10])[0]
|
||||
|
||||
# 0x5000 is OpOutput / OpDmx
|
||||
if opcode == 0x5000:
|
||||
universe = struct.unpack('<H', data[14:16])[0]
|
||||
if(universe == self.id_universe):
|
||||
# DMX data starts at byte 18
|
||||
dmx_data = data[18:]
|
||||
|
||||
if(len(dmx_data) > self.id_ch_end):
|
||||
for i,n in enumerate(range(self.id_ch_start, self.id_ch_end+1)):
|
||||
self.channels[i] = int(dmx_data[n])
|
||||
|
||||
if(self.clbk is not None):
|
||||
self.clbk(self)
|
||||
47
xmit/pixmod_xmit_1v2_ethernet/lib_pixmod.py
Normal file
47
xmit/pixmod_xmit_1v2_ethernet/lib_pixmod.py
Normal file
@ -0,0 +1,47 @@
|
||||
from machine import Pin, PWM
|
||||
import time
|
||||
|
||||
|
||||
class PixMod():
|
||||
def __init__(self, pin_nr=6):
|
||||
#ir_led = PWM(Pin("GP18"))
|
||||
self.ir_led = PWM(Pin(pin_nr))
|
||||
self.ir_led.freq(38000)
|
||||
self.ir_led.duty_u16(0)
|
||||
|
||||
self.READ_DELAY_US = 10000
|
||||
self.PROCESS_DELAY_US = 30000
|
||||
# so a single frame takes roughly 200ms
|
||||
|
||||
|
||||
def emit_pulse(self, duration_us):
|
||||
self.ir_led.duty_u16(32768) # 50% duty cycle
|
||||
time.sleep_us(duration_us)
|
||||
self.ir_led.duty_u16(0) # 0% duty cycle
|
||||
|
||||
def xmit_bin(self, msg_data_bin, msg_len, repeat=1):
|
||||
msg_data_bin = (msg_data_bin << 1) + 1
|
||||
msg_len += 1
|
||||
|
||||
for n in range(repeat):
|
||||
self.emit_pulse(4500)
|
||||
time.sleep_us(self.PROCESS_DELAY_US)
|
||||
|
||||
for i in range(msg_len-1, -1, -1):
|
||||
if(msg_data_bin & (1<<i)):
|
||||
self.emit_pulse(1500)
|
||||
else:
|
||||
self.emit_pulse(500)
|
||||
|
||||
time.sleep_us(self.READ_DELAY_US)
|
||||
|
||||
self.emit_pulse(4500)
|
||||
time.sleep_us(self.PROCESS_DELAY_US)
|
||||
|
||||
def xmit_fx(self, id_effect, id_colour_fg, id_colour_bg, repeat=1):
|
||||
msg = id_effect
|
||||
msg = (msg << 4) + id_colour_fg
|
||||
msg = (msg << 4) + id_colour_bg
|
||||
msg = (msg << 2) + 0 # TODO: CRC
|
||||
|
||||
self.xmit_bin(msg, 14, repeat)
|
||||
22
xmit/pixmod_xmit_1v2_ethernet/main.py
Normal file
22
xmit/pixmod_xmit_1v2_ethernet/main.py
Normal file
@ -0,0 +1,22 @@
|
||||
from lib_pixmod import PixMod
|
||||
from lib_artnet import ArtNet
|
||||
|
||||
|
||||
def clbk_packet(artnet):
|
||||
print("Uni: {} | Ch1: {} Ch2: {} Ch3: {}".format(artnet.id_universe, artnet.channels[0], artnet.channels[1], artnet.channels[2]))
|
||||
|
||||
pixmod.xmit_fx(0, 6, 0, repeat=1)
|
||||
time.sleep_ms(1000)
|
||||
|
||||
try:
|
||||
pixmod = PixMod()
|
||||
|
||||
artnet = ArtNet(0, 0, 9)
|
||||
artnet.clbk = clbk_packet
|
||||
|
||||
while(True):
|
||||
artnet.tick()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pixmod.ir_led.deinit()
|
||||
artnet.s.close()
|
||||
13
xmit/pixmod_xmit_1v2_ethernet/pyproject.toml
Normal file
13
xmit/pixmod_xmit_1v2_ethernet/pyproject.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[project]
|
||||
name = "pixmod_xmit_1v2_ethernet"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"mpremote",
|
||||
"ruff",
|
||||
]
|
||||
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"micropython-rp2-stubs",
|
||||
]
|
||||
3
xmit/pixmod_xmit_1v2_ethernet/pyrightconfig.json
Normal file
3
xmit/pixmod_xmit_1v2_ethernet/pyrightconfig.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"reportMissingModuleSource": false
|
||||
}
|
||||
102
xmit/pixmod_xmit_1v2_ethernet/uv.lock
generated
Normal file
102
xmit/pixmod_xmit_1v2_ethernet/uv.lock
generated
Normal file
@ -0,0 +1,102 @@
|
||||
version = 1
|
||||
requires-python = ">=3.10"
|
||||
|
||||
[[package]]
|
||||
name = "micropython-rp2-stubs"
|
||||
version = "1.27.0.post1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "micropython-stdlib-stubs" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/38/32/c41a7cea2919776f0535f0cfb53bbcc045e3feca406e712b4821d56e8d48/micropython_rp2_stubs-1.27.0.post1.tar.gz", hash = "sha256:f65fa6f257f4043190d24e0eefbf238faf61c40e11afb018476c21488a9ea1a8", size = 72154 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/de/4d/466f4688860b76fd31c29d6345a7168ba7e9db026dce10192128f80cecfb/micropython_rp2_stubs-1.27.0.post1-py2.py3-none-any.whl", hash = "sha256:c7566d863f693ac3a69cf496607b5d88a57f9a162922f67f1f086c34cf5f5c2f", size = 94638 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "micropython-stdlib-stubs"
|
||||
version = "1.27.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/9d/c9/7b2b826822db66ee35582fd219379a45c4b3aaa2ac1d3f99e2a87f146cf5/micropython_stdlib_stubs-1.27.0-py3-none-any.whl", hash = "sha256:372070e64b5aadf106d6c11d27e47e9d5d1e157914c740d0ee1d27ee2e34276a", size = 166165 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mpremote"
|
||||
version = "1.27.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "platformdirs" },
|
||||
{ name = "pyserial" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d2/1c/be7d96275379eca70af111a1d4711c77b1afa78f1782582f3ad082e2d228/mpremote-1.27.0.tar.gz", hash = "sha256:6bb75774648091dad6833af4f86c5bf6505f8d7aec211380f9e6996c01d23cb5", size = 31420 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/58/bf/cb9a7f38015c0fec0295b2cd014b830561f224d264f2f303c2ec15d8ef2f/mpremote-1.27.0-py3-none-any.whl", hash = "sha256:11d134c69b21b487dae3d03eed54c8ccbf84c916c8732a3e069a97cae47be3d4", size = 36094 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pixmod-xmit-1v2-ethernet"
|
||||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "mpremote" },
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "micropython-rp2-stubs" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "mpremote" },
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [{ name = "micropython-rp2-stubs" }]
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "4.5.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cf/86/0248f086a84f01b37aaec0fa567b397df1a119f73c16f6c7a9aac73ea309/platformdirs-4.5.1.tar.gz", hash = "sha256:61d5cdcc6065745cdd94f0f878977f8de9437be93de97c1c12f853c9c0cdcbda", size = 21715 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/cb/28/3bfe2fa5a7b9c46fe7e13c97bda14c895fb10fa2ebf1d0abb90e0cea7ee1/platformdirs-4.5.1-py3-none-any.whl", hash = "sha256:d03afa3963c806a9bed9d5125c8f4cb2fdaf74a55ab60e5d59b3fde758104d31", size = 18731 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyserial"
|
||||
version = "3.5"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/1e/7d/ae3f0a63f41e4d2f6cb66a5b57197850f919f59e558159a4dd3a818f5082/pyserial-3.5.tar.gz", hash = "sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb", size = 159125 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/07/bc/587a445451b253b285629263eb51c2d8e9bcea4fc97826266d186f96f558/pyserial-3.5-py2.py3-none-any.whl", hash = "sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0", size = 90585 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff"
|
||||
version = "0.14.14"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/2e/06/f71e3a86b2df0dfa2d2f72195941cd09b44f87711cb7fa5193732cb9a5fc/ruff-0.14.14.tar.gz", hash = "sha256:2d0f819c9a90205f3a867dbbd0be083bee9912e170fd7d9704cc8ae45824896b", size = 4515732 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d2/89/20a12e97bc6b9f9f68343952da08a8099c57237aef953a56b82711d55edd/ruff-0.14.14-py3-none-linux_armv6l.whl", hash = "sha256:7cfe36b56e8489dee8fbc777c61959f60ec0f1f11817e8f2415f429552846aed", size = 10467650 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a3/b1/c5de3fd2d5a831fcae21beda5e3589c0ba67eec8202e992388e4b17a6040/ruff-0.14.14-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:6006a0082336e7920b9573ef8a7f52eec837add1265cc74e04ea8a4368cd704c", size = 10883245 },
|
||||
{ url = "https://files.pythonhosted.org/packages/b8/7c/3c1db59a10e7490f8f6f8559d1db8636cbb13dccebf18686f4e3c9d7c772/ruff-0.14.14-py3-none-macosx_11_0_arm64.whl", hash = "sha256:026c1d25996818f0bf498636686199d9bd0d9d6341c9c2c3b62e2a0198b758de", size = 10231273 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a1/6e/5e0e0d9674be0f8581d1f5e0f0a04761203affce3232c1a1189d0e3b4dad/ruff-0.14.14-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f666445819d31210b71e0a6d1c01e24447a20b85458eea25a25fe8142210ae0e", size = 10585753 },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/09/754ab09f46ff1884d422dc26d59ba18b4e5d355be147721bb2518aa2a014/ruff-0.14.14-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3c0f18b922c6d2ff9a5e6c3ee16259adc513ca775bcf82c67ebab7cbd9da5bc8", size = 10286052 },
|
||||
{ url = "https://files.pythonhosted.org/packages/c8/cc/e71f88dd2a12afb5f50733851729d6b571a7c3a35bfdb16c3035132675a0/ruff-0.14.14-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1629e67489c2dea43e8658c3dba659edbfd87361624b4040d1df04c9740ae906", size = 11043637 },
|
||||
{ url = "https://files.pythonhosted.org/packages/67/b2/397245026352494497dac935d7f00f1468c03a23a0c5db6ad8fc49ca3fb2/ruff-0.14.14-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:27493a2131ea0f899057d49d303e4292b2cae2bb57253c1ed1f256fbcd1da480", size = 12194761 },
|
||||
{ url = "https://files.pythonhosted.org/packages/5b/06/06ef271459f778323112c51b7587ce85230785cd64e91772034ddb88f200/ruff-0.14.14-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:01ff589aab3f5b539e35db38425da31a57521efd1e4ad1ae08fc34dbe30bd7df", size = 12005701 },
|
||||
{ url = "https://files.pythonhosted.org/packages/41/d6/99364514541cf811ccc5ac44362f88df66373e9fec1b9d1c4cc830593fe7/ruff-0.14.14-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1cc12d74eef0f29f51775f5b755913eb523546b88e2d733e1d701fe65144e89b", size = 11282455 },
|
||||
{ url = "https://files.pythonhosted.org/packages/ca/71/37daa46f89475f8582b7762ecd2722492df26421714a33e72ccc9a84d7a5/ruff-0.14.14-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bb8481604b7a9e75eff53772496201690ce2687067e038b3cc31aaf16aa0b974", size = 11215882 },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/10/a31f86169ec91c0705e618443ee74ede0bdd94da0a57b28e72db68b2dbac/ruff-0.14.14-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:14649acb1cf7b5d2d283ebd2f58d56b75836ed8c6f329664fa91cdea19e76e66", size = 11180549 },
|
||||
{ url = "https://files.pythonhosted.org/packages/fd/1e/c723f20536b5163adf79bdd10c5f093414293cdf567eed9bdb7b83940f3f/ruff-0.14.14-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e8058d2145566510790eab4e2fad186002e288dec5e0d343a92fe7b0bc1b3e13", size = 10543416 },
|
||||
{ url = "https://files.pythonhosted.org/packages/3e/34/8a84cea7e42c2d94ba5bde1d7a4fae164d6318f13f933d92da6d7c2041ff/ruff-0.14.14-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:e651e977a79e4c758eb807f0481d673a67ffe53cfa92209781dfa3a996cf8412", size = 10285491 },
|
||||
{ url = "https://files.pythonhosted.org/packages/55/ef/b7c5ea0be82518906c978e365e56a77f8de7678c8bb6651ccfbdc178c29f/ruff-0.14.14-py3-none-musllinux_1_2_i686.whl", hash = "sha256:cc8b22da8d9d6fdd844a68ae937e2a0adf9b16514e9a97cc60355e2d4b219fc3", size = 10733525 },
|
||||
{ url = "https://files.pythonhosted.org/packages/6a/5b/aaf1dfbcc53a2811f6cc0a1759de24e4b03e02ba8762daabd9b6bd8c59e3/ruff-0.14.14-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:16bc890fb4cc9781bb05beb5ab4cd51be9e7cb376bf1dd3580512b24eb3fda2b", size = 11315626 },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/aa/9f89c719c467dfaf8ad799b9bae0df494513fb21d31a6059cb5870e57e74/ruff-0.14.14-py3-none-win32.whl", hash = "sha256:b530c191970b143375b6a68e6f743800b2b786bbcf03a7965b06c4bf04568167", size = 10502442 },
|
||||
{ url = "https://files.pythonhosted.org/packages/87/44/90fa543014c45560cae1fffc63ea059fb3575ee6e1cb654562197e5d16fb/ruff-0.14.14-py3-none-win_amd64.whl", hash = "sha256:3dde1435e6b6fe5b66506c1dff67a421d0b7f6488d466f651c07f4cab3bf20fd", size = 11630486 },
|
||||
{ url = "https://files.pythonhosted.org/packages/9e/6a/40fee331a52339926a92e17ae748827270b288a35ef4a15c9c8f2ec54715/ruff-0.14.14-py3-none-win_arm64.whl", hash = "sha256:56e6981a98b13a32236a72a8da421d7839221fa308b223b9283312312e5ac76c", size = 10920448 },
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user