Arduino - ์•„๋‘์ด๋…ธ

Intro ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์šด ํ•˜๋“œ์›จ์–ด์™€ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์˜คํ”ˆ์†Œ์Šค ์ „์ž ํ”Œ๋žซํผ ์ดํƒˆ๋ฆฌ์•„ ๋งˆ์‹œ๋ชจ ๋ฐ˜์ง€(Massimo Banzi,๋Œ€ํ•™๊ต์ˆ˜)๊ฐ€ ๊ฐœ๋ฐœ ๋ฐ ๊ณต๊ฐœ ๋น„์ „๊ณต์ž๋ฅผ ์œ„ํ•œ ๊ฐœ๋ฐœ ๋ณด๋“œ ํ•˜๋“œ์›จ์–ด ์ข…๋ฅ˜ $ arduino-cli board listall Board Name FQBN Adafruit Circuit Playground arduino:avr:circuitplay32u4cat Arduino BT arduino:avr:bt Arduino Duemilanove or Diecimila arduino:avr:diecimila Arduino Esplora arduino:avr:esplora Arduino Ethernet arduino:avr:ethernet Arduino Fio arduino:avr:fio Arduino Gemma arduino:avr:gemma Arduino Industrial 101 arduino:avr:chiwawa Arduino Leonardo arduino:avr:leonardo Arduino Leonardo ETH arduino:avr:leonardoeth Arduino Mega ADK arduino:avr:megaADK Arduino Mega or Mega 2560 arduino:avr:mega Arduino Micro arduino:avr:micro Arduino Mini arduino:avr:mini Arduino NG or older arduino:avr:atmegang Arduino Nano arduino:avr:nano Arduino Pro or Pro Mini arduino:avr:pro Arduino Robot Control arduino:avr:robotControl Arduino Robot Motor arduino:avr:robotMotor Arduino Uno arduino:avr:uno Arduino Uno Mini arduino:avr:unomini Arduino Uno WiFi arduino:avr:unowifi Arduino Yรบn arduino:avr:yun Arduino Yรบn Mini arduino:avr:yunmini LilyPad Arduino arduino:avr:lilypad LilyPad Arduino USB arduino:avr:LilyPadUSB Linino One arduino:avr:one ์†Œํ”„ํŠธ์›จ์–ด ์„ค์น˜ arduino-ide - ์•„๋‘์ด๋…ธ ํ™ˆํŽ˜์ด์ง€์— OS๋ณ„๋กœ ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜ ๊ฐ€๋Šฅ arduino cli - Command Line Interface (Linux, Win์šฉ) REFERENCE ์•„๋‘์ด๋…ธ - https://www.arduino.cc

2023-10-30 ยท (updated 2023-10-31) ยท 154 words

Arduino-cli - ์•„๋‘์ด๋…ธ ๋ช…๋ น๋ผ์ธ ์‚ฌ์šฉ

Intro arduino-cli๋Š” ์•„๋‘์ด๋…ธ IDE์˜ ๋ช…๋ น๋ผ์ธ ํˆด์ด๋‹ค. (์†Œํ”„ํŠธ์›จ์–ด ํˆด) Shell Script๋กœ ์—ฌ๋Ÿฌ ๋ฒˆ๊ฑฐ๋กœ์šด ์ž‘์—…์„ ์ž๋™ํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค. nvim ์ด๋‚˜ vim์—์„œ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. nvim์„ ์ค‘์‹ฌ์œผ๋กœ ์ฝ”๋“œ ์ž‘์„ฑ, ์ปดํŒŒ์ผ, ๋””๋ฒ„๊น…์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์„ค์น˜ ๋ฐ ์‚ฌ์šฉํ™˜๊ฒฝ: windows, windows-wsl2-alpine, linux-ubuntu Intall: Windows reference: https://dumblebots.com/2020/08/02/arduino-cli-getting-started-windows/ ์œˆ๋„์šฐ์ฆˆ์šฉ arduino-cli.exe๋ฅผ ๋‹ค์šด๋ฐ›์•„ ์„ค์น˜, dos-shell ๋˜๋Š” powershell์—์„œ ๊ฒฝ๋กœ ์ถ”๊ฐ€ํ•˜๊ณ  ์‚ฌ์šฉ ์ด๋ฅผ ์œˆ๋„์šฐ์ฆˆ wsl2 ๊ธฐ๋ฐ˜์˜ ๋ฆฌ๋ˆ…์Šค์—์„œ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ /mnt/c/<์ดํ•˜๊ฒฝ๋กœ>๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋‹ค. PATH์— ์ถ”๊ฐ€. Install: Linux ์ผ๋ฐ˜์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ ~/bin์— ์„ค์น˜: PATH์— ์ถ”๊ฐ€ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh Install: windows-wsl2-alpine reference: https://github.com/dorssel/usbipd-win/wiki/WSL-support ์•„๋‘์ด๋…ธ ์žฅ์น˜๋ฅผ USB์— ์—ฐ๊ฒฐํ•œ๋‹ค. wsl2-alpine - gcompat, usbip, hwdata ์„ค์น˜ gcompat์€ ardunino-cli๋กœ ์ปดํŒŒ์ผํ•  ๋•Œ ld-linux-x86-64.so.2 ์‚ฌ์šฉํ•˜๋Š”๋ฐ alpine์€ musl ๊ธฐ๋ฐ˜์ด๋ฏ€๋กœ ํ˜ธํ™˜ ์ง€์› ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค. usbip๋Š” usbipd์˜ ํด๋ผ์ด์–ธํŠธ ํŒจํ‚ค์ง€ hwdata๋Š” USB๋“ฑ์˜ ์žฅ์น˜ํŒŒ์ผ ardunino-cli ์‚ฌ์šฉ์ž ์„ค์น˜์‹œ์— USB์žฅ์น˜ ์†Œ์œ ๊ถŒ ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ์žฅ์น˜ ์†Œ์œ ๊ถŒ์„ ํ•ด๋‹น ์‚ฌ์šฉ์ž๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. windows - usbipd-win ์„ค์น˜ ๋ฐ ์„ค์ • usbipd๋Š” ์œˆ๋„์šฐ์ฆˆ์—์„œ wsl2 ๋“ฑ์— USB ์žฅ์น˜๋ฅผ ๊ณต์œ ํ•ด์ฃผ๋Š” ๋ฐ๋ชฌ ํ”„๋กœ๊ทธ๋žจ ๋ฐ˜๋“œ์‹œ ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•ด ์ฃผ์–ด์•ผํ•œ๋‹ค. ์•„๋‘์ด๋…ธ ์žฅ์น˜๋ฅผ wsl2์— ๋ถ™์—ฌ ์ฃผ์—ˆ์„ ๊ฒฝ์šฐ ์œˆ๋„์šฐ์—์„œ๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ์ด ๋ฐ๋ชฌ์€ usbip ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ํ†ตํ•ด USB์žฅ์น˜(์—ฌ๊ธฐ์—์„œ๋Š” ์•„๋‘์ด๋…ธ)๋ฅผ ๊ณต์œ  # WSL2-Alpine Linux: Pre-Package Install doas apk update doas apk add gcompat linux-tools-usbip hwdata # Windows-Powershell # ๊ด€๋ฆฌ์ž๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰, ์œˆ๋„์šฐ์ฆˆ ์žฌ๋ถ€ํŒ…์‹œ ๋‹ค์‹œ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. # ์—ฐ๊ฒฐ์‹œ ์ž๋™ attach ๋ฐฉ๋ฒ•์„ ๋ชจ์ƒ‰ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. # usbipd๋ฅผ ์„ค์น˜ํ•˜๊ณ  wsl list๋ฅผ ํ†ตํ•ด ์•„๋‘์ด๋…ธ์˜ busid๋ฅผ ํ™•์ธํ•˜๊ณ  ์ด๋ฅผ ์—ฐ๊ฒฐํ•˜๊ณ  ํ™•์ธ. winget usbipd usbipd wsl list usbipd wsl attach --busid=2-2 usbipd wsl list # WSL2-Alpine Linux: arduino-cli Install # usb ์ง€์›์—ฌ๋ถ€ ํ™•์ธ # ardunino-cli ์„ค์น˜ ๋ฐ ํŒจ์Šค ์„ค์ • # ์žฅ์น˜ ์†Œ์œ ๊ถŒ ํ˜„ ์‚ฌ์šฉ์ž๋กœ ๋ณ€๊ฒฝ lsusb curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh export PATH=$PATH:$HOME/bin arduino-cli board list doas chown -R <user_id>:<user_id> /dev/ttyACM0 arduino-cli --help Install: debian, ubuntu lsusb curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh export PATH=$PATH:$HOME/bin arduino-cli board list sudo chown -R <user_id>:<user_id> /dev/ttyACM0 arduino-cli --help ์‹œ์ž‘ํ•˜๊ธฐ reference: https://arduino.github.io/arduino-cli/0.35/getting-started/ ์•„๋ž˜๋Š” Ardunino UNO์˜ ๊ฒฝ์šฐ # ๋„์›€๋ง arduino-cli help arduino-cli help core # ์„ค์ • ํŒŒ์ผ ์ดˆ๊ธฐํ™” (~/.arduino15/arduino-cli.yaml) arduino-cli config init # ์žฅ์น˜์™€ ์—ฐ๊ฒฐํ•˜๊ธฐ (Arduino UNO) arduino-cli board list arduino-cli core update-index arduino-cli core install arduino:avr arduino-cli board listall mkr # list์˜ ๋ณด๋“œ๊ฐ€ Unknown์œผ๋กœ ๋‚˜์˜ฌ ๊ฒฝ์šฐ arduino-cli board list # ์†Œ์Šค ์ž‘์„ฑ (๋™์ผํ•œ ์Šค์ผ€์น˜ ์ด๋ฆ„์˜ ํด๋”์™€ ํŒŒ์ผ์ด ํ•„์š”) # ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•: arduino-cli sketch new myfirst && vim myfirst/myfirst.ino mkdir myfirst cat<<EOF > myfirst/myfirst.ino void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); } # ์ปดํŒŒ์ผ๊ณผ ์—…๋กœ๋“œํ•˜๊ธฐ (upload์‹œ ์ž๋™ ์ปดํŒŒ์ผ) # ์žฅ์น˜๋ช… ํ™•์ธ: ardunino-cli board list # ์ปดํŒŒ์ผ(-b) arduino-cli compile --fqbn arduino:avr:uno myfirst # ์—…๋กœ๋“œ (-u) arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno myfirst # ์ปดํŒŒ์ผ(-b) & ์—…๋กœ๋“œ(-u) arduino-cli compile -p /dev/ttyACM0 -u arduino:avr:uno myfirst REFERENCE ardunino-cli ์„ค์น˜ ๋ฐ ์‹œ์ž‘ - https://arduino.github.io/arduino-cli/0.35/getting-started/ ์œˆ๋„์šฐ์ฆˆ ์„ค์น˜ ๋ฐ ์•ˆ๋‚ด - https://dumblebots.com/2020/08/02/arduino-cli-getting-started-windows/ wsl2์—์„œ usb์žฅ์น˜ ์—ฐ๊ฒฐ - https://github.com/dorssel/usbipd-win ardunino-cli linux install - https://m.blog.naver.com/roboholic84/221815428642

2023-10-30 ยท (updated 2023-10-31) ยท 437 words

Dockerfile - run, cmd, entrypoint ์ฐจ์ด

Dockerfile ์—์„œ RUN, CMD, ENTRYPOINT ์ฐจ์ด RUN - ๋„์ปค์ด๋ฏธ์ง€ ์ƒ์„ฑ์‹œ ๋™์ž‘ CMD - ๋„์ปค์ด๋ฏธ์ง€ ์‹คํ–‰์‹œ ๋™์ž‘ (๋Œ€์ฒด ๊ฐ€๋Šฅ) ENTRYPOINT - CMD์™€ ๊ฐ™์œผ๋‚˜ ์‹คํ–‰์‹œ ๋ฐ˜๋“œ์‹œ ๋™์ž‘ Dockerfile - RUN # create log script vi log-event.sh ... #!/bin/sh echo `date` $@ >> log.txt cat log.txt ... chmod u+x log-event.sh # create Docker Image vi Dockerfile ... FROM alpine ADD log-event.sh / RUN ["/log-event.sh","image created"] # ์ƒ์„ฑ์‹œ ๋™์ž‘ CMD ["/log-event.sh","container started"] # ์‹คํ–‰์‹œ ๋™์ž‘ ... docker build -t myimage . # Run Docker Image - RUN์€ ์ด๋ฏธ์ง€ ์ƒ์„ฑ์‹œ์— ๋™์ž‘ํ–ˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. docker run myimage Wed Sep 27 07:10:26 UTC 2023 image created Wed Sep 27 07:36:10 UTC 2023 container started docker run myimage Wed Sep 27 07:10:26 UTC 2023 image created Wed Sep 27 07:36:21 UTC 2023 container started Dockerfile - CMD, ENTRYPOINT ์—ฌ๋Ÿฌ๊ฐœ์˜ CMD # Create Docker Image vi Dockerfile ... FROM alpine ADD log-event.sh / RUN ["/log-event.sh","image created"] # ์ƒ์„ฑ์‹œ ๋™์ž‘ CMD ["/log-event.sh","container started"] # ์‹คํ–‰์‹œ ๋™์ž‘ (๋ฌด์‹œ๋จ) CMD ["/log-event.sh","container running"] # ์‹คํ–‰์‹œ ๋™์ž‘ (๋งˆ์ง€๋ง‰CMD์ฒ˜๋ฆฌ) ... docker build -t myimage . # Run Docker Image docker run myimage Wed Sep 27 07:10:26 UTC 2023 image created Wed Sep 27 07:23:09 UTC 2023 container running CMD์™€ ENTRYPOINT # Create Docker Image vi Dockerfile ... FROM alpine ADD log-event.sh / RUN ["/log-event.sh","image created"] # ์ƒ์„ฑ์‹œ ๋™์ž‘ ENTRYPOINT ["/log-event.sh"] # ์‹คํ–‰์‹œ ๋™์ž‘ CMD ["container started"] # ์‹คํ–‰์‹œ ๋™์ž‘ ... docker build -t myimage . # Run Docker Image docker run myimage Wed Sep 27 07:10:26 UTC 2023 image created Wed Sep 27 07:23:09 UTC 2023 container started # Run Docker Image with argument docker run myimage custom event Wed Sep 27 07:10:26 UTC 2023 image created Wed Sep 27 07:24:31 UTC 2023 custom event REFERENCE Difference Between run, cmd and entrypoint in a Dockerfile - https://www.baeldung.com/ops/dockerfile-run-cmd-entrypoint Entrypoint vs cmd - https://bluese05.tistory.com/77

2023-09-27 ยท (updated 2023-10-13) ยท 298 words

Graphic Card - ๊ทธ๋ž˜ํ”ฝ์นด๋“œ

Nvidia Quadro 5000 ์ตœ์‹  ๋“œ๋ผ์ด๋ฒ„ ์„ค์น˜: windows 10, 11 dp ์—ฐ๊ฒฐ: ๊ทธ๋ž˜ํ”ฝ ์ถœ๋ ฅ์˜ ์ตœ์ ์€ ํ˜„์žฌ๋กœ์„œ๋Š” dp์ด๋‹ค. dp์„ ์„ ์—ฐ๊ฒฐ ๋‹ค๋ฅธ ์„ ์ด ์žˆ์„ ๊ฒฝ์šฐ ์ œ๊ฑฐํ•˜๋ฉด ๋””ํดํŠธ๋กœ ํ™”๋ฉด ์ถœ๋ ฅ์ด ๋œ๋‹ค.

2023-09-19 ยท 27 words

Openresty - Scalable Web Platform NGINX with Lua

INTRO openresty๋Š” nginx์™€ lua ๊ธฐ๋ฐ˜์˜ ์›น๊ฐœ๋ฐœ ํ”Œ๋žซํผ์ด๋‹ค. lua๋Š” luajit ์„ ์‚ฌ์šฉํ•˜๊ณ  ์—”์ง„์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค. ์„œ๋ฒ„์—์„œ ๋™์ž‘ํ•œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์€ ํŒจํ‚ค์ง€๋ฅผ ์ง€์›ํ•œ๋‹ค. ์—ฌ๊ธฐ์—์„œ๋Š” docker ์ด๋ฏธ์ง€๋กœ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•œ๋‹ค. System Info: RaspberryPi 3 Model B Rev 1.2 OS: Raspbian (Debian 11, Bullseye) Docker: version 24.0.5 Getting Started Hello World # Install Docker and Relogin after exit curl -sSL https://get.docker.com | sh sudo usermod -aG docker $usermod exit ... docker run hello-world # Docker Image get docker pull openresty/openresty:alpine # Setup mkdir ~/www cd ~/www mkdir conf html vi conf/nginx.conf ... worker_processes 1; error_log error.log; events { worker_connections 1024; } http { server { listen 8000; location / { default_type text/html; content_by_lua ' ngx.say("<p>hello world!</p>") '; } } } ... # Run openresty docker image docker run --name mresty --rm --volume `pwd`/conf/:/usr/local/openresty/nginx/conf/ \ -p 127.0.0.1:8000:8000 openresty/openresty:alpine # docker process check docker ps # openresty web server test curl localhost:8000 <p>hello world!</p> Openresty Comandline Utility # version check resty -v # Hello World resty -e 'print("Hello World")' echo 'print("Hello World")' > hello.lua resty hello.lua # resty ngx module test time resty -e 'gnx.sleep(1) ngx.say("done")' resty -e 'local sock = ngx.socket.tcp() print(socke:connect("openresty.com",443))' resty -e 'ngx.thread.wait(ngx.thread.spawn(function () print("in thread!") end))' mkdir lua/ vim lua/test.lua ... local _M = {} function _M.hello() print("Hello") end return _M ... resty -e 'require "test".hello()' # Error resty -I lua/ -e 'require "test".hello()' # Hello resty -e 'local ok, stdout = require "resty.shell".run([[echo ok]]) print(stdout)' # ok resty --shdict 'dogs 10m' -e 'print(ngx.shared.dogs:set("age",11))' # truenilfalse resty --shdict 'dogs 7m' --shdict 'cats 5m' -e 'print(ngx.shared.dogs, " ", ngx.shared.cats)' resty --http-conf 'lua_regex_match_limit 102400;' -e 'print "ok"' # Bench Test echo 'local a = 0 for 1, 1e8 do a = a+1 end print(a)' > bench.lua time resty -joff bench.lua # without Jit Compiler time resty bench.lua # with Jit Compiler (Fast) resty -jv bench.lua resty -jdump bench.lua | less # Help resty -h | less # See Help restydoc resty-cli # See Document Structure and Lua Module Create Project Folder and Modules mkdir test-module cd test-module mkdir logs conf lua vim lua/hello.lua ... local _M = {} function _M.greet(name) ngx.say("Greetings from ", name) end return _M ... Setup nginx.conf vim conf/nginx.conf ... worker_processes 1; events { worker_connections 1024; } http { # Lua module Preload for performance and Cache init_by_lua_block { require "hello" } # add module path to lua package path: $prefix means nginx -p option value lua_package_path "$prefix/lua/?.lua;;" # Server Setup: port, lua block... server { listen 8080 reuseport; location / { content_by_lua_block { local hello = require "hello" hello.greet("a Lua module") } } } } ... Server start and Test # server configuration test nginx -p $PWD/ -t # server start nginx -p $PWD/ # Chech Error Log tail logs/error.log # client request test : Browser also available curl 'http://127.0.0.1:8080' Greetins from a Lua module Server Admin # check server process ps aux | grep nginx | grep -v /tmp/ pgrep -l nginx # Edit nginx.conf vim conf/nginx.conf # Server Restart (After editting of nginx.conf) kill -HUP `cat logs/nginx.pid` # client request again curl 'http://127.0.0.1:8080' Build Develop Environment Makefile์„ ๋งŒ๋“ค๊ณ  ๋„์ปค์ด๋ฏธ์ง€๋ฅผ ์ œ์–ดํ•˜๊ณ  ๋กœ๊ทธ ๋“ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์„ ๋งŒ๋“ ๋‹ค. Makefile conf/nginx.conf Test REFERENCE awesome-resty - https://github.com/bungle/awesome-resty ...

2023-09-16 ยท (updated 2023-09-27) ยท 566 words