Amazing resource for learning C++

C++ is very powerful language and learning it can be a bit daunting for some. I’ve found a beautiful course in MIT OCW.

The link to the course is as follows: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-096-introduction-to-c-january-iap-2011/lecture-notes/

It doesn’t matter if you are learning from scratch or want a quick refresh on your concepts, this is the course for you.

The examples taken in the slides are to the point and relevant in real life coding. Concepts like constructors, destructors and even the tricky ones like pointers, memory management and templates to name a few are beautifully explained.

If you don’t have a compiler and IDE installed then the CodeBlocks IDE is a great bundle. Here is a link to the windows bundle : http://www.codeblocks.org/downloads/26

If you are a beginner then codeblocks-17.12mingw-setup.exe is the file you should download (this advice is given on codeblocks site).

Hope this helped!

Embedded C programming using AVR Studio on Arduino Boards

For those of you who have an Arduino development board and wanted to code in embedded c and upload your code on the board, this is the right post.

For starters you need to download following components:
1. Arduino IDE Download Link
2. AVR Studio Download Link or AVRDUDE download

We shall be using AVRDUDE utility for burning our programs onto the micro-controller.

Once you’ve installed above programs. We can begin the setup of AVR studio using AVRDUDE for burning our programs.

First you must locate following two files:

  1.  avrdude.exe : If you have installed Arduino IDE then a sample path for this file is as follows. C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe
  2.  avrdude.conf : Similarly for Arduino IDE installation the path is as follows. C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf

If you are using AVRDUDE direct download, then these files shall be in the avrdude installation folder. example: C:\avrdude\avrdude.exe and C:\avrdude\avrdude.conf

We shall require both of these paths in the subsequent steps, so kindly ensure you’ve copied these two paths and kept it somewhere.

Next step is detecting which COM port your arduino board uses.

devicemanager

In my case the port used by the Arduino Board is COM3. Keep this information with you.

Now the AVRDUDE arguments is as follows:

  1. Arguments for Arduino Mega 2560
    -v -patmega2560 -cwiring -P COM3 -b115200 -D -Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i -C"C:\avrdude\avrdude.conf"
  2. Arguments for Arduino UNO
    -v -patmega328p -carduino -P COM3 -b115200 -D -Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i -C"C:\avrdude\avrdude.conf"

I shall explain few important command line options used in above commands. The detailed explanation for all the options is given in following documentation.
options
Now that we understand about the commands that shall be used, we can proceed with the creation of AVR Studio programmer.

avrstudioprogrammer

Steps:

  1. Open AVR Studio.
  2. Under tools select external tools.
  3. Press add.
  4. Name your programmer in the Title field.
  5. Paste the appropriate arguments in the Arguments field.
  6. Paste the avrdude.exe file path without the quotation marks in the Command field.
  7. Check the ‘Use Output window’ box.
  8. Press OK.

Now you have your programmer available in the tools menu above the external tools sub-menu.

You can upload a LED blinking program to your board to check whether everything is working.

Steps for testing

  1. Create a new GCC executable project
  2. Make your main.c file
  3. Build the project so that the hex file is generated
  4. Go to Arduino Programmer in the tools menu and click on it
  5. You should get an output window

If everything works you will have the hello world blinking LED.

Hope you liked the post. If you found it useful, please like and share! Remember sharing is caring 🙂

Patient Monitoring Smart Wheelchair

As part of my final year project our team chose the topic as Patient Monitoring Smart Wheelchair. We wanted to make something for the society. As a part of one of my earlier projects Improving Infrastructure for specially challenged citizens in Vashi we had conducted a survey. We found out that the existing infrastructure in Vashi(Navi Mumbai, India) is not at all disabled friendly and same is the situation in majority of India. On top of that the modern assistive technology is too expensive for the common man or aam aadmi.

proportion of diabled population

Above figure shows the percentage of disabled population to total population in India as per 2011 census. In states like Maharashtra, Andhra Pradesh etc. the percentage is very high.

type of disability

Above figure shows the proportion of disabled population by type of disability. We can see that disability in movement accounts for 20.3 % and multiple disability 7.9%. This led us to the idea of making a smart wheelchair.

rural vs urban

This shows that a major chunk of the disabled population lives in rural India. Our market analysis led us to the finding that all the modern electric wheelchairs available in the market have outrageous price tags.

market analysis

So we decided that our wheelchair would be affordable. Then depending on the analysis of disabilities we found out which all modes should be incorporated into this smart wheelchair.

The modes selected are :

  • Voice control mode
  • Gesture control mode
  • Joystick control mode

Patient monitoring was thought of as an added service. Initially the plan was to measure heart rate, body temperature and blood pressure. But due to time constraints we limited to just measuring body temperature and displaying it on a LCD.

Here is a short video of the completed project.

The bill of materials is as follows.

bom

As you can see we achieved the cost reduction. So that is all from my side in this post. Thank you for patiently reading this and reaching till the end. If you people want a post about the technical details I will require at least 10 Word press likes Winking smile. Share with as many as you can. Maybe someone will take this idea to the next level. Thank you once again for reading this post.

 

P.S: I just felt like sharing this news article with you all.

http://economictimes.indiatimes.com/news/politics-and-nation/government-set-to-bring-private-sector-under-the-new-disability-legislation/articleshow/48780998.cms

Gesture control for PowerPoint presentation

Basic idea of the project

The intention of this tutorial is to learn how to control computer keyboard and mouse events using your micro-controller. For demonstration I have chosen to name the project as gesture control for PowerPoint presentation. At the end of this tutorial you will be able to control the slides using your gestures. Now in order to control the operating system you need a language like python, java, c++ etc. I find python affable and powerful so I’ll be using that for coding. You can use any language you want but the logic and algorithm will remain the same, only the syntax will differ. I won’t be teaching you python in this post that is beyond the scope of this post. If you want to learn the language there is plethora of content available online. You just need a net connection and off you go.
P.S. : If you like the posts do like and share them with others.

Python

Python is an easy to learn high level programming language. It is a beautiful and a very powerful language. The packages that are available make it kind of limitless. Some of the places where python is used are mentioned below.

  • Google makes extensive use of Python in its web search systems.
  • The popular YouTube video sharing service is largely written in Python.
  • The Dropbox storage service codes both its server and desktop client software primarily in Python.
  • The Raspberry Pi single-board computer promotes Python as its educational language.
  • NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming tasks.

So we know that most of the big shots use python. Now they use it for a reason and the reason being that its simply an awesome language. If you want to start learning programming you ought to start with python. Here are a list of sites and books that you may use for learning python.

  1. https://www.python.org/about/gettingstarted/ (This is the official page where you can learn how to install the IDE and get started.)
  2. Learning Python, 5th Edition (This is a good book if you are new to programming and otherwise as well.)
  3. http://www.learnpython.org/
  4. http://www.tutorialspoint.com/python/

Once you get the hang of it then you can directly use the documentations for learning how to use the packages.

pySerial and PyUserInput

We will be requiring these modules in our project. The names are quite self explanatory the former is for serial communication while the latter is for the mouse and keyboard events. The links to these modules are:

Well download these and install them. I recommend you to use 32bit python 2.7 version modules as well as the language. Because most of the modules are available for 2.7 version.

Components and Software requirements

  • A microcontroller board with UART capability e.g. MSP430G2 Launchpad, Arduino Uno board etc.
  • An accelerometer e.g. ADXL335 etc..
  • Python 2.7 , pySerial & PyUserInput modules

Connections

connections

I have used fritzing for making this. Here is the link to their home page.  http://fritzing.org/home/

Logic

We will calibrate the accelerometer and take readings for left and right position. Use the serial monitor for this. Read my tutorial titled Capacitive Accelerometer Interfacing if you don’t know what I am talking about. Next once you have those digital values you need to make the program for slide control. We know that left arrow and right arrow keys are used for navigation purpose. So in our python script the if statements will contain code for left arrow button press and right arrow button press. Note that you are reading the values that the controller is sending serially using python and taking decisions based on that value.

Energia Code

int x_pin = A0;
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(x_pin,INPUT);
  analogReference(INTERNAL2V5);
}

void loop()
{
  // put your main code here, to run repeatedly:
  int x = analogRead(x_pin);
  Serial.println(x);
  delay(500);
}

Python Script

__author__ = 'MANPREET'
'''
This is a file for controlling keyboard events.
'''
from pykeyboard import PyKeyboard
import serial
import time

comPort = raw_input("Please enter the COM port number")
baudRate = raw_input("Please enter the baud rate")
myserial = serial.Serial(comPort, baudRate)
k = PyKeyboard()
TRUE = 1;
try:
    while (TRUE):
        if (myserial.inWaiting()):
            mydata = myserial.readline()
            x = int(mydata)
            print(x)
            if x > 650:
                k.tap_key(k.left_key)
                print("left")
                time.sleep(1)
            if x < 550:
                k.tap_key(k.right_key)
                print("right")
                time.sleep(1)
except KeyboardInterrupt:
    print("stop")

Code Explanation

The Energia code is pretty straightforward but still just to cover that as well. We have declared A0 i.e. P1.0 pin as input and changed the ADC reference voltage to 2.5V in line 7. Next part is just getting the ADC reading and sending it serially.

The python code demands some explanation. So lets begin understanding the code .

from pykeyboard import PyKeyboard
import serial
import time

This code will import three modules PyKeyboard, serial and time. For the pykeyboard we have imported the constructor. Then you have made one object k using the same.

comPort = raw_input("Please enter the COM port number")
baudRate = raw_input("Please enter the baud rate")
myserial = serial.Serial(comPort, baudRate)
k = PyKeyboard()

myserial is an object of the serial module that you have imported. You will use this to access its functions. The raw_input() is for taking the com port and baud rate values from the user. Example COM11 and 9600.

TRUE = 1;
try:
    while (TRUE):
        if (myserial.inWaiting()):
            mydata = myserial.readline()
            x = int(mydata)
            print(x)
            if x > 650:
                k.tap_key(k.left_key)
                print("left")
                time.sleep(1)
            if x < 550:
                k.tap_key(k.right_key)
                print("right")
                time.sleep(1)
except KeyboardInterrupt:
    print("stop")

Well this is an infinite loop and you are checking this block for keyboard interrupt i.e. ctrl+c . This is done so that you can come out of the program properly without having to kill the program. Next we are checking if there is data in the serial buffer. If yes then we are storing it in mydata variable. Convert it into integer and store it as some variable say x. Next step is easy write two if statements and include the code and condition for left arrow button press and right arrow button press. For more details of the PyKeyboard module visit : https://pypi.python.org/pypi/PyUserInput/0.1.9
For running the python script install python 2.7. Copy paste the python script code into notepad and save it as gersturecontrol.py(or any name for that matter) Then follow these steps.

  1. Open command prompt(Press windows+r, then type cmd and press enter.)
  2. opening_command_prompt

  3. Change the directory to the one containing your python script i.e. the .py file. Use cd for that.
  4. file_location

  5. Use python gesturecontrol.py for running your code
  6. running the program

  7. For stopping the code press ctrl+c

Thank you for reading the post and hope that it was helpful.If you like the post do share it with others and spread the knowledge.

Wireless Notice Board using SIM 300 and EK-TM4C1294XL

Well I just loved the idea of a wireless noticeboard which will display the notice whenever some sms is sent to it. That way you can intimate the concerned people about the notice or information even if you are not physically present at the location. This can be used in colleges wherein two notice boards can be installed per department. One will be used by the principal and the other may be by the head of dept. or the teachers. This is a quick way to send the info. So starting with the list of materials required.

Components

  • Micro-controller board with at least two hardware UARTs(not mandatory but will be beneficial.)
  • SIM 300 module or equivalent(with the charger etc.)
  • Some display e.g. LCD, dot matrix, graphical LCD etc.

Connections

connections

EK-TM4C1294XL Pins

TM4C129-X11-—-Pins-Maps

Code Explanation

The main objective is to extract the message from the received message. Now you can use some special character for this but I’ve decided to use the concepts of html tags. So my tag is <s></s>. Whatever is written in these tags will be displayed. String object provides beautiful string manipulation functions. So we will not reinvent the wheel but use it in our application so to speak. Let’s look at the code that will extract the message from the received data.

  char buffer[250];
  Serial.readBytes(buffer, 250);
  String message = buffer;
  String command = "<s>";
  String commandEnd ="</s>";
  int indexOfMessage = message.indexOf(command);
  int indexOfMessageEnd = message.indexOf(commandEnd);
  if(indexOfMessage>0 && indexOfMessageEnd>0){
  String actualMessage = message.substring(indexOfMessage+3,indexOfMessageEnd);
  Serial.print("Message             :");
  Serial.println(message);
  Serial.print("Command             :");
  Serial.println(command);
  Serial.print("CommandEnd          :");
  Serial.println(commandEnd);
  Serial.print("Actual Message      :");
  Serial.println(actualMessage);
  actualMessage.toCharArray(actualMessageArray,250);

We are making two strings command and commandEnd. These will store our tags. Next we need to find the index of these tags. For this we use indexOf() and this will return –1 if the string is not present. So we need to send the message only if both the indices are not –1.Next is just one toCharArray(), this is for the LCD function. Also the serial printing is just for our reference. You may remove those lines.

The scrolling part is taken from arduino cook book. Here is the link.

Thank you for reading this. If you liked this post do share it with others!!

Entire Code

#include <LiquidCrystal.h>;
LiquidCrystal lcd(42,44,49,50,70, 69);

const int numRows = 2;
const int numCols = 16;
char actualMessageArray[250];

void setup()
{
	  // put your setup code here, to run once:
	  Serial.begin(9600);
	  Serial7.begin(9600);
	  Serial7.println("AT");
	  while(Serial.available()>0)
	  {
		Serial.print((char)Serial.read());
	  }
	  delay(1000);
	  Serial7.println("AT+CMGF=1");
	  while(Serial.available()>0)
	  {
		Serial.print((char)Serial.read());
	  }
	  delay(1000);
	  Serial7.println("AT+CNMI=2,2,0,0");
	  delay(100);
	  while(Serial.available()>0)
	  {
		Serial.print((char)Serial.read());
	  }
	  delay(1000);
	  lcd.begin(numCols, numRows);
	  lcd.setCursor(0,0);
}

void loop()
{
  // put your main code here, to run repeatedly:
 if(Serial.available()>0)
 {
	  char buffer[250];
	  Serial.readBytes(buffer, 250);
	  String message = buffer;
	  String command = "<s>";
	  String commandEnd = "</s>";
	  int indexOfMessage = message.indexOf(command);
	  int indexOfMessageEnd = message.indexOf(commandEnd);
	  if(indexOfMessage>0 && indexOfMessageEnd>0){
	  String actualMessage = message.substring(indexOfMessage+3,indexOfMessageEnd);
	  Serial.print("message          :");
	  Serial.println(message);
	  Serial.print("command          :");
	  Serial.println(command);
	  Serial.print("commandEnd       :");
	  Serial.println(commandEnd);
	  Serial.print("actualMessage    :");
	  Serial.println(actualMessage);
	  actualMessage.toCharArray(actualMessageArray,250);
	 }
 }
  marquee(actualMessageArray);
  delay(1000);
  lcd.clear();
}
void marquee( char *text)
{
	int length = strlen(text); // the number of characters in the text
	if(length < numCols)
	lcd.print(text);
	else
	{
		int pos;
		for( pos = 0; pos <= numCols; pos++)
		lcd.print(text[pos]);
		delay(1000); // allow time to read the first line before scrolling
		pos=1;
		while(pos <= length - numCols)
		{
		lcd.setCursor(0,0);
		for( int i=0; i < numCols; i++)
		lcd.print(text[pos+i]);
		delay(300);
		pos = pos + 1;
		}
	}
}

Serial Monitor Output

notice board

Video