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