Auto pressing inputs or wrong characters

When i move arround Gamepad (mpu6050) It press inputs like that WWSAA F or if i press any button It does like WDD*SA #

I got some narrowing int to Char 177 and some numbers more...

Whats wrong??

Fixed!! Was a fault on the transmision buffer
Thanks to everybody!!!

PD: can somebody give me a code for try the Gyroscope mouse just on case?

Are you saying that it presses keys when you don't want it to, or it's pressing keys instead of pretending to be a mouse? Where did you get that code?

Sneaky trick: If you want to post code, just click the [</>] button and paste your code between the [\code][\code] markers.

 Then your code will show up in this tidy little box!

Thanks you for the trick!

hahag

Sorry for my lenguaje,
I paid a Guy for Code and for the Arduino Gamepad,
it have a gyro mouse with some keyboard physical keys.

But now when i move the gyro i Mean moving the Gamepad It keep pressing buttons for It self like wwwaass de rrr

And things like that when im not pressing nothing only moving the mpu6050 and if i press one physical button like the W It Will do like WSF# E, so something its wrong with the input intefering on the mpu ir what?

This code doesn't compile on an Arduino mega:

#include <Mouse.h>
#include <Keyboard.h>

On (probably) all of the Arduinos which will run that code, SoftwareSerial is not required.

What do you really have?

MorganS:
This code doesn't compile on an Arduino mega:

#include <Mouse.h>

#include <Keyboard.h>




On (probably) all of the Arduinos which will run that code, SoftwareSerial is not required.

What do you really have?

Thats on the receptor let me explain you:

I have mega r3 2560 ch340 as transmisor connected to some physical buttons acting as a keyboard, 2 joystick, mpu6050 for gyro mouse and one hc05 bt

In the another side i have a cjmcu beetle atmega32u4 as receptor with another hc05 bt

Before i reload the same Code on diferent pc It was working perfect butnafter the code the problem started and i dont know if the Guy that created it (Gamepad and Code) touched something in the code coz he think its the same but i feel that not :blush:
Really thanks in advance!!!!!

Before i uploaded the Code the cjmcu beetle receptor was recogniced on my phone with and OTG cable as Sparkfun USB and now after the upload Its called Arduino LLC arduino micro,

Dont know if is coz i installed diferent drivers on my pc for the mega r3 or cjmcu coz i dont flashed nothing or touched anything strange...

The Guy told me maybe if something wrong with the bluetooth hc05 conection, check this line:

SoftwareSerial HC05_Serial(9, 10); // RX, TX

Maybe i have to do again the process máster and slave just for select 9 and 10 Rx TX? Or not coz i already got conexion on both?

I hope you didn't pay a lot of money for that code. It reads like a lot of code we see here from inexperienced Arduino coders. But it should basically work.

What do you have connected to analog inputs A10 and A11 on the transmitter? That seems like the most likely source of inadvertent pressing of WASD keys. If there is nothing connected then you will get random outputs.

UPDATE!!!

Ok!!! A10 and A11 are the joystick for WASD F exactly the buttons that pressed for itself!!
If i disconnect A10 and A11 the problem act at a higher speed and looks like It press more buttons like 4AS ER!AW

Looks like when i disconnect some buttons from the mega It press some buttons more automaticly no??

Before uploading the code, i cutted pin 6 and 7 (espace button) because I didn't need it but was still working perfect until I put the code again ...

One thing more I glued it with silicone to the Gamepad, but was working...

And no one button is working properly if i press key 1 for example It does like WWAS# and things like that..

Can u make me please a simple Code bases on mine just for try if any key input works? I tried to leave gyro words and mouse and no one button works :confused:

If you mean control the WASD keys by the gyroscope, then I just finished writing some code that should work:

/* Tilt Control - King Dub Dub, 11/29/19

A tilt-controller script for USB-HID enabled Arduino boards with the MPU-6050 sensor.
Tilt to control the WASD controls and spacebar (JK I lied about the W, it presses [space]).
There is an additional fail-safe that keeps any keyboard data from being printed if pin 9
isn't grounded. Ground pin 9 with a switch/button when you want to send keyboard inputs.

MPU6050 - Arduino
VCC to 5V
GND to GND
SCL to A5 or SCL
SDA to A4 or SDA
ADO to GND
INT to digital pin 2
Pin 9 to button/switch to ground

*/

#include<Wire.h>
#include<Keyboard.h>

const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; //sets up the accelerometer XYZ's, temperature, and gyro XYZ's
int minVal=265;
int maxVal=402;
double x,y,z;
int MPUFail = 0;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);

  pinMode(9, INPUT_PULLUP); //pin 9 is a fail-safe switch
  Keyboard.begin();
}

void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B); Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);
  AcX=Wire.read()<<8|Wire.read();
  AcY=Wire.read()<<8|Wire.read();
  AcZ=Wire.read()<<8|Wire.read();

  int xAng = map(AcX,minVal,maxVal,-90,90);
  int yAng = map(AcY,minVal,maxVal,-90,90);
  int zAng = map(AcZ,minVal,maxVal,-90,90);

  x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
  y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
  z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
  
  if ((AcX == -1) and (AcY == -1) and (AcZ == -1)){
    MPUFail = 1; //if the Arduino can't connect to the MPU, all raw values come out as -1,
  } else {       // so this is another fail-safe that stops it from pressing keys.            
    MPUFail = 0;
  }

  Serial.print("X= "); Serial.print("N/A"); //the X value doesn't work on our axis
  Serial.print(" Y= "); Serial.print(y);    //print the Y value
  Serial.print(" Z= "); Serial.print(z);    //print the Z value
  Serial.print("  Safety: ");
  if(digitalRead(9) == 0){ //prints if safety button is on
    Serial.print("Off");
  } else {
    Serial.print("On");
  }
  Serial.print("\n");                       //prints a new line

  if ((y >=130) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted left:
    Keyboard.press('a'); //"press" the [a] key
  } else {
    Keyboard.release('a'); //else, stop "pressing"  the [a] key
  }
  if ((z <=335) and (z >= 180) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted down:
    Keyboard.press('s');
    delay(10);
  } else {
    Keyboard.release('s');
  }
  if ((y<=60) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted right:
    Keyboard.press('d');
    delay(10);
  } else {
    Keyboard.release('d');
  }
  if ((z >= 35) and (z<=179) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted up:
    Keyboard.press('w'); //sends [spacebar] key
    delay(10);
  } else {
    Keyboard.release('w');
  }
  delay(10);//keeps a regulated speed
}

Run that on your 32u4 board, make sure you have a wire going from pin 9 to ground, it keeps the code from pressing keys constantly when you don't want it to! The code is made for an upright MPU on its side, with the pin holes horizontal with the floor. Like in this picture:

Have you tried this without using the bluetooth? That could be causing the problem. You should only see one letter get pressed, not WWAS#. Sounds like something is messing up your transmitter or receiver.

@TonyMaz and @Alazor, are you the same person? Please just use one account, it's breaking my brain!

@Alazor

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Please READ THIS POST to help you get the best out of the forum.

Bob.

@kingdubdub sorry im the same person yes, on the account of my brother haha

Thanks you very much but i need to move just the mouse cursor with my gyro, but the gyro its pressing that button when i move It :confused:

I have in the 32u4 to hc05:

32u4 - hc05

Gnd. Gnd
5v. VCC
D9. TXD

Its that ok? coz i havent got a cable from pin 9 to gnd :confused:
And i didnt triyed without bt coz i dont know what code to put in just for try... im new, can u tell me someone to try please¿
they both pair perfect but maybe i should do the repair process to slave and master after uoload code again???

Pics of the Sheme just in case:

BIG UPDATE!!!!!

I got a warning on the receptor cjmcu while uploading the sketch!
can be for that???

Waning:

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '177' from 'int' to 'char' inside { } [-Wnarrowing]

 char buttons[20] = {'D', 'A', 'S', 'W', MOUSE_RIGHT , MOUSE_LEFT, KEY_ESC, KEY_TAB, ' ', 'F', 'E', 'R', '4', '3', '2', '1', KEY_F4, KEY_F3, KEY_F2, KEY_F1};

                                                                                                                                                           ^

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '179' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '197' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '196' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '195' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\TonyMaz\Downloads\ARRDUUU\arduino\Receptor\Receptor.ino:11:155: warning: narrowing conversion of '194' from 'int' to 'char' inside { } [-Wnarrowing]

I read about usbapi.h
you can change something to read other kind os ascii or something like that
And now looking this lines:

 if (recTXT.indexOf("*") == 0)
 {
   vx = recTXT.substring(recTXT.indexOf("*") + 1, recTXT.indexOf("#") + 1).toInt();
   vy = recTXT.substring(recTXT.indexOf("%") + 1, recTXT.indexOf("@") + 1).toInt();
   puldadores_DWORD = recTXT.substring(recTXT.indexOf("$") + 1, recTXT.indexOf("&") + 1).toInt();

looks like i have to insert something in usbapi.h to read that ascii or just the pulgadores_DWORD its interfering there coz it is the WASD F just the buttons it press when i move the mpu6050

Please give me any simple gyro mouse Code based on 2 parts with hc05 pleaseeee i cannot sleep triying :frowning:

Here's some code that works with the same setup I explained earlier, only it controls the mouse:

/* Tilt Control (Mouse Version) - King Dub Dub, 12/1/19

A tilt-controller script for USB-HID enabled Arduino boards with the MPU-6050 sensor.
Tilt to control an emulated mouse input, up for up, right for right, and so on.
There is an additional fail-safe that keeps any mouse data from being printed if pin 9
isn't grounded. Ground pin 9 with a switch/button when you want to send keyboard inputs.

MPU6050 - Arduino
VCC to 5V
GND to GND
SCL to A5 or SCL
SDA to A4 or SDA
ADO to GND
INT to digital pin 2
Pin 9 to button/switch to ground

*/

#include<Wire.h>
#include<Mouse.h>

const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; //sets up the accelerometer XYZ's, temperature, and gyro XYZ's
int minVal=265; //math-error
int maxVal=402; //checking
double x,y,z;
int MPUFail = 0;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);

  pinMode(9, INPUT_PULLUP); //pin 9 is a fail-safe switch
  Mouse.begin();
}

void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B); Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);
  AcX=Wire.read()<<8|Wire.read();
  AcY=Wire.read()<<8|Wire.read();
  AcZ=Wire.read()<<8|Wire.read();

  int xAng = map(AcX,minVal,maxVal,-90,90);
  int yAng = map(AcY,minVal,maxVal,-90,90);
  int zAng = map(AcZ,minVal,maxVal,-90,90);

  x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
  y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
  z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
  
  if ((AcX == -1) and (AcY == -1) and (AcZ == -1)){
    MPUFail = 1; //if the Arduino can't connect to the MPU, all raw values come out as -1,
  } else {       // so this is another fail-safe that stops it from pressing keys.            
    MPUFail = 0;
  }

  Serial.print("X= "); Serial.print("N/A"); //the X value doesn't work on our axis
  Serial.print(" Y= "); Serial.print(y);    //print the Y value
  Serial.print(" Z= "); Serial.print(z);    //print the Z value
  Serial.print("  Safety: ");
  if(digitalRead(9) == 0){ //prints if safety button is on:
    Serial.print("Off");
  } else {
    Serial.print("On");
  }
  Serial.print("\n"); //prints a new line

  if ((y >=130) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted left:
    Mouse.move(-10, 0, 0); //move mouse left 10 units
    delay(10);
  }
  if ((z <=340) and (z >= 180) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted down:
    Mouse.move(0, -10, 0); //move mouse down 10 units
    delay(10);
  }
  if ((y<=60) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted right:
    Mouse.move(10, 0, 0); //move mouse right 10 units
    delay(10);
  }
  if ((z >= 35) and (z<=179) and (digitalRead(9) == 0) and (MPUFail == 0)){ //if tilted up:
    Mouse.move(0, 10, 0); //move mouse up 10 units
    delay(10);
  }
  delay(10);//keeps a regulated speed
}

So make sure the MPU is upright on it's side and pin 9 is grounded, this is just a modified version of the earlier sketch. Note that the mouse speed is constant, you can add your own math to fine-tune the sensitivity and maybe change the speed depending on how far it's tilted. Just download this to your 32u4 board. Worry about bluetooth after you have something simple that works (even then, bluetooth is tricky and means you need a portable power source for your controller, which is why I don't like using bluetooth that much).

Alazor:
I have in the 32u4 to hc05:

32u4 - hc05

Gnd. Gnd
5v. VCC
D9. TXD

Its that ok? coz i havent got a cable from pin 9 to gnd :confused:
And i didnt triyed without bt coz i dont know what code to put in just for try... im new, can u tell me someone to try please¿
they both pair perfect but maybe i should do the repair process to slave and master after uoload code again???

You can just change the code so a different pin needs to be grounded; heck, you could even get rid of the safety pin entirely, but that would cause many problems! Just change it to pin 7 or something if you want to go with that.

@KingDubDub Thanks you really for the efforts but i have the mpu6050 on Arduino mega r3 and it dosnt accept mouse.h that why i asked for a code with 2x hc05 :confused:

Alazor:
Please give me any simple gyro mouse Code based on 2 parts with hc05 pleaseeee i cannot sleep triying :frowning:

That's all you need? You don't need the other 16 buttons? Then that's simple. In your receiver code, put "//" in front of both "Keyboard.press" and "Keyboard.release". That will stop it pressing keyboard keys.

Do the mouse buttons work like you expect?

@Morgans thanks!! I Will try tomorrow un the morning.
I dont tried the mouse buttons i Will tell you tomorrow sir, really THX!!!!

I read that i should disconnect the tx and Rx pin from the receptor hc05/atmega32u4 for upload new Code?
Coz i tried gyro data test directly without the atmegs32u4/hc05 and was perfect :confused:

No, the 32u4 chip has dedicated USB. You don't need to disconnect Rx and Tx to upload new code. In fact, since it has dedicated USB, you didn't need to use SoftwareSerial on that board. You could have connected the HC05 to the regular Rx and Tx pins.

Thanks @Morgans!! But let me explain you now its not pressing any button but the gyro mouse its like drifting jumping even if i press a button the mouse jumps to sides

Screenshot for console when i press a button: