{"id":11248,"date":"2016-04-04T09:00:51","date_gmt":"2016-04-03T23:00:51","guid":{"rendered":"http:\/\/legoeng.local?p=11248&preview_id=11248"},"modified":"2016-12-16T12:56:40","modified_gmt":"2016-12-16T01:56:40","slug":"scratch-and-lego-wedo","status":"publish","type":"post","link":"http:\/\/legoeng.local\/scratch-and-lego-wedo\/","title":{"rendered":"Scratch and LEGO WeDo"},"content":{"rendered":"

You may have heard of the computer programming language Scratch. It\u2019s a child-friendly system where you code by dragging around colored blocks and snapping them together \u2013\u00a0and for that reason some schools call it \u2018Computer LEGO\u2019. Even better, Scratch has a built-in extension that allows it to work with LEGO\u2019s WeDo robot kits. I want to tell you about how I\u2019ve been using Scratch and WeDo with children in the UK.<\/p>\n

\"Scratch
Scratch once the WeDo extension has been enabled. The yellow dot next to LEGO WeDo in the middle column indicates that the WeDo hub hasn\u2019t yet been plugged into the computer. If it\u2019s red, you need to install the browser plug-in. Green indicates that you\u2019re good to go.<\/figcaption><\/figure>\n

Scratch is developed by The Lifelong Kindergarten Group at the Massachusetts Institute of Technology, and is completely free to use. You can either use the online version at the scratch.mit.edu<\/a> website, or you can download and install the Scratch 2.0 Offline Editor<\/a>. If you go for the first approach, you also have to install a browser plug-in (see here<\/a>). The plug-in doesn\u2019t seem to work reliably across all browsers and operating systems \u2013 so if you\u2019re having problems try a different browser. If instead you\u2019re using the Scratch Offline Editor, everything you need is already built-in, so you\u2019re good to go.<\/p>\n

LEGO launched a new version of WeDo, WeDo 2.0, in January 2016, and the Scratch team has since released an extension<\/a> that works with it. This post is all going to be about the original WeDo. This kit includes a hub you plug into your computer, a motor, a tilt sensor, a distance sensor, and loads of LEGO blocks. The LEGO WeDo Software is sold separately, but you don\u2019t need anything extra if you\u2019re using Scratch instead. Having said that, I would recommend buying the Power Function Lights, as they\u2019re relatively cheap, and are fully compatible with Scratch and the WeDo hardware.<\/p>\n

Once you\u2019ve got your kit, just plug it into the USB slot, start up Scratch and go to \u2018More Blocks\u2019. Next select \u2018Add an Extension\u2019 and then LEGO WeDo. If you don\u2019t see these options, you may need to update your Scratch to a newer version. A selection of new blocks will now appear, offering very self-explanatory options for controlling the motor and reading the sensors. You can control the motor speed and direction, find out how far in front of the distance sensor the nearest surface is, and in which direction the tilt sensor is angled.<\/p>\n

All of these blocks can be fully integrated with any Scratch program, so you could use the tilt sensor to control a sprite, or have the motor react to events in a game. The main limitation is that with Scratch you can only use one WeDo hub at once \u2013 if you\u2019re using the LEGO WeDo Software you can connect up to three at once. This limits you to using just two electronic components at a time: a motor and a sensor, two sensors, two motors, a motor and a light, etc. As each kit only comes with one hub, this isn\u2019t likely to be a problem for most of us.<\/p>\n

Now, how about the LEGO WeDo kit itself? The base kit includes some 158 elements \u2013 a mixture ranging from standard four by twos to cogs and gears borrowed from the LEGO Technic range. And if that\u2019s not enough for you, there\u2019s a resource set with another 326 bits, but it doesn\u2019t include any more electronic components \u2013 you have to buy them separately. This brings us to what I really love about WeDo \u2013 it uses classic studded<\/em> LEGO bricks, rather than the studless<\/em> Technic beams used in the MINDSTORMS EV3 set, so it really feels like LEGO. Every robot you make, you build brick by brick \u2013 so you really can make absolutely anything. An EV3 set is also at least twice the price \u2013\u00a0so I\u2019d much rather go for a WeDo set any day.<\/p>\n

\"Scratch
Scratch code for controlling \u2018Drumming Monkey\u2019. The tilt sensor keeps the sounds in sync with his movements.<\/figcaption><\/figure>\n

There are twelve official models you can make with the WeDo set. You don\u2019t get the instructions with the kit (unless you buy the activity add-on to the software), but you can download them for free from the LEGO website<\/a>. There\u2019s a good variety here \u2013 ranging from a sailboat that rocks, to a foot that kicks anything placed in front of it. The sailboat is intended to be used as part of a story \u00ad\u00ad\u2013 you can add sounds and vary the speed and degree of rocking with your Scratch program. The sounds and any visuals will play through your computer’s speakers and screen as normal. The foot is probably the simplest model to build, but also one of the most popular with children. It uses the distance sensor to detect when an object is placed in front of it\u00a0and then turns on the motor to kick it.<\/p>\n

Another favorite is the \u2018Smart Spinner\u2019. It uses the motor to rotate a spinning top, and the distance sensor to detect when to switch the motor on and off. It uses gears to step up the motor speed, so the top goes on spinning for ages after release. \u2018Goal Keeper\u2019 is also very popular \u2013 you use the computer keyboard to move a soccer goalie into the path of balls rolled towards him. You can also use the distance sensor to detect every time a ball gets past him. Scratch can keep count of the number of goals, and play a sound every time as well.<\/p>\n

Four models respond to your actions. The alligator snaps her jaws shut when you put your hand inside. The lion rises up and roars when you move the meat he is guarding. The giant awakes and stands up when you put a LEGO man in front of him. The \u2018Cheerful Fans\u2019 rotate and bob up and down when you get close. In my version, I made them move faster (and make more noise) the closer you get. \u2018Dancing Birds\u2019 is similar to Cheerful Fans, but they simply spin around under computer control, without using a sensor to respond to your actions. \u2018Drumming Monkey\u2019 beats drums with his arms, and if you add the tilt sensor, you can coordinate drum sounds to play in sync\u00a0with his movements.<\/p>\n

\"The
The twelve official WeDo models<\/figcaption><\/figure>\n

There\u2019s another story-based model \u2013\u00a0\u2018Airplane Rescue\u2019 \u2013\u00a0which uses the tilt sensor to adjust propeller-speed based on its orientation. You can also add sound effects and calamities such as the engine stuttering to a halt mid-flight. Finally, \u2018Flying Birds\u2019 is unique in not using the motor, but using both sensors instead. You manually flap her wings, and she can play a sound through the computer every beat, and another one when you tip her head down to peck at her feet.<\/p>\n

I\u2019ve always used Scratch rather than LEGO Education’s WeDo Software. I\u2019ve created my own Scratch studio with code for each WeDo robot here<\/a>, and I\u2019ve added videos of them in action to my Vimeo channel here<\/a>. I\u2019ve used the WeDo kits as part of Code Clubs run by Success4All<\/a>, and at a primary (elementary) school with high ability 7 to 9 year-olds.\u00a0Success4All is a voluntary organization that provides free tutoring and educational clubs for children in economically and educationally disadvantaged areas of Newcastle upon Tyne. Code Club<\/a> is a UK organization that helps volunteers to run computer programming clubs in schools and community centers across the UK and internationally, mainly using Scratch. Code Club is aimed at 9 to 11 year-olds, but Success4All\u2019s Code Clubs have been open to children of any age \u2013\u00a0and I\u2019ve found that Code Club projects and the WeDo robots work well with children from 7 right up to 17.<\/p>\n

LEGO Education markets the WeDo kits at primary schools for children aged 7 to 11. In my experience, the models are quite advanced for this age group. Keen LEGO builders will be fine, but it can take a child a full hour to build a model, before they even start with writing the code to control it. Many children will find it hard to persevere with a model this hard, and will need a bit of help and encouragement to get to the end. Even when they have completed one, they are not likely to have much time or stamina left to actually do any coding.<\/p>\n

One solution to this problem is to get the children to start with much simpler models. I\u2019ve done this by getting them to copy a model I\u2019ve created, such as a car that moves forward or backward under keyboard control, but uses the distance sensor to stop before it hits an object in front of it. Another simple model is a magic wand that will only light up and play a sound when tilted in the right sequence of moves. There\u2019s a video of it here<\/a>.<\/p>\n

\"Scratch
Scratch code for a car that won\u2019t crash. You can control it with the arrow keys, but it won\u2019t move forwards if it detects and obstacle less than ten units ahead.<\/figcaption><\/figure>\n

No doubt there is lots of good learning just in building the LEGO, especially in relation to mechanics and gears, so another solution is to let the children build the models and then load in a program you\u2019ve already written (or the code from my Scratch studio). This works well too \u2013 and the children can then go on to modify the model and\/or code themselves. If you\u2019re able to leave the models intact until the next session, that would be a good solution too. Once the kids have built a few models, they\u2019ll probably speed up, and more-experienced\/older kids will be fine from the start.<\/p>\n

\"Mechanical
My Mechanical Grabber. If you place an object in front of the jaws, it will reach out, grab it, and pull it back. The distance sensor detects objects and the motor uses a rack and pinion to move the arm. The jaws open when the arm is pushed forwards, and close when it is pulled back.<\/figcaption><\/figure>\n

We haven\u2019t really got to the real fun of WeDo yet \u2013\u00a0the massive potential to make your own creations. The kits are capable of doing way more than LEGO\u2019s official models. You can see 12 of my own creations on my Vimeo channel<\/a>, and the control code for each in this Scratch studio<\/a>. That\u2019s an open studio, so you can contribute your own creations too (and some people already have). I\u2019ve included photos in the projects as backgrounds, so you should be able to work out how to build the LEGO models.<\/p>\n

I\u2019ve really tried to explore what the WeDo sets are capable of \u2013\u00a0and the answer is a lot. They may not have as many motors or as diverse a range of sensors as the NXT and EV3 sets, but with a bit of ingenuity you can get them to do all sorts of things I\u2019m sure their creators never imagined. I\u2019ve made an earthquake detector, a machine that reaches out and grabs anything put in front of it<\/a>, a car that drives around automatically turning to avoid obstacles, a version of the soccer goalie mentioned above that moves to save goals automatically, a machine that will move a pole until it finds its balance point, and a kind of \u2018radar\u2019 that will draw a graph of objects it senses in its surroundings. Even having done all this, I\u2019m sure there is loads more that you can achieve with WeDo.<\/p>\n

Having given an overview of what you can do with the WeDo kits, I\u2019m now going to show you a couple of useful snippets of code. If you put one of these snippets of code in Scratch (don\u2019t try to use both at once), you\u2019ll be able to see the current reading of the distance or tilt sensor. This is really useful for seeing how those sensors work, and for debugging purposes.<\/p>\n

\"Scratch
Scratch code for reporting the sensor values<\/figcaption><\/figure>\n

Finally, I just want to make a brief shout-out to PicoBoard<\/a>, another piece of hardware supported by Scratch. It has four sensors: a push-button and a slider, as well as light and sound sensors. It also has four inputs that measure resistance, allowing you to easily make and add your own sensors. There is a lot of potential to use this together with WeDo kits to augment their sensing capabilities, and so create more capable robots.<\/p>\n

Whether it\u2019s to play with for your own entertainment, or as part of a mission to advance the technical skills of our planet\u2019s next generation, I\u2019d strongly recommend getting hold of a WeDo kit. I\u2019ve certainly enjoyed playing with mine!<\/p>\n","protected":false},"excerpt":{"rendered":"

You may have heard of the computer programming language Scratch. It\u2019s a child-friendly system where you code by dragging around colored blocks and snapping them together \u2013\u00a0and for that reason some schools call it \u2018Computer LEGO\u2019. Even better, Scratch has a built-in extension that allows it to work with LEGO\u2019s WeDo robot kits. I want […]<\/p>\n","protected":false},"author":531,"featured_media":11262,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[70,69,371,124,523],"_links":{"self":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/11248"}],"collection":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/users\/531"}],"replies":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/comments?post=11248"}],"version-history":[{"count":0,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/11248\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media\/11262"}],"wp:attachment":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media?parent=11248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/categories?post=11248"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/tags?post=11248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}