{"id":1323,"date":"2014-06-09T18:28:46","date_gmt":"2014-06-09T16:28:46","guid":{"rendered":"http:\/\/ubik75.com\/?p=1323"},"modified":"2016-07-01T11:08:45","modified_gmt":"2016-07-01T09:08:45","slug":"tutoriel-1-scratch-brickpi","status":"publish","type":"post","link":"http:\/\/ubik75.com\/?p=1323","title":{"rendered":"Tutoriel 1 Scratch BrickPi"},"content":{"rendered":"<p style=\"text-align: justify;\">Je vais vous pr\u00e9senter la fa\u00e7on de piloter des moteurs et lire des capteurs avec le logiciel Scratch. Je pars du principe que BrickPi Scratch est install\u00e9 sur le raspberry et est fonctionnel, sinon vous pouvez consulter cette\u00a0<a href=\"http:\/\/www.dexterindustries.com\/BrickPi\/program-it\/scratch\/\" target=\"_blank\">page<\/a>\u00a0pour l&rsquo;installation.<\/p>\n<p><!--more--><\/p>\n<p>Nom des ports pour les moteurs connect\u00e9s \u00e0 la carte: MA, MB, MC et MD, et\u00a0les capteurs connect\u00e9s sur la carte: S1, S2, S3, S4 et S5.<\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1343\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1343\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi.jpg\" data-orig-size=\"576,426\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402334532&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"cartebrickpi\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi-300x221.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi.jpg\" class=\"aligncenter size-medium wp-image-1343\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi-300x221.jpg\" alt=\"cartebrickpi\" width=\"300\" height=\"221\" srcset=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi-300x221.jpg 300w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi-405x300.jpg 405w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/cartebrickpi.jpg 576w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\">Pilotage des moteurs, moteurs en rotation:<\/span><\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchmoteur.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1326\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1326\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchmoteur.jpg\" data-orig-size=\"209,188\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402316295&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"image1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchmoteur.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchmoteur.jpg\" class=\"aligncenter size-full wp-image-1326\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchmoteur.jpg\" alt=\"image1\" width=\"209\" height=\"188\" \/><\/a>Pour les moteurs les param\u00e8tres suivants sont utilis\u00e9s:<\/p>\n<ul>\n<li>E (Enable): activation de moteur.<\/li>\n<li>MA 200: apr\u00e8s l&rsquo;activation du moteur, mettre le moteur \u00e0 une vitesse \u00e9gale \u00e0 200.<\/li>\n<li>\u00a0D (Disable): d\u00e9sactivation du moteur.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Utilisation dans le bloc<strong>\u00a0\u00ab\u00a0broadcast\u00a0\u00bb<\/strong> qui se trouve dans le menu <strong>\u00ab\u00a0control\u00a0\u00bb<\/strong>, \u00e0 ce bloc on ajoute un bloc <strong>\u00ab\u00a0join\u00a0\u00bb<\/strong> avec le nom du port<strong>\u00a0MA<\/strong> (car moteur connect\u00e9 sur le port MA, premier port moteur) plus la commande <strong>E<\/strong> (Enable, activation du moteur). Dans l&rsquo;exemple \u00a0ci-dessus, les moteurs MA et MC sont activ\u00e9s et tournent \u00e0 la vitesse de 200. Le bloc <strong>\u00ab\u00a0say\u00a0\u00bb<\/strong> permet d&rsquo;afficher \u00e0 l&rsquo;\u00e9cran l&rsquo;information Running.<\/p>\n<p><span style=\"text-decoration: underline;\">Pilotage des moteurs, moteurs \u00e0 l&rsquo;arr\u00eat:<\/span><\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/StopScratch.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1332\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1332\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/StopScratch.jpg\" data-orig-size=\"229,135\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402331982&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Image2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/StopScratch.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/StopScratch.jpg\" class=\"aligncenter size-full wp-image-1332\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/StopScratch.jpg\" alt=\"Image2\" width=\"229\" height=\"135\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">C&rsquo;est le m\u00eame principe que pour mettre les moteurs en rotation sauf que le bloc <strong>broadcast<\/strong> contient<strong> MA D<\/strong>. Maintenant on peut commander les moteurs par un appui sur la fl\u00e8che haut du clavier et arr\u00eater les moteurs par un appui sur la fl\u00e8che bas du clavier.<\/p>\n<p><span style=\"text-decoration: underline;\">Capteur de contact:<\/span><\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1336\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1336\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact.jpg\" data-orig-size=\"274,355\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402332864&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"image3\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact-231x300.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact.jpg\" class=\"aligncenter size-medium wp-image-1336\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact-231x300.jpg\" alt=\"image3\" width=\"231\" height=\"300\" srcset=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact-231x300.jpg 231w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchcontact.jpg 274w\" sizes=\"auto, (max-width: 231px) 85vw, 231px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Pour d\u00e9finir le capteur de contact branch\u00e9 sur le port S2, il faut un bloc<strong> broadcast<\/strong> et un bloc<strong> join<\/strong> avec le nom du port, ici <strong>S2<\/strong> (capteur branch\u00e9 sur le port S2) plus un nom, ici <strong>TOUCH<\/strong>. Apr\u00e8s il faut ajouter deux blocs broadcast, un <strong>SETUP<\/strong> et un <strong>START<\/strong> permettant de d\u00e9finir le capteur et de l&rsquo;activer. Dans la boucle <strong>forever<\/strong> ne pas oublier de mettre un bloc <strong>broadcast<\/strong> <strong>UPDATE<\/strong>, ce bloc permet de connaitre l&rsquo;\u00e9tat du capteur. Quand le capteur de contact est actionn\u00e9, donc \u00e0 l&rsquo;\u00e9tat 1, le moteur tourne sinon le moteur est arr\u00eat\u00e9.<\/p>\n<p><span style=\"text-decoration: underline;\">Capteur ultrasons:<\/span><\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1339\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1339\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra.jpg\" data-orig-size=\"283,402\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402333640&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"image4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra-211x300.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra.jpg\" class=\"aligncenter size-medium wp-image-1339\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra-211x300.jpg\" alt=\"image4\" width=\"211\" height=\"300\" srcset=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra-211x300.jpg 211w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/Scratchultra.jpg 283w\" sizes=\"auto, (max-width: 211px) 85vw, 211px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Le principe reste identique au capteur de contact, il suffit de modifier son nom (<strong>ULTRASONIC<\/strong>) et de changer de condition dans la boucle if. Ne pas oublier le bloc <strong>broadcast UPDATE<\/strong>, j\u2019ai ajout\u00e9 un bloc <strong>say<\/strong> afin d\u2019afficher la valeur du capteur. Si la valeur est inf\u00e9rieure \u00e0 10 le moteur tourne sinon le moteur est arr\u00eat\u00e9.<\/p>\n<p><span style=\"text-decoration: underline;\">Lecture de la valeur brute d&rsquo;un capteur:<\/span><\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1341\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1341\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw.jpg\" data-orig-size=\"280,345\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402333977&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"image5\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw-243x300.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw.jpg\" class=\"aligncenter size-medium wp-image-1341\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw-243x300.jpg\" alt=\"image5\" width=\"243\" height=\"300\" srcset=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw-243x300.jpg 243w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchraw.jpg 280w\" sizes=\"auto, (max-width: 243px) 85vw, 243px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Le principe reste le m\u00eame, je mesure la valeur brute (valeur de 0 \u00e0 1024) du capteur de contact branch\u00e9 sur le port S3. Si la valeur est inf\u00e9rieure \u00e0 200 (capteur de contact actionn\u00e9) le moteur tourne, sinon le moteur est arr\u00eat\u00e9. Le bloc <strong>say<\/strong> affiche la valeur brute donn\u00e9e par le capteur de contact.<\/p>\n<p>Tableau r\u00e9capitulatif:<\/p>\n<p><a href=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau.jpg\" rel=\"lightbox\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1346\" data-permalink=\"http:\/\/ubik75.com\/?attachment_id=1346\" data-orig-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau.jpg\" data-orig-size=\"563,281\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;ubik&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1402335844&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"tableau\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau-300x149.jpg\" data-large-file=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau.jpg\" class=\"aligncenter size-medium wp-image-1346\" src=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau-300x149.jpg\" alt=\"tableau\" width=\"300\" height=\"149\" srcset=\"http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau-300x149.jpg 300w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau-500x249.jpg 500w, http:\/\/ubik75.com\/wp-content\/uploads\/2014\/06\/scratchtableau.jpg 563w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p>Il ne vous reste plus qu&rsquo;a tester les diff\u00e9rents programmes ci dessus.<\/p>\n","protected":false},"excerpt":{"rendered":"<img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"http:\/\/ubik75.com\/wp-content\/plugins\/thumbnail-for-excerpts\/tfe_no_thumb.png\" class=\"alignleft wp-post-image tfe\" alt=\"\" title=\"\" \/><p>Je vais vous pr\u00e9senter la fa\u00e7on de piloter des moteurs et lire des capteurs avec le logiciel Scratch. Je pars du principe que BrickPi Scratch est install\u00e9 sur le raspberry et est fonctionnel, sinon vous pouvez consulter cette\u00a0page\u00a0pour l&rsquo;installation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[118,6],"tags":[117,108,122],"class_list":["post-1323","post","type-post","status-publish","format-standard","hentry","category-brickpi-2","category-logiciel","tag-brickpi","tag-raspberry","tag-scratch"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2eCSX-ll","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/posts\/1323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ubik75.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1323"}],"version-history":[{"count":26,"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":1423,"href":"http:\/\/ubik75.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions\/1423"}],"wp:attachment":[{"href":"http:\/\/ubik75.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ubik75.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ubik75.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}