Hi,
I have used the default G15 Shield Libraray & have connected my Shield to Arduino Mega. I am using the default settings of Software serial pin 2 & 3 for Rx & Tx and Pin 8 for Control. I am trying to print the current position of the Servo on the serial monitor. When I connect the shield to Uno and run the program, the servo rotates and prints position, but when i connect the Shield to Arduino Mega & run the same program, the servo rotates but nothing gets printed on the Serial Monitor. My program is as follows:
#include <SoftwareSerial.h>
#include <Cytron_G15Shield.h>
Cytron_G15Shield g15(2, 3, 8); // SoftwareSerial: Rx, Tx and Control pin
//Cytron_G15Shield g15(8); // HardwareSerial: Control pin
#define G15_31 31
#define LED 13
word error = 0;
byte data[10];
word position = 0;
void setup()
{
g15.begin(19200);
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
g15.exitWheelMode(G15_31);
delay(2000);
}
void loop()
{
g15.setSpeed(G15_31, 500); // Set G15 (ID = 1) speed to 500,
g15.setPosAngle(G15_31, 90); // Set G15 (ID = 1) position to 0 deg
delay(1000);
error = g15.getPos(G15_31, data); // Get G15 ID1 knob position
if(error == 0) // No error
{
digitalWrite(LED, LOW);
position = data[0];
position = position | (data[1] << 8);
Serial.print(position); // Print position
Serial.print(" ");
Serial.println(ConvertPosToAngle(position)); // Print angle]
delay(1000);
}
else // Error occur, LED on CT UNO will light up
{
digitalWrite(LED, HIGH);
}
delay(200);
g15.setSpeed(G15_31, 500); // Set G15 (ID = 1) speed to 500,
g15.setPosAngle(G15_31, 270); // Set G15 (ID = 1) position to 0 deg
delay(1000);
error = g15.getPos(G15_31, data); // Get G15 ID1 knob position
if(error == 0) // No error
{
digitalWrite(LED, LOW);
position = data[0];
position = position | (data[1] << 8);
Serial.print(position); // Print position
Serial.print(" ");
Serial.println(ConvertPosToAngle(position)); // Print angle]
delay(1000);
}
else // Error occur, LED on CT UNO will light up
{
digitalWrite(LED, HIGH);
}
delay(200);
}
May i know why position is not getting printed on serial monitor while using Arduino Mega, should i change any pins or the Library files???