Hardware Serial Port Communication

Thanks for sharing that - mighty decent of you! Lots of folks just take off and never report on solutions that they are trying or that worked for them for the learning of others on the forum.

For that, I salute you :saluting_face:

indeed - so no wonder it was not working

I will report if it works so everyone can use this information.

1 Like

The print overload for 'int' should try to split the number up and print ASCII digits. The overload for char should send the character read.

I can't test right now but I'm pretty sure that if you read '1' as an int and then print it you'll get "49" as the output.

print will get you the ASCII representation of whatever you had as a parameter based on the type indeed (a char will go through unchanged, an int will be translated into its ASCII decimal representation)

write() will take just the LSB of what you passed and send it out as a byte

You're right. I'm thinking about print.

Hi Folks
Success at last .
MAX232 was the answer, I was mixing TTL with RS232 protocol.

This is the Word "Hello" being sent from Serial Monitor to ComWatch and Vice-versa

Now I am going to connect this to a PTZ camera and send VISCA command Codes to see if I can Control the Camera

2 Likes

thanks for confirming! have fun.

(I don't see the GND being connected in your picture - it's needed)

There was no need , the MAX232 does not provide a GND.

However, I have still not managed to send VISCA commands to teh CAMERA . Although Everything looks fine , but it does not accept the Command .

you don't have a GND pin ??


o

I am you were right. I just took that as Negative Voltage. but in fact it is GND

I have another problem
I need to send HEX Codes to Camera for it to work.
I think I am doing this but I may be wrong as I am new to Arduino IDE programming.
This is my Code :

//Simple Serial Communication
void setup() {
  Serial.begin(9600, SERIAL_8N1 /* default */);
  while (!Serial)
    ;

  Serial1.begin(9600, SERIAL_8N1 /* default */);
  while (!Serial1)
    ;

  // byte Preset1[] = {0x81, 0x01, 0x04, 0x3F, 0x02, 0x01, 0xFF};
  // byte wgstart[] = {0x01, 0x13, 0x43, 0x57, 0x53, 0x02, 0x30, 0x30, 0x04};
  //Serial1.println("");
  //Serial1.flush();
  //delay(500);
  //Serial1.write(Preset1, sizeof(Preset1));
  //delay(500);
  //Serial.write(Preset1, sizeof(Preset1));
  Serial.flush();
}

void loop() {
  while (Serial.available() > 0) {
    char A = Serial.read();
    Serial.println(A);
    if (A == '1') {

      //Serial1.write(Serial.read());
      //Serial1.flush();
      Serial.println(A);
      Serial.write("Sending Preset 1");
      byte Preset1[] = { 0x81, 0x01, 0x04, 0x3F, 0x02, 0x01, 0xFF };
      //Serial1.write(Preset1, sizeof(Preset1));
      Serial1.write(0x81);
      Serial1.write(0x01);
      Serial1.write(0x04);
      Serial1.write(0x3F);
      Serial1.write(0x02);
      Serial1.write(0X01);
      Serial1.write(0xFF);
    }

    if (A == '2') {
      Serial.println(A);
      Serial.println("Sending Preset 2");
      byte Preset2[] = { 0x81, 0x01, 0x04, 0x3F, 0x02, 0x00, 0xFF };
      Serial1.write(Preset2, 7);
    }
  }
  while (Serial1.available()) Serial.write(Serial1.read());
}

Serial1 is sending the VISCA code to Camera
I checked with ComWatch and it is good. But Camera does not Accept it .

I tried 2 methods , sending codes Byte by Byte (Preset1) and sending it together (Preset 2)

But somehow I think these may not be HEX values.

Your code is correct, typically we would do

byte binaryCommand[] = { 0x81, 0x01, 0x04, 0x3F, 0x02, 0x00, 0xFF };
Serial.write(binaryCommand, sizeof binaryCommand);

to send out the 7 bytes of the command to Serial

writing them out individually would work too as basically both just fill in the Tx buffer and then the underlying hardware is picking each byte in turn and sending it out.

what's the bahavior you see ? what type of answer do you expect (binary info or ASCII text)?

can you share a link to your camera's technical documentation?

Does the camera need to be sent a number or a string representing a number, ie

0x81 or "81"

Does the message need to be terminated in some way ?

Is the camera expecting 10000001 which you send as 0x81?