Hello, everyone!



Let's start this assignment!



In this assignment, I have:

  1. To design and build a wired &/or wireless network connecting at least two processors.



An important part of my final project is the network of the remote stick and main Board. That's what we'll do.


I have 2 MCs. ATiny45 at stick and into the main board - ATmega328.


And the finished boards.



What about the code? Really complicated - to create a stable protocol between MCUs. But I was able to implement it.

Both codes here:


Main board code:

It grabes the data from uart (bluetooth),
filtering it,
and sends drive pulses to the motors.

  
  
#include SoftwareSerial.h

int val; 
String inputString = ""; 

boolean stringComplete = false; // whether the string is complete 


SoftwareSerial BTSerial(8, 9); // RX | TX 

void setup() 
{ 
Serial.begin(9600); 
BTSerial.begin(4800); 
inputString.reserve(200); 
} 

void loop() 
{ 
// print the string when a newline arrives: 

// clear the string: 
if (stringComplete) 
{ 
Serial.println(inputString.toInt()); 
inputString = ""; 
stringComplete = false; 
} 
serialEvent(); 
} 

void serialEvent() 
{ 
//Serial.println(1); 
int i = 0; 
while (BTSerial.available()) 
{ 
//Serial.println(2); 
char inChar = (char)BTSerial.read(); 
i++; 
if (i < 2) 
{ 
//Serial.println(3); 
inputString += inChar; 
} 
if (inChar == '\n') 
{ 
stringComplete = true; 
} 

} 
}
 
  

Stick code:

It calibrates the axes of the joystick,
determines the maximum and minimum position
and sends data via port.

  
  
#include SoftwareSerial.h


int Xmax = 0, Xmin = 255, Ymax = 0, Ymin = 255; 
int posX, posY; 
int MposX = 0, MposY = 0; 


SoftwareSerial BTSerial(1, 2); // RX | TX 

void setup() 
{ 
pinMode(4, INPUT_PULLUP); 
BTSerial.begin(4800); 

delay(500); 
for (int i = 0; i < 10; i++) 
{ 
MposX += analogRead(A2); 
delay(10); 
} 
delay(100); 
MposX = MposX / 10; 
delay(100); 


} 

void loop() 
{ 


posX = analogRead(A2); 
// Keep reading from HC-05 and send to Arduino Serial Monitor 

if (posX > Xmax) 
Xmax = posX; 
if (posX < Xmin) 
Xmin = posX; 

if (posX < MposX) 
posX = map(posX, MposX, Xmin, 50, 1); 
else 
posX = map(posX, MposX, Xmax, 51, 99); 

BTSerial.println(posX); 
delay(50); 

} 

 
  

The video of working:


To download the Altium project of MCU click here.


To download the Altium project of Joystick click here.


To download the MCU .png click outline, outline filled, trace.


To download the Joystick .png click outline, outline filled, trace.


Thank you.