Interfacing evive with Scratch

About This Tutorial
This tutorial discusses how to interface evive with Scratch, the Robot palette, the two modes for writing scripts in mBlock, and how to upload the script to evive.
Tutorial Info
Programming Platform:
Difficulty:
Estimated Time (hrs):
1

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Introduction

You can write scripts in Scratch for numerous projects that can be carried out using evive. This tutorial will discuss how to interface evive with Scratch, the two modes for writing scripts, the Robot palette, and how to upload the script to evive.

Interfacing evive with Scratch

To run the scripts written in Scratch on evive, you must upload it to evive. Follow the procedure below to connect interface evive with Scratch:

  1. Connect evive to your laptop/PC and open mBlock. If not yet installed, please refer to the Getting Started with Scratch tutorial here.
  2. In mBlock, go to the tool bar and click on the Boards Select the Arduino Mega 2560 board.
  3. Once you’ve selected the Arduino Mega 2560 board, click on the Connect tab, and then on Serial Port.
  4. Upon clicking on Serial Port, a fly-out menu will appear which shows the different ‘COM’ ports available; select the port to which evive is connected. Once you select the port, the message ‘Serial port connected’ will appear at the very top of mBlock. If it doesn’t appear, select a different port from the list.

Robot Palette

mBlock has a dedicated palette for writing project scripts that can work on evive; it is known as the Robot Palette. The extensions installed while setting up mBlock in the Getting Started with Scratch tutorial come under this palette.

Scratch Extensions for evive

Scratch extensions enable you to control evive and Arduino in Scratch. Following extensions are available for evive in the Robot Palette:

  • Arduino: This extension controls evive’s core, i.e. the Arduino Mega 2560 board
  • evive Inbuilt Tools: The blocks under this extension are used to control the different components that are built into evive, such as tactile switches, and output devices, e.g. the DC motor.
  • evive App: The block under this extension is responsible for receiving input from the evive app which you can install in your smartphone.
  • evive TFT Display: This extension is responsible for controlling the display on the TFT screen on evive.
  • evive Tinkering: You can use this extension to ‘tinker’ around with evive by controlling different sensors and actuators.

Modes to work with evive

There are two modes in Scratch using which you can work on evive:

  1. Scratch Mode
  2. Arduino Mode

Scratch Mode

In Scratch mode, which is the default mode in mBlock, you can run the script and control evive as long as it is connected to your laptop/PC; the moment you remove the USB you cannot use the script to work with evive anymore.

Arduino Mode

In Arduino mode, the blocks are transferred to Arduino C++ in Arduino IDE, and then you can modify the code in Arduino IDE. Another important aspect of Arduino mode is that you can upload the code to evive using this mode only.

Follow the steps given below to switch to Arduino mode:

  1. Go to the tool bar and click on Edit.
  2. Select Arduino mode from the drop-down menu.

On doing so, the screen shown below will appear.

In Arduino mode, there are three buttons in the top right corner, as shown:

  • Back: for switching back to Scratch mode
  • Upload to Arduino: for uploading the script to evive, or any other Arduino board.
  • Edit with Arduino IDE: for editing the code in Arduino IDE

Scripts for lighting up Pin 13 LED

Scratch Mode

In this example we will write a script to turn ON the LED connected to evive’s pin 13 whenever you press the space bar on your keyboard. When you press the space bar, pin 13 becomes HIGH; therefore, the LED lights up. When you don’t press it, the pin returns to its initial state, i.e. LOW, and the LED turns OFF.

When working with evive on Scratch for the very first time, you must upload the following script to evive. Follow the steps bellow to write the script:

evive Alert
Before beginning the script, make sure that you have uploaded the firmware to evive.
  1. Connect evive to your laptop/PC, and select the appropriate port.
  2. Open mBlock; if already open and working on a project, save that project. Then, click on New.
  3. Next, go to the Robot palette and drag and drop the evive Program hat block from evive Inbuilt Tools extension into the Scripting area.
  4. Then,drag and drop the work on Scratch mode (Upload Firmware) block from the same extension below the evive Program block.

Below is the complete script:

To upload the script to evive follow the steps below:

  1. Select the Arduino mode from the Edit tab in the tool bar.
  2. Click on Upload to Arduino. On doing so the message Uploading will pop up in the center of the screen.
  3. Once the upload is finished, the message Upload Finish will appear in the center of the screen. Click on Close.

Follow the steps below to write the script for lighting up the LED:

  1. Connect evive to your laptop/PC, and select the appropriate port.
  2. Save the previous script; then click on New.
  3. Go to the Events palette and drag and drop the when ‘flag’ clicked block.
  4. Next, go to the Control palette and drag and attach the forever block below the when ‘flag’ clicked block.
  5. Then, drag and drop the if-else block below the when ‘flag’ clicked block from the Control palette.
  6. Next, go the Sensing palette, and drag and drop the key () pressed? block; from the drop-down menu, select the ‘space’ key. Then, drag and drop this block inside the diamond shaped space in the if arm of the if-else block.
  7. Now, below the if arm, drag and drop the set digital pin () output as () block. Set the digital pin number to 13 and set it to HIGH.
  8. Next, below the else arm, again drag and drop the set digital pin () output as () block. Set the digital pin number to 13 and set the digital pin to LOW.

Below is the complete script:

To run the script, click on the green flag in the top right corner of the stage. It will start glowing as soon as you click on the flag.

To stop the script, click on the red octagon, next to the green flag.

Arduino Mode

In this example we will write a script to turn ON the LED connected to evive’s pin 13 whenever you press evive’s tactile switch 1. When you press the switch, pin 13 becomes HIGH; therefore, the LED lights up. When you don’t press it, the pin returns to its initial state, i.e. LOW, and the LED turns OFF.

Follow the steps below to write the script:

  1. Connect evive to your laptop/PC, and select the appropriate port.
  2. Save the previous script; then click on New.
  3. Go to the Robots palette and drag and drop the evive Program block in the scripting area from the evive Inbuilt Tools extension.
  4. Next, drag and attach the forever block below the evive Program block.
  5. Then, go to the Control palette and drag and drop the if-else block inside the forever block.
  6. Next, go to the Robots palette and drag and drop the tactile switch () pressed block inside the diamond shaped space in the if arm of the if-else block; from the drop-down menu, select ‘1‘.
  7. Now, below the if arm, drag and drop the set digital pin () output as () block. Set the digital pin number to 13 and set it to HIGH.
  8. Next, below the else arm, again drag and drop the set digital pin () output as () block. Set the digital pin number to 13 and set the digital pin to LOW.
  9. Switch to Arduino mode and upload the script to evive.

Below is the complete script:

This Helped
This didn't help
Share this Tutorial
Facebook
Twitter
Google+
Pinterest
Reddit
Print
Related Tutorials
Featured Projects
Unique-Christmas-Tree

DIY Unique Christmas Tree

This project will show you how to make a unique DIY Christmas Tree for this year’s Christmas.

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart