Principles and Practices Assignment 1

What is my Project ? "Moustic"

I want to Build a Platform That will be FOR PwD " People with Disabilities " As wireless mouse that they can use it in presentation or can be used in Gaming as a wireless joystic ..

The Idea came from When I was In college Studying Electronics and Electrical Engineering .. I spent a lot of time searching for how to interface and control any input for the computer and build my interface with it as a my own customized kit for my PC thing ..

Story Behind :


So I tried a lot to learn About Embedded systems , Communication Which I spent years to understand how can i send and receive data from and to Computer which I was amazed after I saw arduino for the first time as there were Serial Monitor which I was very happy that this thing can do this .. Then I Found to Processing and I was very happy to start working with .. as In same time I had Learnt Image Processing And Using Python and how to Use Programming good .

So as a first application after all milestones to build My Device Ready to use I Decided to control a arm Robot Through Equations and Image processing and Communications and MultiThreading .. And that was my Output then ..




Then I Thought about make a mouse as a second Idea and Try to integrate my new mechanical skills with electronics and programming for the first time and try to make a full prototype for the first time as that is my important target for the academy from day one .. to learn new things and push myself out of the comfort zone .. As you saw I took CAD , machines and Project management very So far Out of my comfort zone ..

So my Strategy is to Make a mouse that is wireless to can play or Present with or to be used by the People with Disabilities PwD as I feel that will more Easily to use .. and can be easily use and make hand feel free and rest .. so i see how my hand looks like in normal postion for it and decided to use the analog joystic as it is an idea out of the box .. and this will tackle Electronics , Programming , Communication , Interfacing , CAD and Subtractive Technology in Casing for the Device Plugged at the Laptop and Addative Technology in Print the hand mount that we can be easily to left and not heavy .

What am I going to do ? "Tasks"

Those are my tasks ..

Transmitter :

Is a device that will be the input circuit for the system which carry the analog joystick and communicate through bluetooth which is already paired with another one in the output circuit also have a very challenge Cad Design for a mount that can wear it in my finger to can use it .

Receiver :

Is a device that will Receive the data from the Input circuit and Output it on the Leds to show the changes that happen .. and Also Pass the data to the computer on the data bus ..

Interfacing :

Is the Software on computer that will control the Mouse and Receive data from the Output Circuit

Communication Bus :

Is the Logic of communicating three devices on same bus and how to handle data from one to another to show and keep tracking data flow going .. On the other hand make the communication not to depend on time .. But there are a way of communication between each one of them to keep tracking data flow without missing any bit .. ..

What processes will be used? "In Details"

Tasks Details..

Transmitter :

  1. Design A hand Mount to can carry my device and feel light to your hand and protect the system ..  
  1. This Will be made Using 3D printer to Print the Mount #Assignment
  2. This will be made Using Vinyl to do the branding .. I prefered to paint it as Phase 1 of the Prototype As I figured Out Practically the Painting will Stay longer than the Vinyl .. So I Decided to use the Paint Process #Assignment
  1. Design a PCB that read the data of the Analog and Transmit it to the output through bluetooth
  1. This will be made using CNC Milling Machine #Assignment
  1. Programming to Read From the Sensor and Send Data to Bluetooth
  1. This will be made in Communication Assignment #Assingment 

Receiver :

  1. Design A mount for My PCB that can hold everything
  1. This Will be made Using Lasercutter to Print the Mount #Assignment
  2. THis will be made Using Vinyl to do the branding #Assignment
  1. Design a PCB that read the data of the Analog and Transmit it to the output through bluetooth
  1. This will be made using CNC Milling Machine #Assignment
  1. Programming to Read From the Sensor and Send Data to Bluetooth
  1. This will be made in Communication Assignment #Assingment 

Interfacing :

  1. Write a code that can Interface with the 2 Pcbs in same time ..  
  1. Testing Using Processing This Phase to Test that the device is Communicating Well as Quick testing before establishing the Python Code
  2. Testing Using Python .. This is the Final Test and this is the software that will Make the Mouse Move #Assignment

Communication bus :

  1. Draft a language to control data from a device to another to keep flow going without have any missing bits  ..  
  1. Draft
  2. Implement in Communication Week #Assignment

What materials and components will be required? "In Details"

Component

Amount

Price for 1

Link

Res 10K

2

$0.05

LINK

Res 499

4

$0.05

LINK

Capacitor 10UF

2

$0.1

LINK

RED LEDs

4

$0.25

 LINK

FTDI Header

1

$0.25

LINK

HC-05 Bluetooth Module

2

$17

LINK

ATTINY44A-SSU-ND

2

 £0.596

LINK

ISP Pin Header

2

$0.83

LINK

Female Pin Header

17 Pin

$0.1

LINK

PLA

18 gm

$0.1

Local

vinyl

10 cm2

$0.2

Local





Final Project Progress

CAD Desing


For the Final Project .. I Designed on Freecad a 3D printed part ..

and this is how it looks like ..

Here I started to sketch it

Those the Dimensions of my Objects



Here I tested the Dimensions







Then I succedded I designed the Full Design ..

I need to make a quick box with pressfit ..
so I Used Makercase to make it .. And I then I Edited it to make fit with my Electronics Board design ..


and this is the box :D


3D Printing

then this is was how I start working on it on Cura ..



and this is was the part after finishing ..

This is after I painted it :D :D But I was so close when I painted it as I was at home and tried to take care of the enviroment around me


## Before Starting With Electronics And Programming ..
The Software Development Model I am going to use is the Spiral Model as I need to make a quick Prototyping and get a quick result without having a long planning phase .. also to divide the project to 3 or 4 small wins to feel and can Measure How much I am now in the Project ..

For More Details about Spiral Model Check this Documentation

Input Circuit

Here Is the Input Circuit For the Project .. Which have a Analog Joystic and Bluetooth
This is circuit is read analog the x and y Dimensions and Read Digital the Push Button .. and Start Sending it Over the Bluetooth To the Output Circuit
I am going to need a Analog joystic to can read the directions and have pushbutton to use a click for the mouse as a Left click

I need also a Bluetooth to make it can use it wirelessly ..

I need FTDI and ISP to can Program and test it serially before applying Bluetooth in the Communication Assignment ..


BOM :

Main Board As a Block

1) Attiny 44
2) Res 10k
3) Cap 10UF
4) ISP Connector
5) FTDI Connector

Then I Added my special Circuit Component :
1) Bluetooth Pin Header
2) Joystic Pin Header
3) Analog Joystic Module
4) Bluetooth HC-05

For Joystic You need to take in consideration the Orientations of the Pins and Its arrngement ..

also Take in Consideration the arrange of the Pins of the Bluetooth to can deliver power and read data right .. and take care of the Orientation you will use ..

You can Find here all component I used with links where to buy it and it is name to can find datasheet ..






Here are the Files to Be fabricated on CNC ..



Then I start to To fabricate it ..

Then This is How it looks like my Final Input PCB ..
This how it looks like with Component




This is the code I am Going to Use ..

This code Read 3 Things Read the Analog Data from x and y .. and Read Digital Data for the Push Button and Send it Over Serial To the PC to Test the Circuit working ..
Important Note about the code : I Divided the Values of Analog on 100 To can reduce the Noise ..
To Understand the Code Syntax and How I Wrote it .. You can Check my Embedded programming Assignment As I made There a full Illustrating for How to use Arduino and What is all Functions I used There ..
     
     #include‹SoftwareSerial.h›

  
#define BUTTON PA3
#define x PA2
#define y PA3
#define btn PA4

#define val 0

#define tx PA0
#define rx PA1
SoftwareSerial ser(rx, tx);
void setup() {
  // put your setup code here, to run once:

ser.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
ser.print("Switch:  ");
  ser.print(digitalRead(btn));
  ser.print("\n");
  ser.print("X-axis: ");
  ser.print(analogRead(x))/100;
  ser.print("\n");
  ser.print("Y-axis: ");
  ser.println(analogRead(y)/100);
  ser.print("\n\n");
  delay(500);
}
     


This is it :D :D The Working Circuit


For more Testing and Ensure that All Project is Going to Work ..
I will make test with 2 Things :
1) Processing " TO check Serial Working Okay "
2) Python to Control The Mouse


Processing is a Very Good tool to transform your data to graphics or to make it to shapes or Changing in Colors .. For a CheatSheat for Processing you can Find this one which is Great .. cheatSheet This is also a document I made 2 years ago .. in arabic for Processing for How to use it for First time Processing Arabic Introduction
I need to just to test if it was reading data with the sequance I want or not ..

So the Interfacing Here Depends on Sending Charachters " x , y, b " For X axis and Y Axis and Push Button and Send the value after ..

I built my Code on Already Made Example in Processing Inside the Examples of Serial Communication Called Simple Read .

this example supposed to show the impact of changing values on a Box Color and and Background color to just show the changes ..

 /**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
char val;      // Data received from the serial port
int x , y , btn;

void setup() 
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.readChar();         // read it and store it in val
    if (val == 'x')
  {
    if ( myPort.available() > 0) {  // If data is available,
    x = myPort.read();
    }
    
    
  }
  
    if (val == 'y')
  {
    if ( myPort.available() > 0) {  // If data is available,
    y = myPort.read();
    }
    
    
  }
  
    if (val == 'b')
  {
    if ( myPort.available() > 0) {  // If data is available,
    btn = myPort.read();
    }
    
    
  }
  
  }
  
  
  
  
  
  background(x);             // Set background to white
  if (btn == 1) {              // If the serial value is 0,
    fill(y);                   // set fill to black
  } 
  else {                       // If the serial value is not 0,
    fill(204-y);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}





This will make some changes in the amount of the filling and the background color .

Testing Processing Code ..

This is Python Code that will work on how to control the mouse for Final Project ..

What is going to do here .. Is using Library called pyautogui to Control the Mouse as there are more ways to make it and this will happen in the developing of the project to make the Output device send data directly to X11 in the Kernel of Ubuntu ..

After I transofrmed the data coming from the Input Circuit , to The Output Circuit , to the PC It was a very challenging to come iver the Noise in the first phase .. So I Transformed it to deigital and Make it works as Steps in the 2 axis ..

x=10
y=10
import time
import pyautogui
import serial
ser = serial.Serial('/dev/ttyUSB0')
kk=0
line1=0
line2=0
line3=0
while 1 :
	line = ser.read()
	print "---------"
	if line == 'x' :
		line1 = int(ser.readline())
		#x=x+line1
		x=line1
		x=x*5
		kk=0
	elif line == 'y' : 
		
		line2 = int(ser.readline())
		y=line2
		y=y*5
		#y=y+line1
		kk=1
	elif line == 'b' : 
		line3 = ser.readline()
		if line3 == '1' :
			pyautogui.click(x,y)
	if kk ==1 :
		pyautogui.moveTo(x, y)
	#time.sleep(1);
	print "btn = " , line1 , " x = " ,  line2 , " y = " , line3
		

    
    

Python Testing

Reading data on Python ..


Moving Python Depending on Data COming from Sensor ..




Output Circuit

Here Is the Output Circuit For the Project .. Which have a 4 LEDs and Bluetooth ..
This output circuit is used for Receiving data from the Input Circuit and Start SHowing it is impact on the LEDs as Indicators and Start Control the Communication bus to dont miss any data or conflict together .. so It receives from the Input and Put it on Hold until Send it to the PC and show it in the Indicators and Then comeback to read from the input ..

In Details :
I am going to need a bluetooth in the circuit to communicate Communication assingment at future with the input assignment I made before to read the Analog joystic Data ..

Then I will need LEDs as Indicators for The system that is receiving the Data Correctly from the input circuit and Show it on the LEDs and a LED for bluetooth to show that there are a connection .. That is Connected to State pin in the Bluetooth

And FTDI and ISP to can Program and send Data to Computer through serial to start moving the Mouse and Circuit interact with the Interface program ..
BOM :

Main Board As a Block

1) Attiny 44
2) Res 10k
3) Cap 10UF
4) ISP Connector
5) FTDI Connector

Then I Added my special Circuit Component :
1) Bluetooth Pin Header
2) 4 LEDs
3) 4 Res 490
4) Bluetooth HC-05

Important Informations about the SMD LEDs .. the Negative side of it you will Find a Green line on a side that is the negative side .. and you need to take on Consideration this in the design .. Also LEDs need a Resistance that is 499 OHm to can deliver to it the amper that it is want ..

also Take in Consideration the arrange of the Pins of the Bluetooth to can deliver power and read data right .. and take care of the Orientation you will use ..

Then I start Building on it .. and this is the result ..




Here are the Files to Be fabricated on CNC ..



But I didnt notice this while I was making it on Fab Modules .. That there are a short circuit .. and this Short circuit happened because of I had in the design a circle because of un finished trace that I didnt See that above my trace that makes fab modules see them as 1 Trace and Didnt figure out that they are 2 Traces ..

the other issue that I need to take in consideration next is to leave a little more space between traces as I wanted to make my PCbs Design Perfectly Design with the Smallest Size and Traces ..

As A Credit For My Instructor Hagag He Had a Great idea Like you will see at the picture that he removed all the lines and let just the ground .. and this what happen .. the machine removed the short circuit ..



This is the error



Then This is How it looks like my Final Output PCB ..
This how it looks like with Component




This is the code i used for the output circuit ... Which read the data coming from the the Input circuit and Test it with LEDs and Pass it To the FTDI to Send it to the Connected Computer .

A Important note about the code ..
I Transform the Analog Readings to Digital Because of the Noise ..
To Understand the Code Syntax and How I Wrote it .. You can Check my Embedded programming Assignment As I made There a full Illustrating for How to use Arduino and What is all Functions I used There ..
    
    #include ‹SoftwareSerial.h›

  
#define x PA2
#define y PA3
#define btn PA4

#define tx PA0
#define rx PA1
SoftwareSerial ser(rx, tx);
void setup() {
  // put your setup code here, to run once:

ser.begin(9600);
pinMode(x,OUTPUT);
pinMode(y,OUTPUT);
pinMode(btn,OUTPUT);
}

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

  if (ser.available()) {
     char val = ser.read();
     if (val == 'x')
     {
      if (ser.available()) {
         int mov =  (ser.parseInt());
         if (mov > 5)
         digitalWrite(x,HIGH);
         else
         digitalWrite(x,LOW);
      }
     }
     else if (val == 'y')
     {
      if (ser.available()) {
         int mov =  (ser.parseInt());
         if (mov > 5)
         digitalWrite(y,HIGH);
         else
         digitalWrite(y,LOW);
      }
     }
      else if (val == 'b')
     {
      if (ser.available()) {
         int mov =  (ser.parseInt());
         if (mov ==1)
         digitalWrite(btn,HIGH);
         else
         digitalWrite(btn,LOW);
      }
      
      
     }
  }
     
  delay(500);
}

This is The working Circuit With the live data


Communication

The Draft for how the Communication is going to work ..

Now we need to Produce our communication system between the two boards and Laptop on same bus ..

First to maintain the data flow I make a Feedback Communication With each data slave Circuit " Output Circuit " Receive , Send to the master Circuit " Input Circuit " To send next Data ..

So 1 For Send Which Data it will send xor y or Btn , 2 For sending the value ..

So Here Slave controlling the master ..

Next Thing .. How To communicate data with My PC ..

As My sensor is not very accurate and Have a huge Noise .. SO i Determine to make it Digital By Making a average value that above is plus below is Minus So For x the Slave Circuit will Send on Same Bus a for Plus , b for minus and y is c,d and Button is e,f ..

That is it

This is the code I used in Each Circuit and PC and With the GUI ..

First code for Input Circuit : ..

To Understand the Code Syntax and How I Wrote it .. You can Check my Embedded programming Assignment As I made There a full Illustrating for How to use Arduino and What is all Functions I used There ..
 //#define F_CPU 20000000UL
#include 
char control();
  
#define BUTTON PA3
#define x PA2
#define y PA3
#define btn PA4
#define val 0

#define tx PA0
#define rx PA1
SoftwareSerial ser(0, 1);
void setup() {
  // put your setup code here, to run once:
pinMode(btn,INPUT);

pinMode(x,INPUT);
pinMode(y,INPUT);

ser.begin(9600);

}
int casse=0;

int casse1=0;
void loop() {
  // put your main code here, to run repeatedly:
  while(!(control() == '1'))
  {}
  ser.print("b");
while(!(control() == '2'))
  {}
  ser.print(digitalRead(btn));
  casse = analogRead(x);
  casse1 = analogRead(y);
casse = map(casse ,0,1024,0,20);
casse1 = map(casse1 , 0,1024,0,20);
  //delay(200);
while(!(control() == '1'))
  {}  ser.print("x");
while(!(control() == '2'))
  {}  ser.print(casse);
  
while(!(control() == '1'))
  {}  ser.print("y");
while(!(control() == '2'))
  {}  ser.print(casse1);

  
}

char control ()
{
   while (!ser.available()) {
     
     
   }
   return ser.read();
      

}

    

First code for Output Circuit : ..

To Understand the Code Syntax and How I Wrote it .. You can Check my Embedded programming Assignment As I made There a full Illustrating for How to use Arduino and What is all Functions I used There ..
 #include 

  
#define x PA2
#define y PA3
#define btn PA4
#define tx PA0
#define rx PA1
SoftwareSerial ser(0, 1);

void setup() {
  // put your setup code here, to run once:

ser.begin(9600);
pinMode(x,OUTPUT);
pinMode(y,OUTPUT);
pinMode(btn,OUTPUT);

}

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

ser.print("1");

  if (ser.available()) {
     char val = ser.read();
      
     
      
     if (val == 'x')
     {
      ser.print("2");
      while(1) 
      if (ser.available()) {
         int mov =  (ser.parseInt());
      if(calc(mov)==1)
      ser.print("a");
      else
      ser.print("b");
      delay(10);
      ser.print("1");
         if (mov > 5)
         {digitalWrite(x,HIGH);
                     break;
}
         else
         {

         digitalWrite(x,LOW);
         break;
         }
      }
     } else if (val == 'y')
     {
      
      ser.print("2");
      while(1) 
      if (ser.available()) {
         int mov =  (ser.parseInt());
if(calc(mov)==1)
      ser.print("c");
      else
      ser.print("d");
      delay(10);
      ser.print("1");
         if (mov > 5)
         {digitalWrite(y,HIGH);
                     break;
}
         else
         {

         digitalWrite(y,LOW);
         break;
         }
      }
     } 
     else if (val == 'b')
     {
      
      ser.print("2");
      while(1) 
      if (ser.available()) {
         int mov =  (ser.parseInt());

      ser.print("1");
         if (mov == 1 )
         {digitalWrite(btn,HIGH);
         ser.print("e");
                     break;
}
         else
         {
ser.print("f");
         digitalWrite(btn,LOW);
         break;
         }
      }
     }
      
      
    
  }
delay(100);     
}





int calc (int mov)
{
  if(mov>6)
  return 0;
  else
  return 1;
}

    

Third code for Python On Laptop : ..

 x=100
y=100
import time
import pyautogui
import serial
ser = serial.Serial('/dev/ttyUSB0')
kk=0
line1=0
line2=0
line3=0
while 1 :
	line = ser.read()
	print line
	print "---------"
	if line == 'a' :
		
		if(x< 6<00):
			x=x+10
	elif line == 'b' : 
		if(x>0):
			
			x=x-10
	elif line == 'c' :
		
		if(y< 600):
			y=y+10
	elif line == 'd' : 
		if(y>0):
			
			y=y-10
	if line == 'e' :
		pyautogui.click(x,y)
	elif line == 'f' : 
		print "nothing"
			
	pyautogui.moveTo(x, y)
	#time.sleep(1);
	#print "btn = " , line1 , " x = " ,  line2 , " y = " , line3
		

    

Fourth code for Processing : ..

 
  /**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
char val;      // Data received from the serial port
int x = 100, y=100 , btn=0;

void setup() 
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, "/dev/ttyUSB0", 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.readChar();         // read it and store it in val
    if (val == 'a')
  {  
    if(x<300)
    x=x+50;
  }
  
   else if (val == 'b')
  {
      
    if(x<50)
    x=x+50;
  }
   else if (val == 'c')
  {
      
    if(y<300)
    y=y+50;
  }
   else if (val == 'd')
  {
     
    if(x>50)
    x=x-50; 
  }
   else if (val == 'e')
  {
      btn=1;
  }
   else if (val == 'f')
  {
      btn=0;
  }
  }  
  
  
  
  background(x);             // Set background to white
  if (btn == 1) {              // If the serial value is 0,
    fill(y);                   // set fill to black
  } 
  else {                       // If the serial value is not 0,
    fill(204-y);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}
    


Testing Processing Code ..

Everything Working Together

Integration

This is after trying the Mount I made ..

Those are the last things :) :D with Updates :)

Output Circuit and Communication Master in It's Laser Cutter Mount


Input Circuit and Communication Slave in it's Painted 3D printed Mount


As I was working Along on Integration so I this is what I took in consideration and what to do for Next Phase Enhancement :

1) The 3D printed Part and the Input Circuit is one part now as the circuit fit exactly at it's mount .. For next Phase I will add place for a Nail to fix the Joystic at the mount or make the Width fit exactly with the joystic ..

2) The Laser Cutter part and Output Circuit is one Part Now as the circuit fit exactly .. And I broke a laser cutter part once to extract the Circuit but for next Phase I will make it with nails to easy exchange the circuit if i want as this wont be need at future but For Extremes I need to take this in consideration ..

3) Powering the Joystic I will take in Consideration at circuit and the mount to put a Powerbank and Put a Female USB in the circuit to can power it up .. But for the Circuit now I power it with external power from FTDI Pins ..



This is my Presentation




This is my Video For Final Project