Notifications
Clear all

Transmitting some joystick and switch values with 433mhz transmitter

3 Posts
3 Users
0 Likes
968 Views
10jack2
(@10jack2)
Member
Joined: 2 years ago
Posts: 3
Topic starter  
#include 

#include 

#include 

// 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() {
  rf_driver.init();
}

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));
  rf_driver.waitPacketSent();
}

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


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@10jack2

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.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6932
 

@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?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote