Arduino Nano BLE 33

Hello Arduino Forum, Please I need a little help, I am using Arduino Nano BLE 33. And I want to print two values on my serial monitor. and i can't seem to get the values. My wiring is correct, i verified it using Arduino Nano. So i assume it's my code. Please Help me, thank you

volatile int NbTopsFan = 0;         // Nombre de tours d'hélices
float Calc = 0.0;          // Calcul du volume
float Q = 0.0;             // Calcul du débit
int hallsensor = 3;        // PIN DIGITAL 3
int tsampling = 500;
void rpm() {
  NbTopsFan++;
  Serial.println("Interrupt triggered. NbTopsFan: " + String(NbTopsFan));}
void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT_PULLUP);
  Serial.println("Hall effect sensor test:");
  for (int i = 0; i < 10; i++) {
    int sensorValue = digitalRead(hallsensor);
    Serial.println(sensorValue);
    delay(500);}
  Serial.println("End of hall effect sensor test");
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING); // Gestion de l'interruption
}

void loop() {
  NbTopsFan = 0;
  delay(1000);
  Q = NbTopsFan / (20.0 * tsampling);
  Calc += (Q / 60.0);
  Serial.println(Calc);
  Serial.println(Q);
  delay(200);
}

Why did you start a topic in the Uncategorised category of the forum when its description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to the Nano 33 BLE category

Please is there a problem with Interrupt in Arduino Nano BLE 33?

Please someone can help me, i am very hopeless. Spent two days on this. Please help me

Serial.println("Hall effect sensor test:");

Do you see this message on the Serial monitor ?

No. I don't. I simplied my code to this and I still can't see anything, please help

#define hallsensor 2        // PIN DIGITA
volatile int NbTopsFan;         // Nombre de tours d'hélices
float Calc;          // Calcul du volume
float Q;             // Calcul du débit
int tsampling = 2;

void rpm() { 
   NbTopsFan++;
   Serial.println("Interrupt triggered");}

void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT); 
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);} // Gestion de l'interruption
void loop() {
  NbTopsFan = 0;
  delay(1000 * tsampling);
  Q = NbTopsFan/ (20 * tsampling);}

It can be something related to the interruption that you are attaching. Check if the function works with the nRF52 SoC. I had problems before working with interruption. I solved them by coding at a register level and assigning the correct priorities to the interruptions.

Simplify it further


void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println("Hello");
    delay(1000);
}

After uploading the program, are you going back into tools and selecting the USB port instead of the programming port? It may not automatically revert.

Hello @cattledog . Yes I am selecting the right port and the only thing i see is 0.00 (which is the value of Q) so i believe rpm function I created doesn't increment. I think it's a problem of the interruption, But i am not sure, feel free to give me ideas.

Hello, yes i tried it, it works, and I even connected a led to all the digital ports to see if they work, and they all work just fine, so i think there is a problem with interruption. Do you have any suggestions how i can solve this?

Hello, My arduino nanno is based on Nordic nRF 52840. Its microcontroller is not type nRF52 SoC, can you please me how to code at a register level and assign the correct priorities to the interruptions, if not just show me your code and i can inspire from it. Thank you.

One obvious problem is that you are printing inside the ISR

Interrupts are disabled when in an ISR
Serial printing uses interrupts

Can you see a potential problem ?

@UKHeliBob I removed all the Serial.print(), and it stills doesnt work. If i am still doing it wrong, please feel free to correct me.

volatile int NbTopsFan = 0;         // Nombre de tours d'hélices
float Calc = 0.0;          // Calcul du volume
float Q = 0.0;             // Calcul du débit
int hallsensor = 2;        // PIN DIGITAL 3
int tsampling = 1;

void rpm() {
  NbTopsFan++;}

void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT);
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING); }

void loop() {
  NbTopsFan = 0;
  delay(tsampling * 1000);
  Q = NbTopsFan / (20.0 * tsampling);
  Serial.println(Q);
  delay(200);}

You have several other threads where you have read interrupts to see
values for Q which you sent to a phone with BLE. Are you saying that in those other threads, you never achieved data other than 0? Did something change?

What happens if you don't set NbTopsFan to zero each time through loop() ?

No i use to receive the data i wanted, now absolutely nothing, nothing has changed. And I don't know why.

Still nothing.

Please post the code and output in code tags

Okey, i am sorry i thought with a capture it's much easier

int hallsensor= 2;        // PIN DIGITA
int NbTopsFan;         // Nombre de tours d'hélices
float Calc;          // Calcul du volume
float Q;             // Calcul du débit
int tsampling = 2;

void rpm() {NbTopsFan++; }


void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT); 
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);
  }
void loop() {
 // NbTopsFan = 0;
  delay(1000 * tsampling);
  //Serial.println(digitalRead(hallsensor));
  Q = NbTopsFan/ (20 * tsampling);
  Serial.println(Q);}