Skip navigation

Week 10 - Nov 6 - 12

 

     This will be last week in the design phase of the IoT on Wheels Design Challenge and for my trafficpredictor project. This blog will be a walkthrough of the entire project. The blogs posted over the two months time is at the end of this blog in a categorized format. Check it out if you have missed out any or to better understand the project.

 

     I ventured out on a trip today (rainy at times) with the trafficpredictor alongside and captured it in a video. Check it out in the video below.

               Today's Weather from Google

 

 

Code to program Nucleo-L476RG board(Arduino compatible

I have posted an updated code used for programming the Nucleo-L476RG board below You can also find the below code in my GitHub repository Click Here. The input to the mobile app will be like (A, T, N) improved from (Location of Servo, Location of Obstacle).

  • A - Alert (Object is near Vehicle - Have to stop)
  • T - Traffic (Object is near Vehicle - traffic)
  • N - Normal (No Object, free to Move)

 

/*This is the code for element14 IoT on wheels design contest traffic predictor project
 * https://www.element14.com/community/community/design-challenges/iot-on-wheels/
 * 
 * Author : Dixon Selvan
 * Date   : November 08, 2017
 * Project: Traffic Predictor and Auto Pilot
 * Website: https://traffic-predictor.000webhostapp.com/
 * 
 * Hardware components
 * -----------------------------------
 1 Nucleo-L476RG microcontroller board 
 * 2. HC-05 Bluetooth module
 * 3. HC-SR04 Ultrasonic Sensor
 * 4. Servo motor
 * 
 Nucleo-L476RG Bluetooth module 
 * ------------------------------------
 *      5V        |         5V
 *      Gnd       |         Gnd
 *      TX        |         CN3 RX
 *      RX        |         CN3 TX
 *      
 * Servo
 * -----
 * Left = 45 degree
 * Mid = 90 degree
 * Right = 135 degree
 * 
 * A (Alert) <= 60
 * T (Traffic) <=75
 * N (Normal) >=90
 */     
#include 


//Servo variables and constants
Servo myservo;
int pos = 0;
int value = 0;
int servoPin = 3;//Nucleo pin D3


//Ultrasonic sensor variables and constants
int trigPin = 5;//Nucleo pin D5
int echoPin = 2;//Nucleo pin D2


//General variables and constants
long duration;
int distance;


void setup() {
  // put your setup code here, to run once:
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT);  


  Serial.begin(38400);//Serial Connection begin
  
  myservo.attach(servoPin);//Attaching servo pin
}


void loop() {
  // put your main code here, to run repeatedly:
  //servoRotate();
  delay(250);
  serialPrint(45);
  delay(250);
  serialPrint(90);
  delay(250);
  serialPrint(135);
  Serial.println();
}


void serialPrint(int pos){
  myservo.write(pos);
  delay(10);
  value = calculateDistance();
  if(pos==45){
    Serial.print(classifiedData(value));
    Serial.print(",");
  }
  else if(pos==90){
    Serial.print(classifiedData(value));
    Serial.print(",");
  }
  else if(pos==135){
    Serial.print(classifiedData(value));
  }
  else{Serial.print('N');Serial.print(",");}
}


char classifiedData(int value){
  char out=' ';
  if((value<=60)&&(value!=0)){out = 'A';}
  else if((value<=90)&&(value>=75)&&(value!=0))
  {
    out = 'T';
  }
  else{out='N';}
  return out;
}


int calculateDistance()
{
  //Code to calculate Distance from Duration
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance= duration*0.034/2;
  return distance;
}

 

Conclusion

     I am happy to reach the final stage. This trafficpredictor idea sprung when I was stuck in the middle of traffic, thinking what if someone shares me their shortcut(best route to avoid traffic). I have discovered three ways to reach my workplace and wondered which one is the quickest and at what time of the day. These thoughts have now come life!

 

     This is my first Android app project and I am hoping to release this application soon in the Google Play Store after purchasing a web domain and tidying the code a bit more and adding beauty to the look and feel. This is to collect more data which is the heart of machine learning.

 

     Thank you all for your love and support. I once again would like to thank Element14 community, ST Microelectronics and Duratool for providing me a wonderful platform and Nucleo-L476 RG board along with the other expansion boards to learn about Mbed OS and programming the Nucleo boards. I had absolute fun playing with Nucleo board along with the expansion boards. My favorite I would say is the MEMS expansion board IKS01A2 [User Manual] and the below tool Unicleo-GUI for testing it.

 

 

 

Links to all blogs posted for my trafficpredictor project are given below,

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   100%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Traffic Predictor #12 - Predicting the best route to avoid traffic [Part 2 of 2]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

Traffic Predictor #11 - Module 2 and 3 [Completed]

IntegrationThis blog
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

Logo

Week 10 - Nov 6 - 12

 

     This will be last week in the design phase of the IoT on Wheels Design Challenge and for my trafficpredictor project. This blog will be a walkthrough of the completed module 1. Check out Part 1 of this blog - Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2] for a better understanding of the progress.

Module 1 - Traffic prediction with machine learning

To be covered in this blog,

Completed App (Android)

Functionality explained

Database Schema

Machine Learning model

 

Completed App (Android) & Functionality explained

     I have already given an insight of how the trafficpredictor mobile app looks like in

     In this blog, I will explain the completed app in detail with the functionality of the traffic predictor project followed by. The various screens or activities (if I were to say the Android way) are categorized as follows:

 

  • Home

         This is the page where the user lands once the user successfully logs in. This page contains details about the user and the last trip user has taken to. It also has buttons to redirect a user to Maps and Auto Pilot Screens.

App Home         

  • Maps

        This is the main interaction screen related to the trafficpredictor project. The first screenshot in the gallery below is the main Maps screen. It has almost all GMaps Option using GMaps API.

      1. We can locate our current location using LOCATE ME button.
      2. We can Search addresses in both From and To text box. Also, we can mark the same on the MAP shown below all the buttons. This is used along with the PREDICT button. The From and To GPS latitude and longitude locations marked will be queried to the database. This will return a match from the list of available traffic free predicted data which is machine learned. [Refer the second screenshot in the gallery below, for an example of the predicted route marked in green].
      3. REGISTER button will provide the user's Journey ID using this API - https://traffic-predictor.000webhostapp.com/JourneyId.php. Hit this and you will receive a message like {"success":true,"journey_id":15} in JSON format.
      4. START and STOP buttons are used to mark the start and end of user's journey. The data (GPS latitude and longitude of current location) collected from when the user starts the journey will be stored along with the generated Journey ID. This is to keep the data as one set of entry.

 

{gallery} Maps Screen

App Maps

Image: Maps Screen

App Predicted Maps

Image: Predicted Map Route from my Journeys!

 

  • Auto Pilot

          For details on the Auto-Pilot functionality check out my blogs - Traffic Predictor #10 - Evading traffic like a Bat and Traffic Predictor #11 - Module 2 and 3 [Completed] . The GET SPEED button fetches the best speed for your current location. The GO LIVE displays your current speed and next to it a text (Move) which describes whether you have traffic or not from the Hardware communicating through Bluetooth. Also, we have a toast (below GO LIVE button) displaying the Bluetooth's MAC address.

App AutoPilot

  • About

          This screen displays what the application is all about. This gets data from the webpage - https://traffic-predictor.000webhostapp.com/About.

App About

  • Connect Device

           This is used to connect the hardware through Bluetooth. We have buttons to turn ON and OFF the Bluetooth. Also, LOAD DEVICE LIST to display the list of paired devices.

App ConnectBT

 

Database Schema

      The database for the trafficpredictor project has the below tables

          1. User - To store the user profile data.

          2. gpsData - To store the GPS Co-ordinates when the user sets out for a journey.

          3. machineLearn - To store a formatted version of gpsData with one row for a full journey.

          4. predictedData - To store the best route with less traffic_count and less duration.

          5. predictedData_Arc - To act as a backup of predictedData storing the records whenever they are inserted, updated or deleted from predictedData.

Database Schema

 

Machine Learning model

     Below is the machine learning model for my trafficpredictor project, I managed to model my thoughts and give it below. It is self-explanatory, I believe. I designed the below on Gliffy.

    

 

 

Progress made so far,

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   90%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

Traffic Predictor #11 - Module 2 and 3 [Completed]

IntegrationYet to Begin
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

Logo

Week 10 - Nov 6 - 12

 

     This will be last week in the design phase of the IoT on Wheels Design Challenge and for my trafficpredictor project. This blog will be a walkthrough of the completed modules 2 & 3. Please have a glance at my previous blog Traffic Predictor #10 - Evading traffic like a Bat for a better understanding of the progress.

Module 2 - Auto-pilot mode with predefined speed

 

Module 3 - Speed adjustment with correspondence to current vehicular movement and real-time traffic

Video - Device in action

     Below is the video where I will be explaining the entire setup shortly [Hardware explained video - Click Here] and the working of the kit in detail. The output/ outcome of these modules is the location of the obstacle(traffic) in front of the driver. This will be fed to the mobile app which will handle the rest of the processing. The final output will be posted during the integration part which will be the final blog for my trafficpredictor project. The mobile app will display the below data

  • Module 2 - Static speed output from predicted route [From ML Data]
  • Module 3 - Dynamic speed output from real-time traffic [From Hardware]

 

     The output of this current working hardware will be a serial output through Bluetooth to the mobile device. Where the app will capture it to display to the user in a formatted way. The communication data will be like

     (Location of Servo, Location of Obstacle)

 

 

Circuit Diagram

     Below is the circuit diagram of the entire hardware in my trafficpredictor project[designed using Fritzing I have also mentioned the pin in the different modules adjacent to their connection in Nucleo-L476RG board in the table below the circuit diagram

Circuit Connection

Part NamePart PinNucleo L476RG board Pin
Bluetooth moduleVcc5V
GndGnd
TXCN3 TX
RXCN3 RX
Servo MotorPulseD3 (PWM)
Vcc5V - Arduino Uno
GndGnd - Arduino Uno
Ultrasonic SensorVcc5V
GndGnd
TRIGD5
ECHOD2

 

Code to program Nucleo-L476RG board(Arduino compatible  Updated

I have pasted the entire code used for programming the Nucleo-L476RG board below You can also find the below code in my GitHub repository Click Here.

 

/*This is the code for element14 IoT on wheels design contest traffic predictor project
 * https://www.element14.com/community/community/design-challenges/iot-on-wheels/
 * 
 * Author : Dixon Selvan
 * Date   : November 08, 2017
 * Project: Traffic Predictor and Auto Pilot
 * Website: https://traffic-predictor.000webhostapp.com/
 * 
 * Hardware components
 * -----------------------------------
 1 Nucleo-L476RG microcontroller board 
 * 2. HC-05 Bluetooth module
 * 3. HC-SR04 Ultrasonic Sensor
 * 4. Servo motor
 * 
 Nucleo-L476RG Bluetooth module 
 * ------------------------------------
 *      5V        |         5V
 *      Gnd       |         Gnd
 *      TX        |         CN3 RX
 *      RX        |         CN3 TX
 */     
#include 


//Servo variables and constants
Servo myservo;
int pos = 0;
int servoPin = 3;//Nucleo pin D3


//Ultrasonic sensor variables and constants
int trigPin = 5;//Nucleo pin D5
int echoPin = 2;//Nucleo pin D2


//General variables and constants
long duration;
int distance;


void setup() {
  // put your setup code here, to run once:
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT);  


  Serial.begin(38400);//Serial Connection begin
  
  myservo.attach(servoPin);//Attaching servo pin
}


void loop() {
  // put your main code here, to run repeatedly:
  servoRotate();
}


void servoRotate()
{
  //Servo rotate from 0 to 180
  for(pos = 0; pos <= 180; pos += 2){
    myservo.write(pos);
    delay(10);
    
    distance = calculateDistance();
    
    //Send Data in the format -> (position, distance)
    Serial.print(pos);
    Serial.print(",");
    Serial.print(distance);
    Serial.println();
  }


  //Servo rotate from 180 to 0
  for(pos = 180; pos >= 0; pos -= 2){
    myservo.write(pos);
    delay(10);
    distance = calculateDistance();
    Serial.print(pos);
    Serial.print(",");
    Serial.print(distance);
    Serial.println();
  }
}


int calculateDistance()
{
  //Code to calculate Distance from Duration
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance= duration*0.034/2;
  return distance;
}

 

Hurdle

I faced trouble making the Bluetooth module communicate serially by obtaining data from D0 and D1 Serial pins in the Nucleo-L476RG board Luckily I found these articles https://os.mbed.com/teams/ST/wiki/Use-of-D0D1-Arduino-pins and known limitations - https://os.mbed.com/platforms/ST-Nucleo-L476RG/ which explained why D0 and D1 have been disabled for serial communication and gave the alternative which was CN3 TX and RX.

 

 

Progress made so far,

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   80%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

IntegrationYet to Begin
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

Logo

Week 9 - Oct 30 - Nov 5

 

     This week I have planned to design and build module 2 & 3 in my trafficpredictor project. Check out the plan - Traffic Predictor #3 - The Plan and revisions, hardware & software list - Traffic Predictor #9 - Revisions and Hardware, Software list for a better understanding of the progress as I pause module 1 progress and shift to progress in module 2 & 3.

Module 2 - Auto-pilot mode with predefined speed using Sensor Expansion board

 

Module 3 - Speed adjustment with correspondence to current vehicular movement and real-time traffic

This module 2 title has been revised as above to "Auto-pilot mode with predefined speed". Please note in future I will be referring module 2 with the revised title.

 

Auto-pilot mode - term explained

     The term Auto-pilot is used to refer the act of helping the driver/ rider of the vehicle at frustrating times of traffic by providing speed values. This will not mean or involve integrating an auto driving mechanism without a driver/ rider into a fossil fuel/ electricity-powered vehicle. The output from this module in my trafficpredictor project can be used to auto drive electric vehicles [After alterations in the electric vehicle].

 

Introduction

     Module 2 & 3 have been integrated as one module as they both stand out to be similar in terms of functionality. Both are going to output or instruct the driver/ rider to maintain a particular speed. But they have minor difference in the way of gaining the output.

  • Module 2 - Static speed output from predicted route
  • Module 3 - Dynamic speed output from real-time traffic

 

Ultrasonic sensor to measure the speed

     An ultrasonic sensor is used here to determine the distance of the moving/ static traffic objects from the vehicle. Using change in distance and time, the speed alteration required in order to avoid a collision can be calculated. The formula to do this would be,

     Speed Formula

     The setup has Ultrasonic sensor [Range: 0 to ~75cm] mounted on a Servo motor which will move from 0 to 180 degrees. This will capture a semicircle RADAR like output as shown below [Processing IDE has been used to display output as graph]. Using this the speed with which the driver/ rider should proceed will be calculated.

                   Processing IDE showing RADAR like output with input from Ultrasonic sensor

Ultrasonic RADAR setup

                              Ultrasonic sensor mounted on Servomotor

 

Hardware Explained - Video

 

The below video will explain the various hardware parts used for the entire trafficpredictor project. This has been achieved after a week's time of struggle with soldering, unit testing and integration of all the parts.

 

Do let me know your comments on the hardware build in terms for improvisation.

 

Progress made so far,

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   70%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Module 2 & 3

This blog

IntegrationYet to Begin
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

Logo

Week 8 - Oct 23 - 29

 

This blog will cover revisions made to the traffic predictor project along with a list of Hardware and Software components involved in this project.

 

This blog will be updated when changes are made to the project and it needs to be included in the below list. It can be found by the change of flag from  New --> Updated.

 

Revisions  Updated

 

ContextProposed versionBlog - ProposedRevised versionBlog - Revised
TitleTraffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board

Traffic Predictor #1 - The Official Announcement

Traffic Predictor #3 - The Plan

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic prediction with machine learningTraffic Predictor #7 - Into the traffic [Part 2 of 2]

Component

[Replacement]

Wi-Fi and Bluetooth expansion boardTraffic Predictor #3 - The Plan

Bluetooth Tranceiver

Traffic Predictor #9 - Revisions and Hardware, Software list

[Refer Hardware components table]

Component

[Replacement]

Camera/CCTV and IR sensorTraffic Predictor #3 - The PlanUltrasonic Sensor and Servo Motor

Traffic Predictor #9 - Revisions and Hardware, Software list

[Refer Hardware components table]

Title
Auto-pilot mode with predefined speed using Sensor Expansion board

Traffic Predictor #1 - The Official Announcement

Traffic Predictor #3 - The Plan

Auto-pilot mode with predefined speedTraffic Predictor #10 - Evading traffic like a Bat
Video  NewAdded MEMS expansion boardTraffic Predictor #3 Hardware explainedRemoved it

 

Video  New90-degree Servo rotation to capture live trafficTraffic Predictor #4 - Kit in action180-degree Servo rotation to capture live traffic

Traffic Predictor #11 - Module 2 and 3 [Completed]

Code updated in GitHub

 

Hardware components   Updated

 

The below table consists of the hardware components included in the traffic predictor project.

 

Product Name
Brand Name
Part Number
Purpose

Cost (INR)

* Inclusive of shipping charges

Cost

(Dollars)

Product Link
Nucleo-L476RG board STMicroelectronicsSTM32L476RG

Microcontroller board which would help in

  • Collecting GPS data from user,
  • Enabling BT/ Wi-Fi connection with the user's mobile device/ Web APIs and
  • Controlling Servo and Ultrasonic sensor.
SponsoredClick Here
Bluetooth Transceiver [HC-05]REES52arb004For exchange of information between Microcontroller and mobile device350$ 5.394Click Here
Wi-Fi Transceiver [ESP8266]REES52FZ1082For exchange of information between Microcontroller and mobile device / Web API250$ 3.85Click Here
Ultrasonic Sensor [HC-SR04]REES5225651Capturing live/ static objects in traffic with the help of ultrasonics190$ 2.93Click Here
Servo MotorKTC CONS LabsSG-90-9gFor obtaining a 180-degree capture of live traffic with the help of ultrasonic sensor240 *$ 3.70Click Here

General purpose PCB Stripboard

Solder

Wires

Header pin (Male & Female)

For IoT Expansion board100$ 1.54
Total  Updated 880$ 13.51

 

Software components   Updated

 

The below table consists of the software components included in the traffic predictor project. All of them are freely available either completely or as a trial.

 

Product NamePurposeLink
Mbed online compilerFor compiling and downloading program into the Nucleo-L476RG board Click Here
MATLABFor visualizing machine learning of traffic information through GUIClick Here
Android StudioFor making apps for the user to connect to the device and navigate using GMapsClick Here
000webhostFor making websites and API (login and registration)

Click Here

Traffic Predictor - Website

GMaps APIFor locating, navigating userClick Here
Processing IDE
For Visualizing location of moving/ static objects in traffic through Ultrasonic sensorClick Here
Arduino IDE
For uploading program into Nucleo-L476RG Board Click Here

 

Table of Contents  Updated

The below table consists of the classified table of contents included in the traffic predictor project.

 

 

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

Traffic Predictor #11 - Module 2 and 3 [Completed]

IntegrationYet to Begin
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

Logo

Week 8 - Oct 23 - 29

 

It's almost time to hit the traffic. This blog will cover up the development of login and registration screens, API and integration of the same in the mobile app. Going through my previous blog Traffic Predictor #7 - Into the traffic [Part 2 of 2]  will help in understanding the progress better. Especially the App (Android) part.

Module 1 - Traffic prediction with machine learning

APP (Android)

 

  • Login Screen

          The home screen will act as the login screen [shown below]. It consists of "username" and "password" fields along with "Login" button and "Register Here" link at the bottom. After successful login a personalized user page will be displayed [shown test version below the login screen], else an alert message would pop up to try again.

App Login Screen

App User Screen

  • Registration Screen

          The registration screen is for registering new users once they fill the "username", "password", "gender" and "country" fields and click "Register" button. On successful registration the user will be redirected to login page, else an alert will be shown to try with another username or simply to try again.

App Registration Page

  • API

          API are "Application Program Interface" are like access keys to already developed software. Mostly these will function like giving inputs and obtaining desired outputs from the API.

         

               For example, GMaps API.

 

          In the android app, when the login/ registration button is pressed by the user the data will be converted into JSON object [JSON is a standardized string format].

    

               For instance, lets consider from the login screen the below JSON contents are passed.

                        {

                               username: Dixon124;

                               password: Test;

                         }

 

          This data will be given to Login API which will read the username verify it in the database and then decrypt the stored password to compare it with the JSON input password. Then this will allow user to login. A similar process is followed in Registration API. In this project APIs are written in PHP language.

 

          The main motive of creating a user login screen for traffic predictor project is to obtain user specific location data for machine learning. This will enable easier classification of data when compared to raw location data from route A to B.

 

 

IoT expansion board:

 

For the purpose of connecting the Nucleo-L476RG board with user mobile through BT Wi-Fi I have made the below shield expansion board BT connection is achieved through HC-05 bluetooth transceiver and Wi-Fi connection is achieved through ESP8266 Wi-Fi transceiver module

custom shield

Progress made so far,

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   55%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Module 2

Yet to Begin

Module 3Yet to Begin
IntegrationYet to Begin

Logo

Week 7 - Oct 16 - 22

 

Having set up everything to kickstart the project, this blog will cover up my further progress in moving the device (Nucleo-L476RG kit plus Case) "Into the traffic". This will be the third blog covering module 1. A glance over the previous week's blog Traffic Predictor #6 - Into the traffic [Part 1 of 2] will help you in understanding trafficpredictor project progress better.

Module 1 - Traffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board

This module 1 title has been revised as above to "Traffic prediction with machine learning". Please note in future I will be referring module 1 with the revised title.

 

To be covered later/ on this blog,

 

App (Android)

Code Snippets

MATLAB GUI

Explored Kit's Storage Capacity

 

New Website for my trafficpredictor project - Home

Official Website

App (Android)

The difficulties I had faced and the workarounds used while developing the android app for my project is explained in my previous blog Traffic Predictor #6 - Into the traffic [Part 1 of 2] The app is in its initial stage and the code snippets of the app will be posted in the next blog once completed. The screenshots of the app are given in the gallery below. The app has the following menu,

  1. Home - The homepage will include the login page for each user. This will help in aggregating data and personalizing output for each user. Now it includes a simple text "Welcome!".
  2. Maps - This is the main page of module 1 which will provide the user with the functionality of navigating to his destination. It will involve recording data of latitude, longitude and time of travel. Then these data will be processed to provide the user with a suggestion of the best route.
  3. Autopilot - This will be an option for module 2 & 3 which will be discussed in later blogs.
  4. About -This is a simple page describing the app.
  5. Connect Device - An option which provides user connection with the device (Nucleo-L476RG kit) via either of the following
    • Bluetooth
    • Wi-Fi

 

{gallery} Android App Screenshots

Home

Image 1: Home

Menu

Image 2: Menu

Zoomed View

Image 3: Zoomed map

Map with marked location

Image 4: Map with marked location

App with icon

Image 5: App Icon

 

MATLAB GUI

Sneak peak of the MATLAB GUI was given in the blog - Traffic Predictor #5 - Machine Learning and Building a case for the kit. Since MATLAB program has to be deployed in a server, a GUI will not be needed. But for a developer, an optional GUI to study the patterns of traffic will be essential. To facilitate this, changes are being made to the existing machine learning GUI already developed and make it suitable for learning traffic-related data.

 

[The completed version of the MATLAB GUI will be posted soon]

 

Explored kit's mass Storage Capacity

I have been misled by the term "mass storage". Actually, it has referred to a set of computing communications protocols that would make a USB device accessible to the host computing device and enable file transfers between the host and the USB device. Little less I was aware that it referred to the below and I conceptualized it to be a storage with more space.

Reference of the above: Nucleo-L476RG from ST and Wiki

 

Before this reality was understood, am happy that I had prepared the method of data storage and retrieval which would be over the web/ remote through Google spreadsheets This will not involve storing data either in the Nucleo-L476RG board or user's mobile device

 

 

 

Progress made so far,

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   50%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Module 2

Yet to Begin

Module 3Yet to Begin
IntegrationYet to Begin

 

Logo

Week 6 - Oct 09 - 15

 

     Having set up everything to kickstart the project, this blog will cover up my further progress in moving the device (Nucleo-L476RG kit plus Case) "Into the traffic". This will be the second blog covering module 1. A glance over the previous week's blog #5 will help you in understanding trafficpredictor project progress better.

Module 1 - Traffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board

To be covered later/ in this blog,

 

App (Android / Web)

Code Snippets

MATLAB GUI

Explored Kit's Storage Capacity

 

App (Android)

     It took me almost a day & more than 5GB internet data to complete Android studio SDK along with AVD installation. Meanwhile, I tried few online mobile apps and websites for android application development sites (These are restricted to basic layout modifications & fewer functionalities when compared to Android Studio). Out of the available websites to develop an android app, I found the following websites to be best:

     Advantage - They had faster time from development to production plus more options and layouts. And overall they are FREE!

 

     The main limitation I felt using Android Studio is, it uses most of the computer's RAM (Full capacity of the computer - 4GB). This results in freezing/ hanging off my computer due to 90+% RAM usage. This is severely impacting the application development process as and when I need to test the code I have to wait for 10 to 20 minutes to visualize the output in the Virtual Device Emulator. Credits to IObit's performance monitor which saved my computer from most of the hanging part with an option "Clean RAM" [Refer below screenshot - Broomstick icon].

 

     One more option which I tried out was to reduce the RAM allotted to the AVD from and select Graphics to be Hardware. Refer below screenshot for steps which are given inside the screenshot.

Android Studio AVD Settings

 

If you have suggestions to make Android Studio work fluently without hanging while emulating the output, please do share in the comments section below.

[App is under development and details will be posted in the next blog...]

 

GPS Data

     GPS data collected from the user has to be saved in a database for further processing (Machine Learning). I have planned to transfer data to Google spreadsheets which would be cost and time effective in the testing phase. After the successful test and on demand of huge traffic of data, it can be moved into a database ( preferably SQL/ DB2).

 

Challenging part - GPS & Wi-Fi

     Being not aware of the process of extracting information from GPS satellites through GMAPS API and integrating it to work with the kit, it is really a bit challenging. Though initially, I felt connecting the kit to the internet will be easier, it becomes challenging as I progress.

 

  • Wi-Fi Expansion Board - The Wi-Fi Expansion board X-NUCLEO-IDW01M1 comes with a handy instruction manual from the ST (Download it here). As per the manual, I set up the apache server on my PC and managed it through XAMPP. But I was not able to receive messages as instructed in the manual [Refer Screenshot below]. This can be due to the version difference, version from when they had prepared the document to the version available currently. This led me to a state where I am unable to ensure Wi-Fi expansion board setup is complete. Otherwise, things are good to go.

Wi-Fi Expansion board messages

 

  • GPS - Being the heart of the project I am still clueless to start things with GPS though I have an idea of how would things work.

 

How I overcome - Thank you DAB after your comment, I had some spark to work with. It is a bit challenging to begin with GPS, provided there is no sensor in the kit for directly receiving GPS data. Hence I have planned to kick things through the mobile app. I have now started to use GMAPS API and it is very interesting to work with.

 

Tutorials which helped me are GMAPS API for Android - by Google & the below tutorial in youtube

 

 

 

Progress made so far,

|||||||||||||||||||||||||||||||||||||||||||||||||||||||   40%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Module 2

Yet to Begin

Module 3Yet to Begin
IntegrationYet to Begin

 

Logo

Week 5 - Oct 02 - 08

 

This week I have planned to design and build module #1 which would the biggest and the main module in my trafficpredictor project. In this blog, I have covered up the machine learning concept/ algorithm to be used. Along with this, I am going to unveil the case to be used for mounting the Nucleo - L476RG kit in the vehicle.

 

I am still exploring ways to utilize the kit's storage capacity, once done will share the same in my future blogs.

Module 1 - Traffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board

So far everything to kickstart my trafficpredictor project has been completed.

Plan

Code Editor & Software IDE required

 

Yet to come

App (Android / Web)

Code Snippets

MATLAB GUI

 

Machine Learning  New

 

     Machine learning (ML) has been the talk of the town along with Artificial intelligence (AI). ML is an interesting area because we can teach the computer how to identify objects/ face through computer vision (CV) / predict data. The reason I have opted for machine learning to predict traffic is its ability to process a huge amount of data and convert them into a single output.

     There are two main types of machine learning - Classification and Clustering. I have chosen to classify data into either best route with less traffic or route with traffic, this would fall under type classification. This is one way because of my prior experience with classification type machine learning in MATLAB and also it better suits the project purpose.

Data refers to GPS data - latitude & longitude from API plus time at which data was recorded.

Output refers to resultant of machine learning process - probably a route which is predicted to have less traffic.

GUI for machine learning

     I have a GUI developed in MATLAB already for machine learning smells which can be seen below. The graph plotted to the left (Classification) separates the fragrance of one perfume from other (separated by a line).  The graph to the right (Clustering) clusters the smell values around the 'X' marked and thus separates them.

Machine Learning GUI MATLAB

     Link to share your thoughts in Discussions related to the above project "Odor Detector", if interested - Is it possible to transmit and receive smell?

 

{tabbedtable} Tab LabelTab Content
Building a case for the kit  Updated

Check out the next tab for"How to connect Nucleo-L476RG board to USB Charger Power Bank

 

The case has been built to hold/mount the Nucleo-L476RG kit onto the vehicle therefore while on travel we can record the GPS location data in future modules to identify real-time traffic The case includes two provisions one to hold the MCU board with expansion boards and the other to hold the battery pack power bank Though the case is not an enclosure type it is hard enough to protect the case hold the kit and battery in position even in tough terrains and allows easier access I have added below photos video of the kit inside the case and mounted onto my bike

 

For those who are not able to afford 3D - Printers like me, I would suggest Mechanix Metal - 4. It has been much help in bringing my designs into life at a much faster rate.

 

{gallery} Case for the kit

case 1

Image 1: Case mounted in bike's handlebar

Case 2

Image 2: The Case

Case 3

Image 3: Case and the bike


Travel with the newly built case - Video

 

Please do not attempt to record audio / video while driving the vehicle alone or without any safety harness and auto recording equipments.

How to connect Nucleo-L476RG board to USB Charger Power Bank

Mobility would be the key criteria when it comes to moving the prototype to real-traffic to gather data for machine learning. So I have decided to use my 20,000mAh power bank with 5.1V 2A output as the external power source.

 

Steps to connect Nucleo-L476RG board to USB Charger Power Bank

  1. Connect the Nucleo-L476RG and the USB Charger Power bank using the USB type A to mini-B cable
  2. Make sure JP5's pin 1 and 2 are connected using a jumper (U5V).
  3. Turn ON JP1(using a jumper) to enable power supply from the USB Charger/ Power Bank.

Nucleo-L476RG board connected to power bank

 

Reference for this article: Nucleo-L476RG Datasheet

 

Please find below links to my previous blogs on my traffic predictor project for IoT on Wheels design Challenge,

Blog 1 - The Official Announcement

Blog 2 - Quest for the code editor

Blog 3 - The Plan

Blog 4 - Finally, the kit arrives

Logo

Week 3 - Sep 18 - 24

 

                         Below is the overall layout/ plan of the traffic predictor project

Plan

Module 1: Traffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board

 

Components:

HardwareSoftware
Nucleo L476RG boardMbed Compiler/ VS Code
GPS sensorGMaps API
Wi-Fi Expansion boardMATLAB & Arduino (Mobile Application)

 

This holds the key functionality of the project. Data will be collected from user such as,

  1. Location
  2. Time
  3. Traffic

The collected data is machine learned to develop a pattern with time & traffic in a particular location. This will help users avoid traffic.

 

Module 2: Auto-pilot mode with predefined speed using Sensor Expansion board

 

Components: Module1's components +

Hardware
Sensor Expansion board

 

While on traffic one would easily get bored up. Enabling an auto-pilot mode with a predefined speed from data collected & real-time feed will help one relax.

 

Module 3: Speed adjustment with correspondence to current vehicular movement and real-time traffic

 

Components: Module1, 2's components +

Hardware
Camera/CCTV
IR sensor

The real-time feed is obtained through calculating the position of other vehicles from our vehicle. This is used for adjusting the speed of the vehicle.

 

Please find below links to my previous blogs on my traffic predictor project for IoT on Wheels design Challenge,

Blog 1 - The official announcement

Blog 2 - Quest for the code editor

Logo

Week 4 - Sep 25 - Oct 01

 

Finally, the kit made its way home. And there you have the stunning pictures of the NUCLEO-L476RG kit.

Nucleo L476RG board sponsored from IoT on Wheels design challengeNucleo L476RG board with addons sponsored for IoT on Wheels design challenge

 

Below is the code for the "BLINK LED" program which is the "Hello World" program for electronics to test the Nucleo MCU board.

 

Digital Pins D8 & D13 have been chosen as output pins and have been declared differently. I love the way the LD1 changes from red to green when I feed in the program into the MCU board.

 

#include "mbed.h"
PinName digitalPin = D8;
int main() {
    // put your setup code here, to run once:
    DigitalOut myled(digitalPin);
    while(1) {
        // put your main code here, to run repeatedly:
        myled = 1; // LED is ON
        DigitalOut(D13, 0);
        wait(0.5); // 500 ms
        myled = 0; // LED is OFF
        DigitalOut(D13, 1);
        wait(0.5); // 500 ms
    }
}

 

 

For "Blink Led program" to begin your coding with Nucleo L476RG please visit this link.

For "Hello IoT program" to begin your coding with Nucleo L476RG with steps to start a project in the Mbed online compiler please visit this link.

 

Please find below links to my previous blogs on my traffic predictor project for IoT on Wheels design Challenge,

Blog 1 - The Official Announcement

Blog 2 - Quest for the code editor

Blog 3 - The Plan

Logo

Week 2 - Sep 11 - 17

 

The Kit is on its way to my place   So far I have received an email from the shipping company with estimated delivery on September 19, 2017. Meanwhile, I did not want to waste my time. Hence I started my quest for the code editor with which I can type and test my code.

 

Below are some editors I use for electronics coding with its purpose & link.

 

EditorPurposeLink
Arduino IDEFor Arduino based developmenthttps://www.arduino.cc/en/main/software
MATLABFor GUI and machine learning algorithmshttps://in.mathworks.com/downloads/web_downloads/
Processing IDEFor better showcasing Arduino outputshttps://processing.org/download/

 

After hours of surfing and testing, I found the below editor to be lightweight and which could be used for coding NUCLEO-L476RG

 

VS Code - Download here

 

Visit this link to find some code to start coding NUCLEO-L476RG with. Mbed has its online compiler where you can also become a user to start coding online.

 

Please let me know in comments below if you have trouble kickstarting with VS Code for your project.

 

Please find below links to my previous blogs on my traffic predictor project for IoT on Wheels design Challenge,

Blog 1 - The official announcement

Logo

Week 1 - Sep 6 - 10, 2017

 

Thank you element14 & IoT on wheels design challenge team and all concerned for selecting me to be sponsored with NUCLEO-L476RG kit to compete in the challenge. I received a warm welcome back at my place when I shared about the selection of my project idea by element14. Overall I am thrilled to start my project work to complete it before the deadline November 13, 2017.

 

Project Modules

 

The Traffic Predictor project consists of the below three submodules

 

  1. Traffic prediction with machine learning on an added advantage of mass storage capability of the STM32 Nucleo-64 development board.
  2. Auto-pilot mode with predefined speed using Sensor Expansion board.
  3. Speed adjustment with correspondence to current vehicular movement and real-time traffic.

 

Though it is a tough task to complete within two months, with all your support and love I head on to give my level best.

 

All the best contestants

Logo