Arduino nano 33 ble pin doesn't work

Hello guys!

I'm new to programming in arduino and I have been stuck on a problem that I can't wrap my head around it. I have an arduino nano 33 ble and I'm trying to make a little applience where I'm using the built in IMU and a mini joystick (MICRO-JOY-A NINIGI - Joystick | DC terhelés @R: 0,05A/12VDC; SMT; 300mg; 7,4x7,7mm | TME Hungary Kft. - Elektronikai alkatrészek). I'm using digital pins (d2-d6) with INPUT_PULLUP and the GND to acquire the data of joystick, but it is always show me 1 even when I'm using the joystick. I checked the joystick is working fine but I found out that on the pulled up pin there is [mV] instead of the operating 3V that supposed to be there in my knowledge.
Can you guys help me out on this? Thank you very much for your answers in advance!
This is the code that I upload on it:

#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h>


/*
Used codes:
    Debounce: https://starduino.hu/2020/09/13/prellmentesites-arduino/
    BLE connection: https://forum.arduino.cc/t/connecting-ble-sense-to-the-pc/634760/9
*/

BLEService customService("1101");
BLEUnsignedIntCharacteristic customXChar("2101", BLERead | BLENotify);
BLEUnsignedIntCharacteristic customYChar("2102", BLERead | BLENotify);
BLEUnsignedIntCharacteristic customZChar("2103", BLERead | BLENotify);
BLEBoolCharacteristic customDirection("2104", BLERead | BLENotify);

int accelX = 1, accelY = 1, accelZ = 1;
bool iranyok [5] = {0};     //  saving Joystick data here
float x, y, z;


void read_Accel() {                   // IMU data acquire 

  if (IMU.accelerationAvailable()) {
  IMU.readAcceleration(x, y, z);
  accelX = (1+x)*100;
  accelY = (1+y)*100;
  accelZ = (1+z)*100;
  }
}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

void setup() 
{ 
  IMU.begin();                //  IMU start
  Serial.begin(115200);         
  while (!Serial);

  pinMode(20,INPUT_PULLUP);           
  pinMode(21,INPUT_PULLUP); 
  pinMode(22,INPUT_PULLUP); 
  pinMode(23,INPUT_PULLUP);      
  pinMode(24,INPUT_PULLUP); 


  pinMode(LED_BUILTIN, OUTPUT);                                                   
                                                      //  BLE start
  if(!BLE.begin()){                                   // BLE working?
    Serial.println("BLE nem indult el");
    delay(500);
    while(1);
  }

  BLE.setLocalName("ArduinoBLE_Test");                // BLE identifier
  BLE.setAdvertisedService(customService);

  customService.addCharacteristic(customXChar);             // IMU XYZ data
  customService.addCharacteristic(customYChar);
  customService.addCharacteristic(customZChar);

  customService.addCharacteristic(customDirection);         // Joystick data

  BLE.addService(customService);

  customXChar.writeValue(accelX);                           // writing with ble
  customYChar.writeValue(accelY);
  customZChar.writeValue(accelZ);

  customDirection.writeValue(iranyok);

  BLE.advertise();
  Serial.println("Bluetooh eszköz aktív és csatlakozásra vár...");              

}





void loop() 
{

  BLEDevice central = BLE.central();              // Connecting to device

  if (central) {
    Serial.print("Csatlakozott: ");
    Serial.println(central.address());
    digitalWrite(LED_BUILTIN, HIGH);

    while (central.connected()) {                 
      delay(200);
      read_Accel();

      iranyok [0] = digitalRead(20);                // Joystick data
      iranyok [1] = digitalRead(21);
      iranyok [2] = digitalRead(22);
      iranyok [3] = digitalRead(23);
      iranyok [4] = digitalRead(24);

      customXChar.writeValue(accelX);
      customYChar.writeValue(accelY);
      customZChar.writeValue(accelZ);
      customDirection.writeValue(iranyok);

      Serial.print("XYZ irányok:");
      Serial.println("");
      Serial.print(" - ");
      Serial.println(accelX);
      Serial.print(" - ");
      Serial.println(accelY);
      Serial.print(" - ");
      Serial.println(accelZ);
      Serial.print("\n");
      Serial.print("Joystick:");
      Serial.println("");
      Serial.print(" - ");
      Serial.println(iranyok [0]);
      Serial.print(" - ");
      Serial.println(iranyok [1]);
      Serial.print(" - ");
      Serial.println(iranyok [2]);
      Serial.print(" - ");
      Serial.println(iranyok [3]);
      Serial.print(" - ");
      Serial.println(iranyok [4]);
      
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
  Serial.print("Lecsatlakozott: ");
  Serial.println(central.address());

}

try simple sketch only for Joy. if you understand how it works then implement new features, one by one

Welcome to the forum.

Here are a few things a noted about your code:

  • You should not use delay. It allows to write some very short example code but is generally a bad idea especially for applications with communication stacks. Rewrite your code using millis. Make sure your loop() runs as often as possible. Do not stop and wait for things to happen. Also avoid while as much as possible. Check your buttons, sensors ..., use status variables, set stuff and move on.
  • Custom characteristics and services must use 128-bit random UUIDs. Do not use use 16-bit UUIDs unless they have been specified by the Bluetooth SiG. There are UUID generator available online.
  • I would not use Char for characteristics variable names. That term is used in embedded programming for a specific type.
  • Avoid using your native language. Makes it hard for other to read and understand your code.
  • Listen to kolaha. Test your joystick code with some simple code first.

Here is a BLE example I wrote a long time ago with some tips that may help.

https://forum.arduino.cc/t/bluetooth-communications/902610/2

Thank you very much! What about the pulled up pins? In my knowledge it supposed to be ~3V on the pins, if I use digitalWrite(pinNumber, HIGH) or pinMode(pinNumber, INPUT_PULLUPS), but instead I measure 50-100 mV. What do you guys think about it? Thank you your answeres in advance!

 pinMode(20,INPUT_PULLUP);           
  pinMode(21,INPUT_PULLUP); 
  pinMode(22,INPUT_PULLUP); 
  pinMode(23,INPUT_PULLUP);      
  pinMode(24,INPUT_PULLUP);

22-25 have on board leds attached, and I'm not clear why or how you are using them for digital i/o. How is the joystick wired to the Nano33 BLE?

// LEDs
// ----
#define PIN_LED     (13u)
#define LED_BUILTIN PIN_LED
#define LEDR        (22u)
#define LEDG        (23u)
#define LEDB        (24u)
#define LED_PWR     (25u)

The other two pins at issue should be OK, but perhaps your voltage reading method is pulling them down.
#define PIN_A6 (20u)
#define PIN_A7 (21u)