Raspberry Pi 2 + Mono 3.12.0 + Raspberry# IO で GPIO を使ったアプリケーションを書いてみる - しばやん雑記 ã§ã¯ Raspberry# IO ã使ã£ã¦ GPIO ãæä½ãã¦ã¿ã¾ããããä»åã¯ã¡ãã£ã¨è¤éã§ãã A/D ã³ã³ãã¼ã¿ã¼ã使ã£ã¦ã¢ããã°ã®å¤ãåå¾ãã¦ã¿ã¾ããã
ãã£ãã㯠Raspberry# IO ã Raspberry Pi 2 ã¸ã®å¯¾å¿ã追å ãããã£ã½ãã®ãçºè¦ãããã¨ã§ãã
ããããæ®å¿µãªãã¨ã«ã¾ã Raspberry# IO ã§ã¯ SPI ã使ã£ãå¦çãè¡ããªãã£ãã®ã§è«¦ãã¾ããã
ä»å㯠A/D ã³ã³ãã¼ã¿ã¼ã¨ã㦠MCP3002 ã使ã£ã¦ããã®ã§æ¤ç´¢ããã¨ããã以ä¸ã®è¨äºãã¨ã¦ãåèã¨è¨ãããã®è¨äºã«åºä¼ããªããã°ä»æ¥ã¯å¯ããªããããã®å¢ãã§ããã
アナログ値を測る(ADコンバータ使用)(WebIOPi利用)
ã¨ã¦ãåããããã説æããã¦ããã®ã§ãåå¿è ã®ç§ã§ãç°¡åã«ä½¿ããã¨ãåºæ¥ã¾ãããã¨ããããã§ãã¾ã㯠WebIOPi ã使ã£ã¦å¤ãåå¾ãããã¨ãåªå ãã¦ã¿ã¾ããã
SPI ã®æå¹å
ããã©ã«ãã§ã¯ç¡å¹åããã¦ãããããªã®ã§ sudo raspi-config ãå®è¡ãã¦æå¹åãã¾ããã
ãã®å¾ãæå¹åãããã¨ããã©ã¤ãããã¼ããããã¨èãããã®ã§ãã¨ãããã yes ã¨çãã¦ããã¾ãã
è¨å®ãçµãã£ããåèµ·åãè¦æ±ãããã®ã§ãåèµ·åå¾ã« /dev/spi* ãåå¨ãã¦ããã確èªãã¾ãã
pi@raspberrypi ~ $ ls -l /dev/spi* crw-rw---T 1 root spi 153, 0 Jan 1 1970 /dev/spidev0.0 crw-rw---T 1 root spi 153, 1 Jan 1 1970 /dev/spidev0.1
ããã¤ã¹ãè¦ãã¦ããã° OK ã§ãã
WebIOPi ã®ã¤ã³ã¹ãã¼ã«
WebIOPi ã®ã¤ã³ã¹ãã¼ã«ã¯ SourceForge.net ããã½ã¼ã¹ããã¦ã³ãã¼ãã㦠setup.sh ãå©ãã ããªã®ã§ãå²ã¨ãµã¯ãã¨çµããã¾ãã
WebIOPi - Browse Files at SourceForge.net
ä»å㯠0.7.1 ããã¦ã³ãã¼ããã¦ä½¿ãã¾ããããæ°ã«ãªãè¨è¿°ãããã°ã§çºè¦ãã¾ããã
WebIOPi currently does not support Raspberry Pi 2 yet, but some good things are coming. Stay tuned for updates.
WebIOPi 0.7.1 with Weaved IoT Kit | trouch.com
ã¨æ¸ãã¦ããã¾ããããã¨ããããåããã®ã§è¯ãã¨ãã¾ãã
ã¹ã¯ãªããã®å®è¡
å ã»ã©ã®è¨äºã«ãããµã³ãã«ã³ã¼ãã§ã¯å®è¡æã«ã¨ã©ã¼ã«ãªã£ã¦ãã¾ã£ãã®ã§ãæ°ãããã¼ã¸ã§ã³ã§ãåä½ããããã«æãå ãã¦ã¿ã¾ããã
import webiopi from webiopi.devices.analog.mcp3x0x import MCP3002 webiopi.setDebug() mcp = MCP3002() while 1: ch0 = mcp.analogRead(0) webiopi.debug( "Ch0 : " + str(ch0) ) webiopi.sleep( 1.0 )
æ°ãããã¼ã¸ã§ã³ã® WebIOPi ã«ã¯ MCP3002 ç¨ã®ã¯ã©ã¹ãç¨æããã¦ããã®ã§ãããããã®ã¾ã¾ä½¿ããã¨ã«ãã¾ããããã®ã¹ã¯ãªãããå®è¡ããçµæã¯ä»¥ä¸ã®éãã
ä»åã¯ãã©ããã©ã³ã¸ã¹ã¿ã使ã£ã¦ããã®ã§ãã¹ãã¼ããã©ã³ã®ã©ã¤ãã使ã£ã¦æãããå¤åããã¦ã¿ãã¨ãããã¡ããã¨åºåãããå¤ãå¤ããã¾ããã
ã¨ããããåä½ç¢ºèªã¯åºæ¥ãã®ã§ãC# ãã使ãæ¹æ³ãæ¢ã£ã¦ã¿ããã¨æãã¾ãã