Interface and application programming
Assignment 

Write an application that interfaces with an input &/or output device that you made, 
comparing as many tool options as possible

 

         Application that interface to MPU 6050 module
 
This is a test jig to see if a MPU6050 connected to a DIY Atmega328P is working properly. To do that. An real time aviation  horizon display shows the data graphically by tilting the scale bar and horizon line.





 
 
Hardware includes a DIY Atmega328P based board interfaces to PC via a FTDI cable. if everything works, I will make a DIY shield piggybacked on the Atmega328P board. The shield will houses the MPU-6050 module.

The  MPU-6050 sensor contains a  accelerometer and a  gyro in a single chip. It is very accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C-bus to interface with the Atmega 328 board.


The interface application is developed with Processing. Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping. 

More on how to use processing can be found at: 

        https://processing.org/ 
How the application works

On the left, you can see the main part of the program. 
First the setup() setups the serial communication with the Atmega328 board at 15200 bps. 











In processing, draw() is the main program loop. There are 4 main functions to decode the information from MPU6050 via Atmega328 boards. 
First is Horizon(), this function paints the main background and displays the angular scale as shown below.















Next is the PitchScale() which displays the ladder pitch diagram as shown below.















Axis() is the function that displays the row graphical information.














And finally, the plane() function display the static horizontal wing.
















Serial port; 
float Phi; //Dimensional axis 
float Theta; 
float Psi; 
 
void setup()  
{  
size(700, 700); //was 1400, 700 
rectMode(CENTER);  
smooth();  
// strokeCap(SQUARE);//Optional  
 
println(Serial.list()); //Shows your connected serial ports 
port = new Serial(this, Serial.list()[0], 115200);  
//Up there you should select port which arduino connected and same baud rate. 
port.bufferUntil(' ');  


 
void draw()  
{  
background(0);  
translate(W/4, H/2.1);  
MakeAnglesDependentOnMPU6050();  
// Horizon();  
// rotate(-Bank);  
// PitchScale();  
// Axis();  
// rotate(Bank);  
// Borders();  
Plane();  
 


 
void serialEvent(Serial port) //Reading the datas by Processing. 

String input = port.readStringUntil(' '); 
if(input != null){ 
input = trim(input); 
String[] values = split(input, " "); 
if(values.length == 3){ 
float phi = float(values[0]); 
float theta = float(values[1]);  
float psi = float(values[2]);  
print(phi); 
print(theta); 
println(psi); 
Phi = phi; 
Theta = theta; 
Psi = psi; 


}