기본 콘텐츠로 건너뛰기

ESP8266/nodemcu에서 servo사용하기

https://github.com/milikiller/nodemcu-firmware 에 보니 servo 객체가 있다.

servo를 다루는 것은 프로그램으로 pwm을 구현해도 되지만 잡음 문제도 있고 신경쓰이는 부분이 많으므로 저수준에서 구현된 것을 쓰도록 하자.

일단 firmware 를 다시 빌드하려고 보니

make
DEPEND: xtensa-lx106-elf-gcc -M -Os -Os -ffunction-sections -fno-jump-tables -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -DLWIP_OPEN_SRC -DPBUF_RSV_FOR_WLAN -DEBUF_LWIP -I include -I ./ -I ../../include/ets -I ../libc -I ../platform -I ../lua -I ../wofs -I ../include -I ./ -I ../../include -I ../../include/eagle user_main.c
/bin/sh: xtensa-lx106-elf-gcc: command not found
xtensa-lx106-elf-gcc -Os -Os -ffunction-sections -fno-jump-tables -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -DLWIP_OPEN_SRC -DPBUF_RSV_FOR_WLAN -DEBUF_LWIP   -I include -I ./ -I ../../include/ets -I ../libc -I ../platform -I ../lua -I ../wofs -I ../include -I ./ -I ../../include -I ../../include/eagle  -o .output/eagle/debug/obj/user_main.o -c user_main.c
make[2]: xtensa-lx106-elf-gcc: No such file or directory
make[2]: *** [.output/eagle/debug/obj/user_main.o] Error 1
make[1]: *** [.subdirs] Error 2
make: *** [.subdirs] Error 2

보다시피 xtensa-lx106-elf-gcc 를 찾는다.
xtensa lx106 용 gcc toolchain이 필요한데...

https://github.com/pfalcon/esp-open-sdk 에서 설치해보도록 하자.

OS X의 경우 case-sensetive 문제로 빌드의 애로사항이 있으니 가상 디렉토리를 만들어서 mount 하자
$ sudo hdiutil create ~/Documents/case-sensitive.dmg -volname "case-sensitive" -size 10g -fs "Case-sensitive HFS+"
$ sudo hdiutil mount ~/Documents/case-sensitive.dmg
$ cd /Volumes/case-sensitive
이런 식이다.
실제로 빌드해보니 2.67GB 정도 차지하니 무식하게 -size 10g 아니하고 -size 3g정도로 해도 무방하다.

http://www.esp8266.com/viewtopic.php?f=21&t=1432
일단 성격이 급하신 분은 여기에서 0x00000.bin, 0x10000.bin이 있는 파일을 받아서 사용하시고

빌드를 해서 쓰려면 계속 따라가보자.
OS X 한정인 얘기지만 make해보면 한참 열심히 빌드를 하다가 오류를 발생한다.
https://github.com/pfalcon/esp-open-sdk/issues/45 이런 오류인 것.
은근 이쪽은 OS X보다 Linux환경을 쓰시는 분들이 많은가보다.

잊고 있다가 최근 글을 보니
idserda commented 4 days ago
Probably not the best solution, but this makes it compile:
In esp-open-sdk/crosstool-NG/.build/src/gcc-4.8.2/gcc, add this line somewhere at the top:
#include <stddef.h>
of the following files:
graphite.c 
graphite-blocking.c 
graphite-clast-to-gimple.c
graphite-dependences.c 
graphite-interchange.c 
graphite-optimize-isl.c 
graphite-poly.c 
graphite-scop-detection.c 
graphite-sese-to-poly.c
불완전하지만 이런 해결법을 내놓아서 esp-open-sdk/crosstool-NG/.build/src/gcc-4.8.2/gcc 경로 아래 graphite*.c들 맨 첫줄에 #include <stddef.h> 를 죄다 추가해줬다.
저장하고 make.
어쨌든 이러면 꽤 길도 지루한 시간 동안 커다란 build 파일을 만들고 xtensa toolchain이 완성이 된다.


export PATH=/Volumes/case-sensitive/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

이런 식으로 toolchain을 경로에 넣고 다시 https://github.com/milikiller/nodemcu-firmware 을 clone한 경로로 가서 make를 해준다.

별 오류가 없다면 bin/ 경로 아래에

$ ll
total 760
drwxr-xr-x   7 spectrum  staff     238 Apr 27 04:18 ./
drwxr-xr-x  19 spectrum  staff     646 Apr 21 05:04 ../
-rw-r--r--   1 spectrum  staff      79 Apr 20 05:03 .gitignore
-rw-r--r--   1 spectrum  staff   45872 Apr 27 04:18 0x00000.bin
-rw-r--r--   1 spectrum  staff  325872 Apr 27 04:18 0x10000.bin
-rw-r--r--   1 spectrum  staff    4096 Apr 20 05:03 blank.bin
-rw-r--r--   1 spectrum  staff     128 Apr 20 05:03 esp_init_data_default.bin
bin $ ls

이런 식으로 0x00000.bin과 0x10000.bin을 볼 수 있다.
준비는 끝. flash 하자. GPIO0은 GND로 연결하고 리셋 한번.

/<esptool이 있는 경로>/esptool -p /dev/tty.<esp8266이 연결된 포트> -b 230400 write_flash 0x00000 0x00000.bin 0x10000 0x10000.bin

flash가 끝나면 다시 GPIO0를 원래대로 하고 리셋.
콘솔 접속 후 servo 객체가 있는 것을 확인한다.
사용법은 간단.

setup(id, pin, servo pulse length) - Start generating servopulses on selected pin
position(id, servo pulse length) - Change servo pulse length at selected ID 
stop() - Stop timer for servo pulse generator

이게 전부.
이렇게 번거로운 과정들을 자꾸 겪다보니 어짜피 Renoise말곤 딱히 시퀀서도 안쓰고 멀티미디어도 안하는데 내가 왜 OS X를 쓰나 싶은 생각이 자꾸만 든다 -_ㅜ)
하긴 맥은 iOS 개발 셔틀이었지;;

댓글

이 블로그의 인기 게시물

세상 간단한 https(+secured websocket): Caddy

nginx, apache2 같은 걸로 매번 certbot 연동을 통해 https 하는게 지겨워서 알아보니 Caddy라는게 있더라. 설치법은 강하게 크기 위해 알아서 해본다. # cat /etc/caddy/Caddyfile your.shitty.site:8123 {   proxy / localhost:9123 {     websocket     transparent   } } 이건 외부에서 8123으로 들어오는 걸 내부적으로 9123로 맞춰서 https 맞춰주는 reverse proxy. 만일 port를 생략하면 # cat /etc/caddy/Caddyfile your.shitty.site {   proxy / localhost:9123 {     websocket     transparent   } } 기본포트인 443으로 되어 https://your.shitty.site 로 접속이 된다. 요새 말썽이던 cloudflare 버리고 netlify domain이랑 caddy를 쓰니까 앓던 이가 빠진 느낌. 이 조합은 당분간 계속 써야겠다 싶다.

LG G Pro 2 Custom Rom +Rooting 기록

선 루팅 https://forum.xda-developers.com/lg-g3/general/guide-root-lg-firmwares-kitkat-lollipop-t3056951 1.2버전 스크립트 모드로. echo Looking for LG serial port.. echo. adb.exe wait-for-device 여기에서 정체 상태여서 강제로 adb kill-server 했더니 알아서 재부팅하심. 폰에선 "펌웨어 업데이트"화면이 나오고 Phone found at COM5! Rooting phone.. If you don't see the SuperSu installer script runs within about a minute, then the root failed. Author : blog.lvu.kr SPECIAL COMMAND : ENTER, LEAVE ## 이런 상황이 됨. #이 느린 속도로 하나씩 증가하고 있음. 한 시간 기다려도 성과없음. 뭐 몇번해봐도 안되고 결국 불안하긴 하지만 kingroot.net  로 설치 롤리팝이니까  https://drive.google.com/file/d/0B4kfGU1z_PClQ3AyM2lKOGR1S3M/view  이걸 받아서 압축 풀기. d838recovery.bat 만 있어서 당황스럽긴한데 실행하고 1번 하니까 리커버리 모드 진입까진 잘 되는 듯. adb sideload 라는게 있어서 해봄. Advance에서 adb sideload 선택하고 USB연결한 PC에서 adb sideload RR-N-v5.8.5-20171010-d838-Final.zip 하니까 착착 잘 진행됨. 이제 흉측한 U+LTE 가 없어짐. ㅇㅋ 군더더기 없고 깔끔한데 남은 건 gapps 를 설치해야함. http://opengapps.org/  를 권해줘서 갔는데 지옥 느림. ARM + 7.1 + stock 이 기본이...