Robotics and IoT (LEGO EV3 & IBM Watson IoT)

Author: Gunja

Integrating LEGO EV3 with IBM Watson IoT Platform

What you need?
Hardware

  • LEGO MINDSTORMS EV3 Kit
  • A microSD or microSDHC card (2GB or more)
  • WiFi adapter for LEGO MINDSTORMS EV3 (to connect to internet)

 

Access to Watson IoT Platform
IBM Bluemix account

What are we trying here?
We will integrate EV3 Robot with Watson IoT platform and control basic movement of robot from IoT platform. Objective of this exercise is to gain hands on experience on Internet of Things in real world, and experience how end to end connectivity works.

How it Works?

  • Watson IoT platform setup to receive & send data to EV3
  • EV3 configured with Debian Linux
  • Python program executes on EV3 to communicate with Watson IoT
  • Move instruction sent from IoT platform to EV3 (via MQTT)
  • WiFi adapter for LEGO MINDSTORMS EV3 (to connect to internet)

How to setup?

Step 1: Install Debian Linux on SD Card
Follow Step 1 on below URL -

http://www.ev3dev.org/docs/getting-started/?cm_mc_uid=87814115657415045797131&cm_mc_sid_50200000=1506241907

IOT - 1

Step 2: Boot EV3 with Linux and Connect to WiFi

  • - Insert SD Card into EV3
  • - Insert WiFi Adaptor to USB port into EV3
  • - Start your EV3 and it shall boot to Linux
  • - Go to "Wireless and Networks" > WiFi
  • - Connect to WiFi network of your choice
  • - Test Connectivity - Connect EV3 through SSH
  • - Setup software like Putty on your laptop and connect to EV3 (SSH)
  • - Check IP address of EV3 in "Wireless and Networks"
  • - Default user id and password is - robot / maker


Help on Booting EV3 with Linux (Step 4)

http://www.ev3dev.org/docs/getting-started/?cm_mc_uid=87814115657415045797131&cm_mc_sid_50200000=1506241907

Help on WiFi Connectivity

http://www.ev3dev.org/docs/networking/
IOT - 2


Step 3: Setup Watson IOT Platform (IBM Bluemix)

  • - Create Bluemix account (ignore if you already have one)
  • - Create IoT platform using boilerplate Internet of Things Platform Starter
  • - Once boiler plate is created, create device type and add device
  • - User authentication method as TOKEN
  • - Store Device Type, Device Id, and Token
  • - Device type, device id & token will be required in python program to communication from EV3 to IoT

IOT - 3

Step 4: Setup Python & MQTT on EV3

  • - Connect to EV3 through SSH
  • - Install pip on EV3 using this command for python3: "sudo apt-get install python3-pip"
  • - If you get below error while installing pip, you need to download and update the package list
  • - Reading package lists... Done
  • - Building dependency tree
  • - Reading state information... Done
  • - Update your python by executing this command - "sudo apt-get update"
  • - Install MQTT package by executing this command - "pip install paho-mqtt"

IOT - 4


Step 5: Build Your Robot

  • - Build your EV3 robot with minimum 2 motors
  • - Connect Left Motor (Large) to port B, and Right Motor (Large) to port C

IOT - 5


Step 6: Configure Node Red and Run Sample Program

  • - Download EV3 program from https://developer.ibm.com/recipes/tutorials/connect-lego-mindstorm-ev3-to-ibm-iot-platform-over-mqtt/
  • - Follow Step 3 on above web page to setup your ev3.py program
  • - Run program by executing this command - "python ev3.py"
  • - If you get an error - No module named paho.mqtt.client, you may have some python version issue
  • - Check - python --version
  • - You have installed Python3 but for some reason the interpreter may be using version 2.7 in Linux.
  • - You may try using pip3 install paho-mqtt python-etcd instead
  • - Alternatively you need to unlink python 2.7 and link python 3
  • - unlink /usr/bin/python
  • - ln -s /usr/bin/python3.4 /usr/bin/python
  • - Run program by executing this command - "python ev3.py"
  • - In case log shows "Closed connection from MY_IP_ADDRESS. The operation is not authorized.", you may have TLS issue
  • - New instances of Watson IoT Platform now require TLS connections by default. You can change this, and relax it to TLS optional, in the Security settings of your Watson IoT Platform organization.
  • - Go to my NodeRed editor in Bluemix
  • - Go to GitHub and copy contents of opened file (nodeRED_EV3). Refer Step 4 - https://developer.ibm.com/recipes/tutorials/connect-lego-mindstorm-ev3-to-ibm-iot-platform-over-mqtt/
  • - Import new flow by pressing menu top right corner. Select Import -> Clipboard, Paste content.

IOT - 6


Now you can try controlling your robot from IoT platform. Make sure you have run ev3.py on EV3.

 

 


Comments

There are no comments

Post a comment