Clear all

Transmitting some joystick and switch values with 433mhz transmitter

3 Posts
3 Users
Active Member
Joined: 1 year ago
Posts: 3
Topic starter  



// Joy stick 1 pins
int Joy_stick_switch_L = 3;
int Joy_stick_X_L = A2;
int Joy_stick_Y_L = A3;

// Joy stck 2 pins
int Joy_stick_switch_R = 2;
int Joy_stick_X_R = A1;
int Joy_stick_Y_R = A0;

// Switch pins
int Switch_top_left = 7;
int Switch_top_right = 5;
int Switch_bottom_left = 6;
int Switch_bottom_right = 4;

RH_ASK rf_driver;

void setup() {

void loop() {
  // Reading Joy stick 1
  float S_L = digitalRead(Joy_stick_switch_L);
  float X_L = analogRead(Joy_stick_X_L);
  float Y_L = analogRead(Joy_stick_Y_L);
  // Reading Joy stick 2
  float S_R = digitalRead(Joy_stick_switch_R);
  float X_R = analogRead(Joy_stick_X_R);
  float Y_R = analogRead(Joy_stick_Y_R);

  // Reading the 4 switches 
  float T_L = digitalRead(Switch_top_left);
  float T_R = digitalRead(Switch_top_right);
  float B_L = digitalRead(Switch_bottom_left);
  float B_R = digitalRead(Switch_bottom_right);

  String str_S_L = String(S_L);
  String str_X_L = String(X_L);
  String str_Y_L = String(Y_L);

  String str_S_R = String(S_R);
  String str_X_R = String(X_R);
  String str_Y_R = String(Y_R);

  String str_T_L = String(T_L);
  String str_T_R = String(T_R);
  String str_B_L = String(B_L);
  String str_B_R = String(B_R);

  String str_out = str_S_L + ',' + str_X_L + ',' + str_Y_L + ',' + str_S_R + ',' + str_X_R + ',' + str_Y_R + ',' + str_T_L + ',' + str_T_R + ',' + str_B_L + ',' + str_B_R;

  static char *msg = str_out.c_str();
  rf_driver.send((uint8_t *)msg, strlen(msg));

Hi, I am Jack this is my first project using Arduino and c++ so I am defiantly gonna make some stupid mistakes. So I am using an Arduino Uno with a H34S (written on the back of the PCB) as the transmitter, 2 Joysticks (each one has an integrated switch as well as x and y) and 4 switches. I plan to use this to wirelessly control a small robot but first baby steps. I just want to transmit the pot values from the joysticks and the switch values.

I followed the "Using Inexpensive 433MHz Transmit and Receive Modules with Arduino" video and read the article.

The problem i run into iswhen I go to compile the code I get

"invalid conversion from 'const char*' to 'char*' [-fpermissive]"

"static char *msg = str_out.c_str();"

Any help would be greatly apreciated

Famed Member
Joined: 2 years ago
Posts: 2235


The compiler is complaining that you're assigning the address of a 'constant' (unchangeable) value to a variable which might change it. You'll need to change your variable msg to be const as well.

Your code won't compile on my machine because of the missing include files, so I can't test your code or the fix.

Experience is what you get when you don't get what you want.

Famed Member
Joined: 2 years ago
Posts: 4017

@will Just looking at the code snippet above, the address of str_out.c_str() is being assigned to the char pointer msg. That is not unusual but the compiler warning suggests there is more to this than what the snippet shows. Paste the full data structure. I suspect the structure has const in it's declaration somewhere, you might also have to show us the type declaration if there is one. In the language being used is the definition of const mean it can not be altered? If so, how is it assigned a value and how is it meant to be used. Not all languages treat const the same. The next line of code also appears to be in error, do you want the strlen of the variable msg which is an address, or the strlen of the string that msg points to?

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting