ThinAVR v0.9: The Slim and Minimalist AVR development Board

A While ago I mentioned the need for a minimalist and cheap embedded development board .You may read my previous post here: Developing Slimmer AVR board

It was that day when I designed the prototype and today, I present to you :




A minimum AVR development board with what you need to get started.

The Initial Silk-less Give-Away model
Smooth Edges and Simplified design

Dimensions as that of a Credit Card!

Ergonomic and Simplified PCB Layout

The Size equivalent to the size of your credit card and powered by an ATmega32 at its heart .It gives ThinAVR the following capabilities:


In addition to the above features that are provided by ATmega32 alone, ThinAVR also comes with:
  • A 16X2 LCD connection port mainly for program debugging operations,connected on Port C
  • Additional Power and Ground Pins for interfacing external circuits
  • External Crystal Oscillator for reliable UART/USART operations.The Internal clock just doesn't make it for UART
  • Mounting holes on all 4 corners for a robust design
  • In-Built ISP Port so that you can always reprogram your board.
  • Push Button Power Switch because Reliability
  • On Board Voltage Regulation for protection from over-voltages
  • Power On Indication LED
  • Ergonomic Dimensions the size of a credit card
  • Sleek Look and Slim design

The board is expected to bridge the gap between a development board and a functional embedded system project by making the platform so affordable that each project has its own ThinAVR.

The Initial batch of ThinAVR has been distributed to aspiring embedded developers for a faster growth curve, proper feedback and a higher adoption rate.

ThinAVR v0.9beta :
-No Silk, Markings with a sharpie
-Female connectors for ports,Male Connector for 16x2 LCD
-12MHz Crystal Oscillator
-Embedded ATmega32
-Power Circuit
-Need ISP Programmer to burn programs.

The Next version therefore will have more or less things.

The Mightiest Tree grew from a tiny seed.
Peace Out.

Line Follower using Neural Nets : Part 2 (Designing the Neural Net )

This post is the second in the series of developing a neural net line follower. For the post covering dataset generation, go here

Once data is handy, the next objective in a Neural Net is to plan out its structure.
Neural nets are mostly used for uncertain and non-linear operations as is our task of pattern matching a.k.a Classification.

A neural net has mainly the following layers which map the input to the output
  • Input Layer
  • Hidden Layer(s)
  • Output Layer
The Number of Hidden Layer is a deterministic on the complexity of the task being performed.For example, A deep learning net might contain more hidden layers for a deeper defragmentation of data.However there is a trade off between Depth and Speed of execution, therefore for our case, a single hidden layer would be enough.

The Designed Network looks as depicted here:

8 : 1 mapping through a hidden layer of two nodes (and one bias unit)

Intuition says this will be sufficient for our task as a partition in half can easily tell which side of our sensor strip sees the line.

For details of what a neural network is, I would recommend going through the following site: Neural Networks and Deep Learning

For activation function in our network, I have used tangent sigmoid function:
Tangent Sigmoid Function
For faster development time, the neural net designer tool in MATLAB is used.For the sake of understanding, an algorithmic view is as shown:

x = 1 X 8;                                             {Input from 8 nodes}
W12   =   2 X 8;                                     {Weight Matrix from Input layer to Hidden Layer}
Z1= x*(W12)T = (1X8 * 8X2)= 1X2;   {Mapping from Input layer to Hidden layer}
A1= TanSig(Z1)= 1X2;                         {Activation of Hidden Layer}
W23 = 1 X 2;                                        {Weight Matrix from Hidden layer to Output Layer}
Z2 =A1*(W23)T = (1X2 * 2X1)=1X1; {Mapping from Hidden layer to Output Layer}
A2=TanSig(Z2);                                    {Activation of Output Node}
Y=A2;                                                                    {Output}

The specifications are set up in the NNFit tool in MATLAB and data obtained from the previous post is used to train the network using Backpropagation Algorithm. After the training completes, the entire process is stored as a script using the prompt window.

By default the script generated contains a lot of redundant information which can be optimised on examination.
The entire script is reduced to the following:

 function [y1] = NNLF(x1)   
 %NNLF neural network simulation function.  
 %  
 % Generated by Neural Network Toolbox function genFunction, 13-Aug-2016 14:40:30.  
 %  
 % [y1] = NNLF(x1) takes these arguments:  
 %  x = Qx8 matrix, input #1  
 % and returns:  
 %  y = Qx1 matrix, output #1  
 % where Q is the number of samples.  
 %#ok<*RPMT0>  
 %(c)Sanjeev Tripathi ( AlphaDataOne.blogspot.in )   
 % ===== NEURAL NETWORK CONSTANTS =====  
 % Layer 1  
 b1 = [-8.8516132798193108e-10;2.1615423176361062];  
 IW1_1 = [-30.312171052276302 -15.230142543653209 -7.5989117276441904 -3.8426480381828529 3.8426480396510354 7.5989117277872076 15.230142543113857 30.312171051352024;1.1787493338995503 1.1684723902794487 -0.30187584946551604 -1.2505266965306716 -0.85655951742083458 -0.61361689937359887 -0.51938433720151178 0.43601182390986715];  
 % Layer 2  
 b2 = -3.5519126834821509e-10;  
 LW2_1 = [1.0000000099939996 2.6043564908190074e-09];  
 % ===== SIMULATION ========  
 Q = size(x1,1); % samples  
 x1 = x1';  
 xp1=2*x1 -1;  
 xp1=cast(xp1,'double');  
 a1 = tansig_apply(b1 + IW1_1*xp1);  
 a2 = repmat(b2,1,Q) + LW2_1*a1;  
 y1=a2;      
 end  
 % Sigmoid Symmetric Transfer Function  
 function a = tansig_apply(n,~)  
 a = 2 ./ (1 + exp(-2*n)) - 1;  
 end  

The Neural Net being run uses the pre optimized weights to map the input to the output with an accuracy of 100% (High Variance) as the dataset contained all the possibilities. A demo of our net for different inputs entered manually is as shown:


As stated earlier,
        -1 informs to move left 
        +1 informs to move right 
        ~0 informs to keep moving forward

The network of nodes can compute with accuracy any width,orientation or order of line with absolute accuracy. It can also detect multiple lines simultaneously as the network has been trained for all the possible inputs that it can encounter.

An Implementation on AVR Atmega32 microcontroller to be covered soon.
Stay Tuned for more.

Peace Out

Used:
Matlab 2016a

Line Follower using Neural Nets : Part 1 (Generating Data Set)

Neural Networks are convenient when mapping a function which behaves non-linearly. However, for Training and Testing purpose , Data is the most important piece of the puzzle.

The Neural Network Line Follower to be designed uses 8 Line sensing elements where each will return
 1 : Line Detected
 0 : Line Not Detected

So the possible dataset is the combination of 8 binary units arranged in different pattern leading to a total of
            28 =  256 Samples of data.

I wrote the following MATLAB script to create the data for training the Neural Network.

 function [bin,out]=DataGen(m)  

 % Function to Generate Training Data set for training neural network of a  
 % line follower  
 %    
 %     [bin,out]=DataGen(number of inputs)  
 %       
 % It is a good practice to have an even number of input units for the  
 % NN Network to be trained  
 n=(2^m)-1;              
 bin=decimalToBinaryVector(0:n);   
 [p,q]=size(bin);             
 out=zeros(p,1);   
 bLeft=bin(:,1:(q/2));  
 bRight=bin(:,((q/2)+1):end);  
 wL=bi2de(bLeft,'left-msb');  
 wR=bi2de(bRight,'right-msb');  
  for i=1:p  
    if wL(i)>wR(i)  
      out(i)=-1;  
    end   
    if wL(i)<wR(i)  
      out(i)=1;  
    end  
    if wL(i)==wR(i)  
      out(i)=0;  
    end    
  end  
 end  

Here:
         bin holds the binary input sequence of 8 bits    
         out holds the output corresponding to the input bin

Such that:
          if bin=[1 0 0 0 0 0 0 0]  then out = -1      (Line Sensed on far left : Move Left)
          if bin=[0 0 0 0 0 0 1 0]  then out =  1      (Line sensed on right : Move Right)
          if bin=[0 0 1 0 0 1 0 0]  then out =  0      (Line sensed symetrically : Keep Moving Forward)

For a Neural Network,  0 is pretty much a perfection so it allocates a really small value (~0) such that it can be considered as zero.

From the script above with 8 as a parameter via the following syntax:
           [bin,out]=DataGen(8);
we get:
           bin = 256 X 8 Input Data Matrix
           out = 256 X 1 Output Data Matrix

In the screenshot of the varibles, Left Segment shows the input from the sensors while we have the expected output in the blue bounded box on right:


These Data elements are ready to be used as Training Parameters for our Neural Network.
Further Development to be covered by subsequent posts.

Update 7/Sep/16 : Read Part II: Designing Neural Network

Peace Out.

Used:
Matlab 2016a

RoboAuto : Arduino Bluetooth Joystick for Android™


HC-05 has an added advantage in embedded systems that pretty much every smartphone is equipped with in built Bluetooth hardware.This opens up a large number of possibilities for access and control of embedded systems.

There are apps that do the task of controlling a system via bluetooth however none sufficed to my requirement. So I developed one,

Presenting  
RoboAuto

An Android Application for communication with HC-05 Bluetooth Module.
RoboAuto is a clean and effective app using which you can control your Robots or Devices with a Simple Joystick!
  
What RoboAuto does:

Program Flow

So, You as an embedded developer have to configure your robot only for the commands received from the app!

Here are few screenshots:






RoboAuto connects to the Bluetooth Module using a Wireless Serial Link. Android already provides support for this in their native API.

After a successful connection, characters are sent to the module on actuation of joystick ,buttons or check boxes which can be read and executed by Arduino™ or other microcontrollers.

Special Thanks to zerokol for his JoystickView Library.
The Joystick sends the following :

Forward: F
Backward: B
Left : L
Right : R

Additionally I have assigned intermediate directions , for example, FL for Front-Left, BR for Backward-Right and so on.
No Changes are to be required on the Embedded side as the UART only parses a single character at a time, giving us simultaneous (in theory) Forward and Left motion. Kind of like what happens in a PWM.

Download RoboAuto here:
Get it on Google Play
Google Play and the Google Play logo are trademarks of Google LLC.

This Post therefore will be updated soon and is worth a bookmark.
UPDATE (22/October/17): Savvy has been renamed to RoboAuto and published on Google Playstore
UPDATE (10/August/16) : Few Screenshots and content have been updated!
UPDATE (25/August/16 ):  Savvy(Now RoboAuto) is available for testing and debugging for FREE
UPDATE (12/September/16): Added Internet Access permission for Google Form Integration.
UPDATE (19/March/17): Fixed a lot of bugs in the layout scale. Renamed "Turn Light" to "Rear Light."

Do report any bugs you encounter.
Credits (19/March/17):  Thank You Shivani for your Feedback on Design Issues

Good Stuff Take Time.

Used:
Android Studio 2.3.3
Lenovo S6600 , Micromax Knight Cameo for Debugging.

Programming and Simulation of AVR with HC-05: PART II

The final build of my work with HC-05 involves using AVR ATmega32 microcontroller which is a powerful micro controller. The Controller is programmed in AVR GCC.

For HC-05 (or any other serial communication system), the USART needs to be set on the ATmega32 through programming.
Here is a snippet of code being used for UART in my build:

Setting up UART


The Primary task of responding to various commands is done by a switch statement which is way easier to modify and work on instead of  IF-ELSE statements.Since Each character has a unique ASCII Code, we have a lot of commands which can be given to the micro controller.For example ,there are 26 lower case + 26 upper case + 10 digits + about 32 symbols which equal about 94 unique commands.
Snippet of code for Switch:

Decision Task by Switch Statement

The character 'ch' is set to receive value from registers whenever the receive interrupt is triggered by the HC-05.The ISR (Interrupt Service Routine) is defined as follows:

Interrupt Service Routine

Simulation of code is done in Proteus 8.4 using all the peripherals included. Input here is given from a virtual terminal however HC-05 would have served the same objective.

Simulation in Proteus

A video accompanying the simulation conveys that the code works fine and can be implemented into the hardware.Here's the vid :


Used:
Proteus 8.4
Atmel Studio 7.0