Serial connection with another device

Hello to everyone

I have a problem or mistake in the code and i dont know where is it.

I’m not good with english and programing so i will try to explane the best i can.

In the company where i work we have one device “black box” that box have serial connection, and i’m trying to read information and depending on what i’m read i’m making ethernet client connection to website.

Arduino 0023:

#include <SPI.h>
#include <Ethernet.h>
#include <Client.h>



// MAC address 
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 };
byte ip[] = { 192, 168 ,0 , 200 }; // IP of arduino
byte gateway[] = { 192, 168, 0, 1 };  // IP of the gateway
byte subnet[] = { 255, 255, 255, 0 }; // Subnet
byte server[] = { 192, 168, 0, 101 }; // Web server 

Client client(server, 81);


void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
}

void loop() 
{ 
  char inSerial[6];   
  int i=0; 
  delay(1000);
  
  if (Serial.available() > 0) 
  {             
       while (Serial.available() > 0) {
         inSerial[i]=Serial.read(); //read data  
         i++;      
       }
       inSerial[i]='\0';
      Check_Protocol(inSerial);
    }    
};


void Check_Protocol(char inStr[])
{   
  if(!strcmp(inStr,"*W  0"))  {
                           client.connect(); 
                           client.println("POST /r/ar1/0.php");
                           client.println();
                           client.stop();} 

  
  if(!strcmp(inStr,"*W  1"))  {
                           client.connect(); 
                           client.println("POST /r/ar1/1.php");
                           client.println();
                           client.stop();} 

  if(!strcmp(inStr,"*W 15"))  {
                           client.connect(); 
                           client.println("POST /r/ar1/1.php");
                           client.println();
                           client.stop();} 

                    }

Depending on the blackbox sensors the blackbox will give information like: “*W 0” ; “*W 1” … “*W 10” … and always is 5 character…

I test this code home and when in the serial monitor I type *W 20 and hit enter everything is working, but when i’m connection blackbox with arduino is not working.

connectin: blackbox —> serial ttl TX → arduino RX.
there is no usb connection with PC and Arduino

If i connect blackbox to PC with serial port and try to read with hyperterminal or putty a see normal information like: “*W 0” ; “*W 1”… and so on.

i try with softwere serial and arduino connected with usb to pc to see what is happening and i cant see let say “*W 0” i see only numbers. i check that numbers with ascii table and its not 42 87 32 32 48 for *W 0 its something else like 8A for Š or E2 for â

So what could be the problem here ?

The GND of the blackbox needs to be connected to the GND of the Arduino.

blackbox TO serial cable TO serial ttl - GND 5V and TX are conected to GND 5V and RX on arduino.

Could it be a baud rate issue, or parity settings on the black box?

Bits per second – 9600 Data Bits – 8 Parity – None Stop Bits – 1 Flow Control – None

this is in the user manual book also im using this config in hyperterminal or putty when im connecting to the box with the computer

i try with softwere serial and arduino connected with usb to pc to see what is happening and i cant see let say "*W 0" i see only numbers. i check that numbers with ascii table and its not 42 87 32 32 48 for *W 0 its something else like 8A for Š or E2 for â

Post the code you used to do this.

I dont remember the code i was to nervouz i did not save :/ but i remember rx was pin10

this is in the user manual book also im using this config in hyperterminal or putty when im connecting to the box with the computer

Remember connecting directly to a pc usually involves rs232 protocol, where as directly connecting to an arduino involves TTL protocol.

Yes, i learn that.. im using MAX3232 ttl for connecting blackbox with arduino

because i have very limited access to the blackbox next time(after 2 weeks) when it is possible i will try this code

void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);}
void loop() {
    // from external device to serial console
    if (Serial1.available() > 0) {
        byte incomingByte = Serial1.read();
        Serial.write(incomingByte);
    }
    // from serial console to external device
    if (Serial.available() > 0) {
        byte incomingByte = Serial.read();
        Serial1.write(incomingByte);
   }
}

blackbox to serial1 (mega pin19) with ttl and i will try to see what will show up on serial monitor

If the black box is sending continuously, I'd suggest that you increase the baud rate on serial (not serial1 obviously) so that you avoid the chance of buffer overrun. Come to think of it, I'd do it anyway.

Approximately in 20-30 sec it will show three times data which is maximum 5 characters.

Is it possible the problem to be the serial cabel ? But the same serial cabel have no problem between blackbox and PC