RS-UV3 Arduino Communication Examples

 

Initialization

The Arduino Uno only has one hardware serial port and it’s hard-wired to the USB port. To communicate with the RS-UV3 use a software serial port:

In the declarations area include the Software Serial Library:

#include <SoftwareSerial.h>
SoftwareSerial UV3(9, 8); // RX, TX

 

9 is the TX pin, 8 is the RX pin and the name of the port is ‘UV3’

In Setup() initialize the serial port:

    UV3.begin(19200);
    delay(100);
    UV3.write('\r');
    delay(100);

Start up the port wait 100 msec, send a <CR> to clear the buffer and wait again.

Sending Data to the RS-UV3

Here a local variable, VOL, that stores the volume setting is sent to the UV3. It must be padded with a 0 if it's less than 10:

      UV3.print("VU");
      if (VOL < 10){
        UV3.write('0');
        UV3.write(VOL + 48);
      }
      else{
        CVOL = VOL/10;
        UV3.write(CVOL + 48);
        CVOL = VOL - 10 * CVOL;
        UV3.write(CVOL + 48);
      }
      UV3.write('\r');

Receiving Data from the RS-UV3

Here is the function to call after sending something to the UV3 that elicits a response:

byte get_UV3buff(){
  byte k = 0;
  long T = millis() + 100;
  char c = 0;
 
  while ((millis() < T) && (c != '\r')){
    if(UV3.available()){
      c = UV3.read();
      UV3buff[k++] = c;
      if (c == '\r') UV3buff[--k] = 0;
    }
  }
  if (c == 13){
    return 1;
  }
  return 0;
}

It waits for up to 100 msec to receive a string back from the UV3 and it returns a 1 if it receives a complete string and a 0 if it times out. If the string is successfully received, it is stored in UV3buff.