Hi everybody!
I allow myself to open this topic because I have a small problem which made me lose tufts of hair .. here is my problem:
I'm on a personal project, I bought this camera 4.
To motorize it using dynamixel AX12A servomotors (to avoid shaking in the backlash of inexpensive servos and thus have a clean rendering).
For communication, I bought an RS485 to TTL module:
Here it is 2
I was able to recover and slightly modify a code which works very well, and so I managed my first version using a UNO R3 card and a "smart servo shield" from DFrobot.
my block with the arduino card and its shield being much too big by my eyes, I would therefore like to use a Nano V3.0 card.
I changed library to be able to order my servos without shield.
So I did again my connections with the nano, added a small 12-> 5V transformer for its power supply and turned everything on. Everything is at its nominal voltage, but it does not work.
I do have the TXD led of the module and TX of the card which flash at the same rate as the orders that I send from my return camera (on another PC), so I receive something.
But when I print my frame on the serial monitor, I realize that I only get empty frames
(0000000)
what bothers me is that it works great with the UNO R3 with or without shield ...
and I did not find any similar topics other than those which helped me to make my V1.
maybe a pilot problem?
Do you have any advice for me?
Thanks in advance for your time.
* module rs485 :
* -TXD (out module) sur RX carte
* _relier gnd cam au gnd IN module
*
*
*
*/
/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <ServoCds55.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define ID_Pan 1
#define ID_Tilt 2
#define RS485lTxControl 4 //RS485 Direction control
#define RS485Transmit HIGH // not needed here, the servos attached to the arduino will not transmit any data to the Pelco-D controller
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
ServoCds55 myservo;
/*-----( Declare Variables )-----*/
byte byteReceived[7];
int byteNumber = 0;
int byteSend;
int minPulse1 = 100; // minimum servo position
int maxPulse1 = 212; // maximum servo position
int turnRate1 = 1; // servo turn rate increment (larger value, faster rate)
int minPulse2 = 138; // minimum servo position
int maxPulse2 = 178; // maximum servo position
int turnRate2 = 1; // servo turn rate increment (larger value, faster rate)
/** The Arduino will calculate these values for you **/
int centerservoPAN;
int centerservoTILT;
int pulseWidth1; // servo pulse width
int pulseWidth2; // servo pulse width
void setup() {
Serial.begin (9600);
myservo.begin ();
myservo.setVelocity(50);
centerservoPAN = maxPulse1 - ((maxPulse1 - minPulse1)/2);
centerservoTILT = maxPulse2 - ((maxPulse2 - minPulse2)/2);
pulseWidth1 = centerservoPAN;
pulseWidth2 = centerservoTILT;
Serial.println("Arduino Serial Servo Control with Pelco D");
Serial.println();
pinMode(Pin13LED, OUTPUT);
pinMode(RS485lTxControl, OUTPUT);
digitalWrite(RS485lTxControl, RS485Receive); // Init Transceiver
delay(10000);
Serial.println("initialisation des moteurs");
myservo.WritePos(ID_Pan,pulseWidth1);
myservo.WritePos(ID_Tilt,pulseWidth2);
Serial.println("ready");
}//--(end setup )---
void loop() {
// if (!Serial.available())Serial.println("pas de co");
if (Serial.available() > 0) //Look for incoming serial data from Pelco-D controller
{
byteReceived[byteNumber ++] = Serial.read(); // Read received byte
//Serial.println(byteReceived[byteNumber], DEC); // Show on Serial Monitor
delay(10);
if ( byteReceived[0] != 0xFF ) {byteNumber = 0;} // When Byte 0 isn't 0xFF (Pelco 1st Byte) reset byteNumber to 0 preventing the serial port being blocked.
}
if ( byteNumber > 6 ) // process it
{
byteNumber = 0; // ready for next time
byte data = byteReceived[3]; // read the incoming byte:
Serial.println(data, HEX); // Show on Serial Monitor
switch(data)
{
case 0x00 : break;
case 0x02 : pulseWidth1 = pulseWidth1 - turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); break; // right
case 0x04 : pulseWidth1 = pulseWidth1 + turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); break; // left
case 0x10 : pulseWidth2 = pulseWidth2 - turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // down
case 0x08 : pulseWidth2 = pulseWidth2 + turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // up
case 0x14 : pulseWidth1 = pulseWidth1 + turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); pulseWidth2 = pulseWidth2 - turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // left-up
case 0x12 : pulseWidth1 = pulseWidth1 - turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); pulseWidth2 = pulseWidth2 - turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // right-up
case 0x0C : pulseWidth1 = pulseWidth1 + turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); pulseWidth2 = pulseWidth2 + turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // left-down
case 0x0A : pulseWidth1 = pulseWidth1 - turnRate1; myservo.WritePos(ID_Pan,pulseWidth1); pulseWidth2 = pulseWidth2 + turnRate1; myservo.WritePos(ID_Tilt,pulseWidth2); break; // right-down
}
// stop servo pulse at min and max
if (pulseWidth1 > maxPulse1) { pulseWidth1 = maxPulse1; }
if (pulseWidth1 < minPulse1) { pulseWidth1 = minPulse1; }
// stop servo pulse at min and max
if (pulseWidth2 > maxPulse2) { pulseWidth2 = maxPulse2; }
if (pulseWidth2 < minPulse2) { pulseWidth2 = minPulse2; }
// print pulseWidth back to the Serial Monitor (uncomment to debug)
Serial.println("Servo 1: ");
Serial.println(pulseWidth1);
Serial.println(" Servo 2: ");
Serial.println(pulseWidth2);
Serial.println("degrees");
}
}````