{"id":2309,"date":"2015-10-04T00:17:31","date_gmt":"2015-10-03T15:17:31","guid":{"rendered":"http:\/\/mirror.boy.jp\/?p=2309"},"modified":"2015-10-06T01:17:36","modified_gmt":"2015-10-05T16:17:36","slug":"raspberry-pi-2-openframeworks-%e3%81%a7i2c%e6%8e%a5%e7%b6%9a%e3%81%ae%e3%82%b8%e3%83%a3%e3%82%a4%e3%83%ad%e3%82%b9%e3%82%b3%e3%83%bc%e3%83%97itg-3200%e3%82%92%e4%bd%bf%e3%81%86","status":"publish","type":"post","link":"https:\/\/mirror.boy.jp\/?p=2309","title":{"rendered":"Raspberry Pi 2 &#038; openFrameworks \u3067I2C\u63a5\u7d9a\u306e\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc(InvenSense ITG-3200)\u3092\u4f7f\u3046"},"content":{"rendered":"<h3>Raspberry Pi2 &amp; openFrameworks\u3067I2C\u63a5\u7d9a\u306e\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc\u3092\u4f7f\u3063\u3066\u307f\u305f<\/h3>\n<p><iframe loading=\"lazy\" src=\"https:\/\/vine.co\/v\/e2ztYvETj1r\/embed\/simple?audio=1\" width=\"600\" height=\"600\" frameborder=\"0\"><\/iframe><script src=\"https:\/\/platform.vine.co\/static\/scripts\/embed.js\"><\/script><br \/>\nInvenSense ITG-3200\u306e\u30d6\u30ec\u30a4\u30af\u30a2\u30a6\u30c8\u30dc\u30fc\u30c9\u3092SwitchScience\u3067\u8cfc\u5165\u3057\u3001\u30bb\u30c3\u30c6\u30a3\u30f3\u30b0\u3084\u30b3\u30fc\u30c9\u306f\u3001<a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/learn.sparkfun.com\/tutorials\/itg-3200-hookup-guide');\"  href=\"https:\/\/learn.sparkfun.com\/tutorials\/itg-3200-hookup-guide\">\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8<\/a>\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f\u3002Raspberry Pi\u306b\u304a\u3051\u308bwiringPi\u3068I2C\u81ea\u4f53\u306e\u30bb\u30c3\u30c6\u30a3\u30f3\u30b0\u306f\u3001\u30b0\u30b0\u308b\u3068\u8272\u3005\u3042\u308b\u306e\u3067openFrameworks\u306e\u90e8\u5206\u306e\u307f\u3002wiringPiI2CSetup\u3092\u4f7f\u3063\u305f\u3089\u3068\u306b\u304b\u304f\u697d\u3067\u3057\u305f\u3002<\/p>\n<h3>openFrameworks\u306e\u30b3\u30fc\u30c9<\/h3>\n<pre><code>\r\n#include \"ofApp.h\"\r\n#include \"wiringPiI2C.h\"\r\n\r\nusing namespace std;\r\n\r\nconst auto itgAddress = 0x69;\r\n\r\nconst char WHO_AM_I = 0x00;\r\nconst char SMPLRT_DIV= 0x15;\r\nconst char DLPF_FS = 0x16;\r\nconst char GYRO_XOUT_H = 0x1D;\r\nconst char GYRO_XOUT_L = 0x1E;\r\nconst char GYRO_YOUT_H = 0x1F;\r\nconst char GYRO_YOUT_L = 0x20;\r\nconst char GYRO_ZOUT_H = 0x21;\r\nconst char GYRO_ZOUT_L = 0x22;\r\n\r\nconst char DLPF_CFG_0 = 1<<0;\r\nconst char DLPF_CFG_1 = 1<<1;\r\nconst char DLPF_CFG_2 = 1<<2;\r\nconst char DLPF_FS_SEL_0 = 1<<3;\r\nconst char DLPF_FS_SEL_1 = 1<<4;\r\n\r\nauto fd = -1;\r\n\r\n\/\/--------------------------------------------------------------\r\nvoid ofApp::setup(){\r\n\r\n        \/\/I2C Setting\r\n        fd = wiringPiI2CSetup(itgAddress);\r\n        cout << \"fd:\" << fd  << \"\\n\";\r\n        cout << \"WHO_AM_I:\" << wiringPiI2CReadReg16(fd,WHO_AM_I) << \"\\n\";       \r\n        cout << \"Write DLPF_FS:\" << wiringPiI2CWriteReg8(fd,DLPF_FS,(DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0)) << \"\\n\";\r\n        cout << \"Write SMPLRT_DIV:\" << wiringPiI2CWriteReg8(fd,SMPLRT_DIV,9) << \"\\n\";\r\n\r\n        ofSetFullscreen(true);  \r\n}\r\n\r\n\/\/--------------------------------------------------------------\r\nvoid ofApp::update(){\r\n\r\n}\r\n\r\n\/\/--------------------------------------------------------------\r\nvoid ofApp::draw(){\r\n\r\n        ofPushMatrix();\r\n\r\n        ofTranslate(0,ofGetHeight()\/2);\r\n\r\n        ofBackground(0);\r\n\r\n        function<int16_t(char H,char L)> getValue = [](char H,char L){\r\n\r\n                int data = 0;\r\n                data = static_cast<int8_t>(wiringPiI2CReadReg8(fd,H)) << 8;\r\n                data += static_cast<int8_t>(wiringPiI2CReadReg8(fd,L));\r\n\r\n                return data;\r\n        };\r\n\r\n        ofSetColor(255);\r\n\r\n        const auto MAX_DATA = 10000;\r\n\r\n        auto x = getValue(GYRO_XOUT_H,GYRO_XOUT_L);\r\n        ofRect(0,0,ofGetWidth()\/3.,ofMap(x,-MAX_DATA,MAX_DATA,ofGetHeight()\/2.,-ofGetHeight()\/2.));\r\n\r\n        ofTranslate(ofGetWidth()\/3,0);\r\n        auto y = getValue(GYRO_YOUT_H,GYRO_YOUT_L);\r\n        ofRect(0,0,ofGetWidth()\/3,ofMap(y,-MAX_DATA,MAX_DATA,ofGetHeight()\/2,-ofGetHeight()\/2));\r\n\r\n        ofTranslate(ofGetWidth()\/3,0);\r\n        auto z = getValue(GYRO_ZOUT_H,GYRO_ZOUT_L);\r\n        ofRect(0,0,ofGetWidth()\/3,ofMap(z,-MAX_DATA,MAX_DATA,ofGetHeight()\/2,-ofGetHeight()\/2));\r\n\r\n        ofPopMatrix();\r\n}\r\n\r\n<\/code><\/pre>\n<p>Raspberry Pi\u7528\u306eopenFrameworks\u304cNightly Build\u3067\u3057\u304b\u52d5\u304b\u305b\u306a\u304b\u3063\u305f\u3002\u3051\u308c\u3069\u3001openFrameworks0.9.0\u304b\u3089C++11\u306b\u306a\u3063\u3066\u305f\u306e\u3067function\u3084\u30e9\u30e0\u30c0\u5f0f\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Raspberry Pi2 &amp; openFrameworks\u3067I2C\u63a5\u7d9a\u306e\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc\u3092\u4f7f\u3063\u3066\u307f\u305f InvenSense ITG-3200\u306e\u30d6\u30ec\u30a4\u30af\u30a2\u30a6\u30c8\u30dc\u30fc\u30c9\u3092SwitchScience\u3067\u8cfc\u5165\u3057\u3001\u30bb\u30c3\u30c6\u30a3\u30f3 &hellip; <a href=\"https:\/\/mirror.boy.jp\/?p=2309\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Raspberry Pi 2 &#038; openFrameworks \u3067I2C\u63a5\u7d9a\u306e\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc(InvenSense ITG-3200)\u3092\u4f7f\u3046<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,106,104,105],"tags":[],"_links":{"self":[{"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2309"}],"collection":[{"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2309"}],"version-history":[{"count":9,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2309\/revisions"}],"predecessor-version":[{"id":2329,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2309\/revisions\/2329"}],"wp:attachment":[{"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mirror.boy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}