{"id":1069,"date":"2017-04-17T15:48:30","date_gmt":"2017-04-17T14:48:30","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=1069"},"modified":"2017-04-18T20:09:37","modified_gmt":"2017-04-18T19:09:37","slug":"using-grove-devices-to-the-ev3","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2017\/using-grove-devices-to-the-ev3","title":{"rendered":"Using Grove devices to the EV3"},"content":{"rendered":"<p>After David Lechner announced ev3dev support for it I&#8217;ve been planning to offer myself a couple of <a href=\"https:\/\/www.dexterindustries.com\/brickpi3-tutorials-documentation\/\">BrickPi 3 from Dexter Industries<\/a> (just one is not enough since the BrickPi 3 suports daisy chaining).<\/p>\n<p>While I wait for european distributors to sell it (and my budget to stabilize) and since I&#8217;m also playing with magnets, I ordered a <a href=\"http:\/\/mindsensors.ddns.net\/index.php?module=pagemaster&amp;PAGE_user_op=view_page&amp;PAGE_id=209\">mindsensors.com Grove adapter<\/a> so I can start testing Grove devices with my Ev3. Also got two Grove devices from Seeed Studio at my local robotics store, will start with the easiest one: <a href=\"http:\/\/wiki.seeed.cc\/Grove-Electromagnet\/\">Grove &#8211; Electromagnet<\/a>.<\/p>\n<p>ev3dev doesn&#8217;t have a Grove driver yet but since the adapter is an I2C device it recognizes it and configures it as an I2C host:<\/p>\n<pre>[\u00a0 563.590748] lego-port port0: Added new device 'in1:nxt-i2c-host'\r\n[\u00a0 563.795525] i2c-legoev3 i2c-legoev3.3: registered on input port 1<\/pre>\n<p>Addressing the Grove adpter is easy, just need to follow the ev3dev documentation (<a href=\"http:\/\/docs.ev3dev.org\/projects\/lego-linux-drivers\/en\/ev3dev-jessie\/i2c.html\">Appendix C : I2C devices<\/a>):<\/p>\n<pre>robot@ev3dev:~$ ls \/dev\/i2c-in*\r\n\/dev\/i2c-in1\r\n\r\nrobot@ev3dev:~$ udevadm info -q path -n \/dev\/i2c-in1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\/devices\/platform\/legoev3-ports\/lego-port\/port0\/i2c-legoev3.3\/i2c-3\/i2c-dev\/i2c-3<\/pre>\n<p>So the Grove adapter is at I2C bus #3. According to mindsensors.com <a href=\"http:\/\/mindsensors.ddns.net\/index.php?module=documents&amp;JAS_DocumentManager_op=viewDocument&amp;JAS_Document_id=271\">User Guide<\/a>, it&#8217;s address is 0x42. That&#8217;t the unshifted address but fot i2c-tools we need to use the shifted address (0x21 &#8211; at the end of the ev3dev Appendix C doc there is a table with both addresses).<\/p>\n<pre>robot@ev3dev:~$ sudo i2cdump 3 0x21\r\n\r\n\u00a0\u00a0\u00a0\u00a0 0\u00a0 1\u00a0 2\u00a0 3\u00a0 4\u00a0 5\u00a0 6\u00a0 7\u00a0 8\u00a0 9\u00a0 a\u00a0 b\u00a0 c\u00a0 d\u00a0 e\u00a0 f\u00a0\u00a0\u00a0 0123456789abcdef\r\n00: 56 31 2e 30 32 00 00 00 6d 6e 64 73 6e 73 72 73\u00a0\u00a0\u00a0 V1.02...mndsnsrs\r\n10: 47 61 64 70 74 6f 72 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 Gadptor.........\r\n20: 4a 61 6e 20 30 34 20 32 30 31 35 00 31 32 46 31\u00a0\u00a0\u00a0 Jan 04 2015.12F1\r\n30: 38 34 30 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 840.............\r\n40: 00 97 03 32 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 .??2............\r\n50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\n60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\n70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\n80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\n90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\na0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\nb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\nc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\nd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\ne0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................\r\nf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\u00a0\u00a0\u00a0 ................<\/pre>\n<p>Acording to the User Guide, this is the expected content of the first 24 registers:<\/p>\n<p>0x00-0x07: Software version \u2013 Vx.nn<br \/>\n0x08-0x0f: Vendor Id &#8211; mndsnsrs<br \/>\n0x10-0x17: Device ID \u2013 Gadptor<\/p>\n<p>So I have a v1.02 Grove adapter.<\/p>\n<p>To use the Grove &#8211; Electromagnet I just need to send a &#8220;T&#8221; (0x54) to the Command Register (0x41) to set the Grove Adapter into &#8220;Transmit&#8221; mode and next set the Operation Mode, which can be &#8220;Digital_0&#8221; (sending 0x02 to the Operation Mode register at 0x42) or &#8220;Digital_1&#8221; (sending 0x03 to the Operation Mode register).<\/p>\n<p>So to turn the electromagnet ON:<\/p>\n<pre>sudo i2cset -y 3 0x21 0x41 0x54\r\nsudo i2cset -y 3 0x21 0x42 0x03<\/pre>\n<p>And to turn it OFF:<\/p>\n<pre>sudo i2cset -y 3 0x21 0x41 0x54\r\nsudo i2cset -y 3 0x21 0x42 0x02<\/pre>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO MINDSTORMS EV3 Electromagnet\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/mgsznpgF7Xk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<p>Just a warning: with an operating current of 400 mA when ON the electromagnet gets hot very quickly &#8211; not enough to hurt but don&#8217;t forget to switch it OFF after use to prevent draing the EV3 batteries.<\/p>\n<p>The same method (&#8220;T&#8221; + &#8220;Digital_0&#8221; \/ &#8220;Digital_1&#8221;) can be used with several other Grove devices, like the <a href=\"http:\/\/wiki.seeed.cc\/Grove-Water_Atomization\/\">Grove &#8211; Water Atomization<\/a>:<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO MINDSTORMS EV3 Water Atomization\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/YViCQdmQQTY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<p>(a great way to add fog effects to our creations &#8211; just be careful with short circuits; if you add some kind of parfum you can also have scent effects)<\/p>\n<p>Final note: you can use the mindsensors.com Grove Adapter with native EV3 firmware (just import the available EV3-G block) but if you are using ev3dev like me be sure to use a recent kernel (as of today, &#8220;4.4.61-20-ev3dev-ev3&#8221;) because older versions had a bug that caused some communication problems with I2C devices (the Grove Adapter is an I2C device).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After David Lechner announced ev3dev support for it I&#8217;ve been planning to offer myself a couple of BrickPi 3 from Dexter Industries (just one is not enough since the BrickPi 3 suports daisy chaining). While I wait for european distributors to sell it (and my budget to stabilize) and since I&#8217;m also playing with magnets, &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2017\/using-grove-devices-to-the-ev3\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Using Grove devices to the EV3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[13,157,154,18,158,19,20,148],"tags":[297,296,295],"series":[],"class_list":["post-1069","post","type-post","status-publish","format-standard","hentry","category-ev3dev","category-ev3dev-en","category-lego-en","category-lego","category-lego-mindstorms-en","category-lego-mindstorms","category-linux","category-linux-en","tag-electromagnet","tag-grove","tag-magnet"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-hf","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=1069"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1069"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}