Funduino Joystick Shield with HC05

Hello! I'm a very newbie to Arduino. It hasn't even been a month since I started and I don't know a lot of things. That's why I'm asking for your help.

I have one Arduino Uno, one Arduino Leonardo, one Funduino Joystick Shield and 2 HC05 modules. I wanted to make a wireless joystick for myself using these materials. I set the HC05s as Master and Slave. I connected the Joystick Shield and Slave HC05 to Arduino Uno.

I put this code inside the Arduino Uno:

#define joy_x A0
#define joy_y A1
#define btn_a 2
#define btn_b 3
#define btn_c 4
#define btn_d 5
#define btn_e 6
#define btn_f 7
#define joy_btn 8

void setup()
{
  for (int i = 2; i >= 8; i++)
  {
    pinMode(i, INPUT);
  }
  Serial.begin(115200);
}

void loop()
{
  Serial.print('$');

  if (analogRead(joy_x) < 1000) Serial.print("0");

  if (analogRead(joy_x) <  100) Serial.print("0");

  if (analogRead(joy_x) <   10) Serial.print("0");

  Serial.print(analogRead(joy_x));

  Serial.print(',');

  if (analogRead(joy_y) < 1000) Serial.print("0");

  if (analogRead(joy_y) <  100) Serial.print("0");

  if (analogRead(joy_y) <   10) Serial.print("0");

  Serial.print(analogRead(joy_y));

  Serial.print(',');

  Serial.print(digitalRead(btn_a));

  Serial.print(',');

  Serial.print(digitalRead(btn_b));

  Serial.print(',');

  Serial.print(digitalRead(btn_c));

  Serial.print(',');

  Serial.print(digitalRead(btn_d));

  Serial.print(',');

  Serial.print(digitalRead(btn_e));

  Serial.print(',');

  Serial.print(digitalRead(btn_f));

  Serial.print(',');

  Serial.print(digitalRead(joy_btn));

  Serial.print('#');

  delay(50);

}

I plugged Master HC05 into Arduino Leonardo and connected it to the computer.

I put this code into Arduino Leonardo:

#include <Joystick.h>

int pos_x = 0;
int pos_y = 0;
int a_btn = 0;
int b_btn = 0;
int c_btn = 0;
int d_btn = 0;
int e_btn = 0;
int f_btn = 0;
int joy_btn = 0;

void setup()
{
  Serial.begin(115200); //USB-CDC
  Serial1.begin(115200); //TTL Serial
  Joystick.begin();
  while(!Serial1){}
}

void loop()
{
  readValues();
  Joystick.setXAxis(pos_x);
  Joystick.setYAxis(pos_y);
  Joystick.setButton(0, !a_btn);
  Joystick.setButton(1, !b_btn);
  Joystick.setButton(2, !c_btn);
  Joystick.setButton(3, !d_btn);
  Joystick.setButton(4, !e_btn);
  Joystick.setButton(5, !f_btn);
  Joystick.setButton(6, !joy_btn);
  
  Serial.print(pos_x);
  Serial.print(",");
  Serial.print(pos_y);
  Serial.print(",");
  Serial.print(a_btn);
  Serial.print(",");
  Serial.print(b_btn);
  Serial.print(",");
  Serial.print(c_btn);
  Serial.print(",");
  Serial.print(d_btn);
  Serial.print(",");
  Serial.print(e_btn);
  Serial.print(",");
  Serial.print(f_btn);
  Serial.print(",");
  Serial.println(joy_btn);
  
}

void readValues()
{
  String readout = Serial1.readStringUntil('#');
  String joy_x = readout.substring(1, 5);
  pos_x = joy_x.toInt();
  pos_x = map(pos_x, 0, 1023, -127, 127);
  String joy_y = readout.substring(6, 10);
  pos_y = joy_y.toInt();
  pos_y = map(pos_y, 0, 1023, 127, -127);
  String btn_a = readout.substring(11, 13);
  a_btn = btn_a.toInt();
  String btn_b = readout.substring(13, 15);
  b_btn = btn_b.toInt();
  String btn_c = readout.substring(15, 17);
  c_btn = btn_c.toInt();
  String btn_d = readout.substring(17, 19);
  d_btn = btn_d.toInt();
  String btn_e = readout.substring(19, 21);
  e_btn = btn_e.toInt();
  String btn_f = readout.substring(21, 23);
  f_btn = btn_f.toInt();
  String btn_joy = readout.substring(23, 25);
  joy_btn = btn_joy.toInt();
}

But no matter what I did, I could not transfer any information. When I connect the joystick to the computer via cable, it works and I receive data, so the problem is not there. I checked the HC05s one by one and they both respond to AT commands, so I don't think they are broken either. However, when I connect the HC05 to the Joystick Shield, the LED on it does not blink. I don't know if it needs to flash or not. Do you think the problem is in the codes or does the Joystick Shield not detect the Bluetooth connection? I will be so grateful if you could help me!

Please check if your HC-05 modules are properly getting paired with each other as master and slave. Unless proper pairing, it will not be possible to transfer data.

1 Like

I checked and for some reason they won't flashing simultaneously. I don't know why. Their password and bind adress is the same.

I solved the problem with HC05 module's. They're connect each other pretty well. But there's an another problem. HC05 doesn't work on Funduino. I don't know why but it's LED won't even blink. I think there's no power going into HC05 on Funduino. Anyone know why? I'll probably test this with another Funduino tomorrow. If it's doesn't work then idk what would work.

Your sketches do not address the HC05s. There is no "Serial.read()" (to read the information arriving from the HC05.

Usually, the HC05 uses hardware serial (pins 0 and 1) to pass data. You should remove the HC05 when uploading your sketch.

This (above) does not configure any pin because "i" is never greater than 8, ... Try...

  for (int i = 2; i < 9; i++) { // pins 2 through 8

Are your button pins tied HIGH or LOW?

    pinMode(i, INPUT);

Files for WOKWI.COM

sketch.ino
#define joy_x A0
#define joy_y A1
#define btn_a 2
#define btn_b 3
#define btn_c 4
#define btn_d 5
#define btn_e 6
#define btn_f 7
#define joy_btn 8

void setup() {
  for (int i = 2; i < 9; i++) {
    pinMode(i, INPUT_PULLUP);
  }
  Serial.begin(115200);
}

void loop() {
  Serial.print('$');
  if (analogRead(joy_x) < 1000) Serial.print("0");
  if (analogRead(joy_x) < 100) Serial.print("0");
  if (analogRead(joy_x) < 10) Serial.print("0");
  Serial.print(analogRead(joy_x));
  Serial.print(',');
  if (analogRead(joy_y) < 1000) Serial.print("0");
  if (analogRead(joy_y) < 100) Serial.print("0");
  if (analogRead(joy_y) < 10) Serial.print("0");
  Serial.print(analogRead(joy_y));
  Serial.print(',');
  Serial.print(digitalRead(btn_a));
  Serial.print(',');
  Serial.print(digitalRead(btn_b));
  Serial.print(',');
  Serial.print(digitalRead(btn_c));
  Serial.print(',');
  Serial.print(digitalRead(btn_d));
  Serial.print(',');
  Serial.print(digitalRead(btn_e));
  Serial.print(',');
  Serial.print(digitalRead(btn_f));
  Serial.print(',');
  Serial.print(digitalRead(joy_btn));
  Serial.println('#');
  delay(500);
}
diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-analog-joystick",
      "id": "joystick1",
      "top": -144.6,
      "left": 207,
      "attrs": {}
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -70.6,
      "left": -9.6,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn2",
      "top": -118.6,
      "left": -9.6,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn3",
      "top": -166.6,
      "left": -9.6,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn4",
      "top": -70.6,
      "left": 134.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn5",
      "top": -118.6,
      "left": 134.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn6",
      "top": -166.6,
      "left": 134.4,
      "attrs": { "color": "green" }
    }
  ],
  "connections": [
    [ "nano:5V", "joystick1:VCC", "red", [ "v14.4", "h76.3" ] ],
    [ "nano:GND.1", "joystick1:GND", "black", [ "v24", "h85.9" ] ],
    [ "joystick1:SEL", "nano:8", "green", [ "v19.2", "h-192" ] ],
    [ "joystick1:VERT", "nano:A0", "green", [ "v124.8", "h-38.4" ] ],
    [ "joystick1:HORZ", "nano:A1", "green", [ "v134.4", "h-153.6" ] ],
    [ "nano:GND.2", "btn4:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn5:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn6:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn1:2.r", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn2:2.r", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn3:2.r", "black", [ "v0" ] ],
    [ "nano:2", "btn4:1.l", "green", [ "v0" ] ],
    [ "nano:3", "btn5:1.l", "green", [ "v0" ] ],
    [ "nano:4", "btn6:1.l", "green", [ "v0" ] ],
    [ "nano:5", "btn3:1.r", "green", [ "v0" ] ],
    [ "nano:6", "btn2:1.r", "green", [ "v0" ] ],
    [ "nano:7", "btn1:1.r", "green", [ "v0" ] ]
  ],
  "dependencies": {}
}

Oh I don't think that's the problem tho. I connected again with another cable and it worked. And I think Serial1 part of the code works like "Serial.read()". Now I can send data from Funduino to Leonardo without any problem.

Oh yeah I accidentally write like that lol. I already fixed it so no worries!!

I don't think I need to put high or low. That's for the joystick buttons and they're working.

So I fixed most of the part and I can get all data from serial monitor. But there's another problem now. Even if the joystick is stationary for some reason it's detected this way on the computer like this:

I tried to mess around with the map code but I couldn't fix it. Is it a hardware problem?

You should have a "TRIM POT" dial on your joystick. The physical joystick is made almost perfect. What your program is seeing is the joystick (both of them) are a little bit "up" and a little bit "left"... a "trim pot" will let you center the joystick READING by adding or subtracting a little. Look on your device for a plastic tab. Another solution would be in your software... but first take a look at your joystick.

[edit]
I just looked at an "xbox" controller and did not find a "trim pot" so software will be the answer. Your code should allow about 100 bits for "deadband" meaning "zero/center" will be 462 to 562 and outside of that "deadband" will be a valid x or y movement.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.