Exercise 2 - WefaaRobotics/Smorphi GitHub Wiki

Items needed:

  • An assembled Smorphi mini / Smorphi 2 robot
  • A computer
  • A USB to USB-C cable
  • Internet connection

Objectives of exercise:

  1. Download and set up Arduino IDE
  2. Learn how to include and install library
  3. Setting up of Smorphi for coding to customise functionality
  4. Learn some simple debugging skills
  5. Learn how to look up information on Google
  6. Learn how to use the Arduino IDE

Steps Description
1 [Download the Arduino IDE]

Go to https://www.arduino.cc/en/Guide to download Arduino IDE. Choose the correct version of Arduino IDE according to the type of computer you are using. Eg. If you are using Windows, download the version meant for Windows.



Integrated development environment (IDE) is software for building applications that combines common developer tools into a single graphical user interface (GUI). An IDE typically consists of:
  • Source code editor: A text editor that can assist in writing software code with features such as syntax highlighting with visual cues, providing language specific auto-completion, and checking for bugs as code is being written.
  • Local build automation: Utilities that automate simple, repeatable tasks as part of creating a local build of the software for use by the developer, like compiling computer source code into binary code, packaging binary code, and running automated tests.
  • Debugger: A program for testing other programs that can graphically display the location of a bug in the original code.
The Arduino IDE makes it easy to write code and upload into the Arduino based board we are using for Smorphi.

2 [Setup the Arduino IDE]

In your Arduino IDE, go to File> Preferences



Enter the following into the “Additional Board Manager URLs” field:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Then, click the “OK” button:



Open the Boards Manager. Go to Tools > Board > Boards Manager…



Search for ESP32 and press install button for the “ESP32 by Espressif Systems“:



That’s it. It should be installed after a few seconds.



3 [Download the Smorphi libraries]

Go to https://github.com/WefaaRobotics/Smorphi on Github to download the latest version of our user code via the download zip button. It can be found in the drop down after clicking on the green Code button. Make sure you are downloading from the Main Branch.



4 [How to include Smorphi library into Arduino IDE]

Navigate to the directory that you have downloaded the Smorphi library to --> Unzip / Extract the "smorphi-main" --> Copy all the folders --> Paste all the folders in libraries folder (or) you may also create a folder with the name "libraries" inside your respective arduino directory as shown in the picture below:





5 [What are code libraries?]

If you go into the folder you downloaded from Wefaa Github, you will see the files below. Those of type ‘C++ Source File’ and C Header Source File are the libraries you will be accessing when you code for the next few exercises.



6 [Add the supporting library]

Try clicking the Verify button, you will need to save your file first.



You will see this error message:



This is because another library that the Smorphi library needs, the Adafruit_Motor_Shield_V2_Library, has not been included. So let’s include that library.

Go to the ‘Include Library’ menu and select ‘Manage Libraries…’



In the search bar, look up the ‘Adafruit_Motor_Shield_V2_Library’ and install the latest version.



You will get a pop up that says there are other dependencies that are missing. Click on the ‘Install all’ button.



Close the library Manager. You can now try to Verify again. You will see another error.



Like before, go to the ‘Manage Libraries…’ Menu to download the library Adafruit_MCP23017_Arduino_Library.

Verify the code now. There should be no errors thrown.



7 [Test your setup]

Connect your computer to the board and select the port.

NOTE: If the port is not detected by your windows computer, look up on google for "Silicon Labs CP210x driver" and download the "Universal Windows Driver" under the downloads tab as shown in the image below:



Once downloaded, you may extract the zip folder and select the "silabser.inf" and right-click to install the driver as shown in the image below:



Once installed, connect your robot to the computer and select the right port number in the Arduino IDE by referring to the "Device Manager" and look up for the CP210x driver as shown in the image below.



Once done, Key in the below code into your Arduino IDE.



#include <smorphi.h>

Smorphi my_robot;

void setup(){
Serial.begin(115200);
my_robot.BeginSmorphi();
}

void loop (){
my_robot.MoveForward(50);
delay(3000);
my_robot.MoveForward(0);
delay(3000);
}
Your Smorphi should move forward for 3 seconds, stop for 3 seconds and then repeat.

NOTE: Usually, when you upload the code to the master board, the process should complete automatically. However, sometimes the upload will be stuck at ‘connecting……’



There are 2 solutions for this.
  1. Before it resolves into an error, press and hold the Boot button and click the enable button on the Master board at the same time, then release and wait. The code should complete the upload to the master board.
  2. You can unplug and reconnect the USB cable from the Master board to your computer and then reupload the code.


⚠️ **GitHub.com Fallback** ⚠️