Paul__B:
Most of us who are prepared to look at code here are not prepared to download it from an "ino" file and even less so "C", you need to use the "code" tags to post each in a meaningful form within the text - according to the instructions.
The connections between the two systems should be straightforward and you would realise the requirement for a common ground. The ATmegas use 5 V logic (the term "TTL" is a misnomer as it is not TTL logic levels at all) and presumably so does the 8051. As you have - apparently - connected each of these in reality to a PC and exchanged data correctly in each direction, you clearly should know all about the necessary connections.
So if it is not working, it is because the code is not working. A simulator is not going to tell you why it is not working and is even more likely to have some subtle additional restriction to make matters even more problematic than the Real Thing.
@Paul__B: Okay! Sorry for any inconvenience caused due to uploading the .ino and .C files. I had no clue there are 'upload rules'!! Anyway, here's my Arduino code. I'll post the C code for 8051 in the next reply.
P.S: I have made the common GND connection and connected the Arduino with PC and the 8051 with Arduino. But I am unable to read any Data received from the 8051 to understand if I've received the correct data or not, for my .C code to actually work.
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3, myservo4;
int blueToothTx = 7;
int blueToothRx = 8;
char h;
unsigned int realservo;
String dataread;
SoftwareSerial bluetooth = SoftwareSerial(blueToothTx, blueToothRx);
void setup()
{
/*
pinMode(2, OUTPUT); // Input 1 L293D
pinMode(3, OUTPUT); // Input 2 L293D
pinMode(11, OUTPUT); // Input 3 L293D
pinMode(12, OUTPUT); // Input 4 L293D
*/
myservo1.attach(5);
myservo2.attach(6);
myservo3.attach(9);
myservo4.attach(10);
// Set up Serial Communication to PC
Serial.begin(9600);
// Set up Bluetooth serial Communication to Android
bluetooth.begin(9600);
}
void loop()
{
if(bluetooth.available())
{
delay(10);
h = bluetooth.read();
if( h == '~')
dataread = bluetooth.readStringUntil(','); //Read data Serially
else
{
unsigned int servopos = h;//Serial.read();
unsigned int servopos1 = bluetooth.read();//Serial.read();
realservo = (servopos1*256) + servopos;
//Serial.println(realservo);
}
}
//dataread = inData //make String 'forward','back', 'left', 'right'
if (dataread.length()>0)
{
//Serial.println(dataread);
if(dataread == "UP")
{
delay(100);
Serial.write('W');
//Serial.println(" Fwd ");
}
else if(dataread == "BACK")
{
delay(100);
Serial.write('R');
//Serial.println(" Rev ");
}
else if(dataread == "LEFT")
{
delay(100);
Serial.write('A');
//Serial.println(" Left ");
}
else if(dataread == "RIGHT")
{
delay(100);
Serial.write('R');
//Serial.println(" Right ");
}
else if(dataread == "STOP")
{
delay(100);
Serial.write('S');
//Serial.println(" Stop ");
}
else if(dataread == "OPEN")
{
delay(100);
Serial.write('O');
//Serial.println(" Open ");
}
else if(dataread == "CLOSE")
{
delay(100);
Serial.write('C');
//Serial.println(" Close ");
}
dataread = ""; //Reset the Variable
}
//read from Bluetooth and write to serial port
if( realservo >= 1000 && realservo <1180)
{
int servo1 = realservo;
servo1 = map( servo1, 1000,1180,0,180);
myservo1.write(servo1);
Serial.println(servo1);
delay(10);
}
if( realservo >= 2000 && realservo <2180)
{
int servo2 = realservo;
servo2 = map( servo2, 2000,2180,0,180);
myservo2.write(servo2);
Serial.println(servo2);
delay(10);
}
if( realservo >= 3000 && realservo <3180)
{
int servo3 = realservo;
servo3 = map( servo3, 3000,3180,0,180);
myservo3.write(servo3);
Serial.println(servo3);
delay(10);
}
if( realservo >= 4000 && realservo <4180)
{
int servo4 = realservo;
servo4 = map( servo4, 4000,4180,0,180);
myservo4.write(servo4);
Serial.println(servo4);
delay(10);
}
}