G15 Servo Shield Connected to Arduino Mega

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

G15 Servo Shield Connected to Arduino Mega

Postby Shanunp » Sat Mar 07, 2020 4:48 pm

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???
Shanunp
Greenhorn
 
Posts: 2
Joined: Sat Mar 07, 2020 4:41 pm

Re: G15 Servo Shield Connected to Arduino Mega

Postby ober » Mon Mar 09, 2020 10:04 am

I believe that is due to soft serial on Arduino Mega is different with Arduino UNO.

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).


I am taking this from Arduino.cc page: https://www.arduino.cc/en/Reference/softwareSerial

So I would suggest using D10 for RX, D11 for TX. You need to move the mini jumpers on the shield to respective header pins. And of course, your code need to change too.
Cytron_G15Shield g15(10, 11, 8); // SoftwareSerial: Rx, Tx and Control pin
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: G15 Servo Shield Connected to Arduino Mega

Postby Shanunp » Thu Mar 12, 2020 1:15 pm

IT WORKED!!!!!! Thank you very much.

I am currently working on a project, which requires the mobile robot to move continuously. I would like to calculate how much linear distance the robot has travelled using the Servo Encoders. However since G15 Cube Servo has absolute encoder, When the wheel rotates continuously the encoder count will change from 0 --> 1087 -->Return to 0--->1087.... & the cycle repeats continuously. How can I calculate the linear distance travelled by robot using the absolute encoder????

Further in G15 Cube Servo we can read the present Load on motor. Can I know what is the unit of the returned value?
Shanunp
Greenhorn
 
Posts: 2
Joined: Sat Mar 07, 2020 4:41 pm


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 5 guests

cron