Connecting arduino serial output with Calamp LMU

I have a Arduino 2630 sending a hex message to serial1. I can read the data stream in my terminal but when I try to send the hex message to a Calamp tracking device it wont read the message. I have set all the appropriate in the calamp device , I think, but now luck. anyone have experience with calamp devices?

Post a link to the "Calamp device" product page or user manual and the code, using code tags.

Note that serial data are always binary. "Hex" (like decimal or ASCII) is a human readable representation of binary data, so I suspect you misunderstand what is meant by a "hex message".

2 Likes

CODE:

#define NUM_INPUTS 15  // Number of inputs

const int inputPins[NUM_INPUTS] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36};

void setup() {
    Serial.begin(9600);   // Serial Monitor via USB
    Serial1.begin(9600);  // RS232 Output to AVL (via MAX3232)

    for (int i = 0; i < NUM_INPUTS; i++) {
        pinMode(inputPins[i], INPUT_PULLUP);
    }
}

void loop() {
    byte pinStates[NUM_INPUTS] = {0};  // Array to hold pin states
    String data = "INPUTS:";           // Start the message

    for (int i = 0; i < NUM_INPUTS; i++) {
        int sensorValue = digitalRead(inputPins[i]);
        pinStates[i] = !sensorValue;  // Invert the reading
        data += String(pinStates[i]); // Append state to string
        if (i < NUM_INPUTS - 1) data += ",";  // Add comma between values
    }

    Serial.println(data);  // Send to Serial Monitor (USB)

    // Convert pinStates to a hex-encoded string
    String hexString = "";
    for (int i = 0; i < NUM_INPUTS; i++) {
        if (pinStates[i] < 0x10) hexString += "0";  // Leading zero for single hex digits
        hexString += String(pinStates[i], HEX);
    }

    // Send hex-encoded string to AVL device via RS232
    Serial1.println(hexString);

    delay(2000);  // Adjust as needed

There is no useful information regarding serial I/O or the serial connection in the data sheet you linked, and I can't make much sense of the posted code.

What is the code supposed to do and what is the device supposed to do with the message?

Can you provide documentation relating to the message format you are using? I don't see that detail in the documentation you linked to.

The device reads the incoming message which is made up of the on/off state of several switches as a digital input. then sends the payload , with other device internal information via cell to a central server. The data is then mapped and posted on a web site to monitor the activity of the vehicles. the device is connected to. here is an example of the message that the device fails to read.
30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30 30 30 0D 0A 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30 30 30 0D 0A 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30 30 30 0D 0A 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30 30 30 0D 0A 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30 30 30 0D 0A 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 30 31 30 30 30 30 30 30 30 30

I am not surprised it does not get read. You are sending the two characters for each byte of required message text. Each "30" is the HEX equivalent of "0" Each "31" you send is the HEX equivalent of "1". And the "0D 0A" are carriage return and line feed.
Just send the actual ASCII character, and the carriage return/line feed, and I bet your message will be accepted.

Please post a link to the documentation describing this feature. I'm quite sure you misunderstand the serial data format.

You should probably not be using the HEX qualifier in the Serial.print() command, and it may be necessary to use Serial.write() to send binary, rather than ASCII data.

Thanks for the input
I have changed my code to this, just using the print function. checked the output in the serial monitor and my terminal program. both out put the same. My device is still not recognizing the message.

void loop() {
    String data = "INPUTS:";  // Start the message

    for (int i = 0; i < NUM_INPUTS; i++) {
        int sensorValue = digitalRead(inputPins[i]);
        char state = sensorValue ? '1' : '0';  // Convert to ASCII '1' or '0'
        data += state;
        if (i < NUM_INPUTS - 1) data += ',';  // Add comma between values
    }

    Serial.println(data);     // Send to Serial Monitor (USB)
    Serial1.println(data);    // Send ASCII-encoded string to AVL device via RS232

    delay(2000);  // Adjust as needed

}

INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1
INPUTS:1,1,1,1,1,0,1,1,0,0,1,1,1,1,1

Then whatever you are sending is not what it expects to see.

Good luck with your project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.