RN52 volume

Hi,

I'm working with RN52 (sparfun) and I can increase the volume with the actions command AV+ (or decrease with AV-). What I want to implement too is to set a volume in a certain level with potentiometer. The potentiometer works fine but when I set the volume, nothing happen. I use the HV action command (example HV,8\r).

How can I do this (ajust the volume with potentiometer) with RN52?

Thanks in advance for your help.

A link to the RN52 datasheet will help people to help you.

...R

Robin2:
A link to the RN52 datasheet will help people to help you.

...R

You can find below the link to the datasheet

What about a link to the Sparkfun implementation (breakout board?) that you appear to be using?

...R

Robin2:
What about a link to the Sparkfun implementation (breakout board?) that you appear to be using?

...R

Hi, below are the links
https://learn.sparkfun.com/tutorials/rn-52-bluetooth-hookup-guide

Thanks.

I'm still not clear what the RN-52 module is for, or whether I can help.

I had expected to see an example Arduino program on the Sparkfun website. Can you post the Arduino program that you are using?

...R

Here is the code

#include <SoftwareSerial.h>

const int pinVol=2; //Potentiometer
int val=0;
String valVol;


 SoftwareSerial mySerial(3, 2); // RX, TX

void setup() {
  Serial.begin(115200); //start talking to RN52
  mySerial.begin(115200);
  pinMode(pinVol,INPUT); //set buttons to input
  pinMode(9,OUTPUT); digitalWrite(9,LOW);
  //mySerial.print("D");

 
}

void volume()
{
//The action command is HV,<decimal>. All commands must end with \r
  valVol="HV,";
   val = analogRead(pinVol);
   val = map(val, 0, 1023, 0, 15);
   valVol.concat(val);
  mySerial.print(valVol.concat("\r"));
   Serial.println(value);
   Serial.println(valVol);
  
}

void loop() {  
    volume();
}

mySerial.print("AV+\r") works fine ( mySerial.print("AV-\r") also).

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Try this

void volume()
{
//The action command is HV,<decimal>. All commands must end with \r
   val = analogRead(pinVol);
   val = map(val, 0, 1023, 0, 15);
   mySerial.print("HV,");
   mySerial.print(val);
   mySerial.print('\r');

   Serial.print("value ");
   Serial.println(val);
  
}

Also, add a suitable delay to your loop() because at the moment it is trying to send instructions hundreds of times per second. Try delay(300); to start with.

You also only need to send data if the potentiometer is moved.

...R

Hi,

I just try it but the issue persists.
In the last link, I notice that the command HV isn't present. Maybe it doesn't exists anymore.

Can I use AV+/AV- commands to achieve volume control with potentiometer?

Thanks.

I see what you mean. The last linked document is newer.

Maybe you need the SS command. But I think it requires a value sent as hex text (very strange) so try this

void volume()
{
   val = analogRead(pinVol);
   val = map(val, 0, 1023, 0, 15);
   char hexVal;
   if (val < 10) {
      hexVal = val + '0';
   }
   else {
      hexVal = val + '7'; // the code for 7 is 55 + 10 gives 65 which is the code for A
   }
   mySerial.print("SS,0"); // first hex digit is always 0 in this case
   mySerial.print(hexVal);

   Serial.print("value ");
   Serial.print(val);
   Serial.print( "  hexVal ");
   Serial.print(hexVal);
  
}

...R