DORJ-FSCK Driver

I've been developing some Arduino driver code for the DORJ-FSCK radio modules available at my local electronics store. Data Sheet:

But I've hit a snag. There's some kind of issue converting data types. But I can't quite see whats going on. If somebody doesn't mind tagging in, it would be appreciated. My head hurts. :frowning:

What I have thus far:


// Arduino driver for DORJ-FSK Transmitter/Reciever modules.

// Set labels for each Pin.
int SetA = 40;
int TXD = 18;
int RXD = 19;
int AUX = 42;
int SetB = 41;

void setup()
{
pinMode(SetA, OUTPUT);      // Make SETA Pin Output.
pinMode(SetB, OUTPUT);      // Make SetB Pin Output.
pinMode(AUX, INPUT_PULLUP); // Make AUX Pin Input.
Serial.begin(9600);         // Instantiate communication over USB.
Serial1.begin(9600);        // Instantiate communication over RX/TX pins.
}

void read_settings()        // Read and display module settings
{
byte dorj_status_cmd[7] = {0xff,0x56,0xAE,0x35,0xA9,0x55,0xF0}; // Command used to read from module.
digitalWrite(SetA, HIGH);                                       // Ask module to enter setup/sleep mode.
if (digitalRead(AUX)==HIGH) {Serial1.write(dorj_status_cmd,7);} // Monitor AUX Pin, then send status request when ready.
byte dorj_response[10];                                         // Array for module response.
Serial1.readBytes(dorj_response,10);                            // Aquire response from module.
digitalWrite(SetA, LOW);                                        // Return module to normal opperation.

if (dorj_response[0] == 0x24 && dorj_response[1] == 0x24 && dorj_response[2] == 0x24) // Check for valid preamble.
  {
    Serial.println("Response Valid");
    int frequency = dorj_response[3] + dorj_response[4] + dorj_response[5];
    Serial.println("Frequency:  ", frequency);

    Serial.println("Frequency:  ", dorj_response[3] + dorj_response[4] + dorj_response[5]);
    Serial.println("FSK Data Rate:  ", dorj_response[6]);
    Serial.println("Power Output: ", dorj_response[7]);
    Serial.println("UART Data Rate: ", dorj_response[8]);
    Serial.println("Parity: ", dorj_response[9]);
  }
else 
  {
    Serial.println("Response Invalid");
  }
}

void loop()
{
read_settings();
delay(5000);
}

It would help if you showed your debug data. We don't know what you are seeing, we don't know the inputs, and we don't know what you want for output.

Can we assume it compiles with NO errors?

Actually lot's of errors, did you post ALL the code? Is it the compile errors you need help with, your question sounds like it needs help with execution (cast)

I just realized that there are more problems than I originally realized. Rotten headache at the moment. :face_exhaling:

This might be the thing to fix first:
no matching function for call to 'println(const char [13], int&)'

Is there a library I'm supposed to include to get println?

I think Serial.println is doing most of the complaining. Serial1.readBytes is apparently fine getting a fixed number of bytes from the module. But Serial.println apparently doesn't like working with the byte array.

Is there some data type conversion I need to do before the Serial.println function will play nicely?

Perhaps you should start by reading the Arduino Reference Page for the Print Class. What you're trying to do is not supported.

Certain boards in the Arduino ecosystem add printf() to the Print class. That might help. But, unfortunately you haven't told us what board you're using.

Which Arduino are you using?

I opted for the Mega 2560 on account of needing more than one UART.
Figured I'd get a foothold by communicating with the module, and then printing it's parameters back to the serial monitor.

println only takes one argument

Spend some time reading the reference
https://docs.arduino.cc/language-reference/

So extract the information I need from the byte array. Format as a string then send to println?

That is one way.

Then .printf() is not available to you in the Print class. You can sprintf() to a char array or form a concatenation by using multiple .print() statements.

Of course it was going to be something stupid.

    Serial.println("Response Valid");
    int frequency = dorj_response[3] + dorj_response[4] + dorj_response[5];
    Serial.println("Frequency:  ", frequency);

    Serial.println("Frequency:  ", dorj_response[3] + dorj_response[4] + dorj_response[5]);
    Serial.println("FSK Data Rate:  ", dorj_response[6]);
    Serial.println("Power Output: ", dorj_response[7]);
    Serial.println("UART Data Rate: ", dorj_response[8]);
    Serial.println("Parity: ", dorj_response[9]);

You look to have almost all the data incorrect.

The frequency is a 24-bit binary number, sent as three bytes, most significant byte first. The three bytes cannot simply be summed.
The other data is not directly sent, but is instead a number representing the data value - such as FSK data rate being a number from 0x00 through 0x05, representing 1, 2, 5, 10, 20, or 40 Kbps.

Be careful with the frequency, int on a Mega is only two bytes, having a maximum value of 32767.

Not quite correct, a 2nd argument can be used when printing float values, to specify the number of decimal places, in case @arduino_super_man happens to have seen it actually used somewhere.

Yeah, I realized most of that myself once I re-read the data sheet. Figured I'd try to deal with the first headache first.

What I'm wanting to gradually work towards. Is having a set of functions to setup the module, display it's parameters, report signal strength etc.

I don't suppose anybody knows the most elegant way to handle the multiple bytes used for frequency? I'm fairly sure Arduino doesn't have heep allocation.
Can I define a long int and add the array elements to that?

It does but what does that have to do with anything?

Spend some time reading the reference
https://docs.arduino.cc/language-reference/

AGAIN, look at the reference for the Print() class that I posted. Check out its .write() method.

It does. C++ new() works as expected. So does old-school malloc(). But, neither are needed in this case. A fixed-size array will do the job.

How is that going to help? frequency is a 3-byte binary number, most significant byte first. The Mega has a 24-bit unsigned integer data type, but that is least-significant-byte first, and neither print() nor write() will handle the 24-bit data types. There is nothing in the print() or write() class that will combine three individual bytes into a 24-bit integer.

That is correct.