APA102 POV Globe coding problem

Hi, I’m currently working on a POV Globe powered by an Arduino Nano and 39 APA102 RGB LED’s. The physical build is done, but I have some problems to program the LED’s. I’m using the FastLED library (open for any other library recommendations) and I try to light up some letters on my globe. I’ve found some example code (from GreatScott) but it isn’t working on me even if I just copy the code (not copying it in final project, just a guideline). I think the reason why the code isn’t working are those code lines which i have no clue about what they do…so if someone could explain it to me I’be happy. I think it has something to do with the hall effect sensor he is using, I’m also using one but it is from an older project and is High when no magnet is near to him, the signal gets Low when the magnet is near to him. I have to use an analog input to read the state of the sensor because the high signal of it isn’t 5V, instead it is 4V which isn’t enough that the Nano is recognizeing it as High(actually it should do it but it won’t). This method worked for me in other projects with the hall sensor as well. So if someone could explain to me these lines and tell me how to change it if it has something to do with the hall effect sensor I’d be happy!
The hole .ino file is attached. For better understanding my misunderstanding is about these lines:

EICRA = 0;
EICRA |= (1 << ISC10);
EIMSK = 0;
EIMSK |= (1 << INT1);
sei();
ISR (INT1_vect) {
hall = 1;
}

This is all ot the code:

#include "FastLED.h"
#define NUM_LEDS 38
#define DATA_PIN 11
#define CLOCK_PIN 13
unsigned char i;
unsigned char m;
unsigned int wait = 50;
unsigned int wait2 = 500;
bool hall = 0;
CRGB leds[NUM_LEDS];
bool G[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1}
};
bool R[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
  {1, 1, 0, 0, 0},
  {1, 0, 1, 0, 0},
  {1, 0, 0, 1, 0},
  {1, 0, 0, 0, 1},
};
bool A[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
};
bool T[8][5] = {
  {1, 1, 1, 1, 1},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
};
bool S[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1},
  {0, 0, 0, 0, 1},
  {0, 0, 0, 0, 1},
  {0, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
};
bool C[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1},
};
bool H[8][5] = {
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1}
};

bool E[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1}
};

bool L[8][5] =  {
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1}
};

bool O[8][5] = {
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1}
};

void setup() {
  FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS);
  EICRA = 0;
  EICRA |= (1 << ISC10);
  EIMSK = 0;
  EIMSK |= (1 << INT1);
  sei();
  for (int i = 0; i < 38; i++) {
    leds[i] = CRGB ::Black;
  }
  FastLED.show();
}

ISR (INT1_vect) {
  hall = 1;
}

void loop() {
  if (hall == 1) {
    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (G[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (R[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (E[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (A[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);


    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (T[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);


    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (S[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);


    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (C[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (O[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (T[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (T[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

    for (int i = 11; i < 17; i++) {
      leds[i] = CRGB ::Red;
    }
    leds[18] = CRGB::Red;
    FastLED.show();
    delayMicroseconds(wait);

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);
    hall = 0;
  }
}

bool hall = 0;Should really be true or false and as it is changed in the ISR and its value used outside of the ISR it should be declared volatile

Thak you! I cant use the hall in that way because it is an analog value in my case..what do the lines of code mean I asked before?

I would recommend getting a hall sensor that is compatible to the code.

You will have a very hard time switching the code to use an analog hall, if that's possible at all.

Halls are so cheap, just get the same (or compatible) as used in the original project.

But the arduino can read analog inputs 10.000 times per second...the motor is spinning with 3000rpm so it should be enough? What do these code lines i asked before mean, because I guess these are making the problems..I'd really like if I could use the hall sensor with the analog input.

It's only capable of 9000+ analogReads per second if the processor is not doing anything else.

Using the analogue comparator could be a solution.

But its funny that I bought hall sensors especially made for the arduino and those are outputting 4V...

Yes but I think it will be enough…at 3000rpm the arduino reads the sensor only 50times per second which should definitely work…also I’m not using the hall all the time just for certain animations.

BuildBoy:
I bought hall sensors especially made for the arduino

Unlikely

So can someone of you confirm to me that those code lines are for the hall sensor, what are they doing and how can I inplement my hall sensor? Thak you.

The code lines are setting up an interrupt for a digital Hall effect sensor, which is why I suggested using the analogue comparator.

Thank you for the answer! If we look at all of the code is there a possibility to change it that it works with my analog signal...I've tried it normally to read the input which is on an analog value of 770 (4V) if it isn't near a magnet and 20 when it is near a magnet...I simply created an if analogvalue is below 50 than it should run the code but somehow it doesnt. Any solutions? What exactly do you mean with analog comperator?

The processor has an analogue comparator that can be programmed to generate an interrupt.
It is all detailed in the processor's datasheet.

There will be tutorials on how to use it on the web.

Are those code lines which I asked necessary to run the code and why isnt it working if I delete these lines and replace the hall digital signal with a hall analog value?

But the analog converter does basically the same as analogRead...it looks at the voltage and triggers wehn its above a certain level if I understood it right from the internet...analogread and a simply if code could do the same?

But the analog converter does basically the same than analogRead...

But it does it all the time, and it does it faster.

Hi,

Today at 16:19:28 Last Edit: Today at 16:20:18 by BuildBoy

Hi, I'm currently working on a POV Globe powered by an Arduino Nano and 39 APA102 RGB LED's.
The physical build is done, but I have some problem to program the LED's.
I'm using the FastLED library (open for any other library recommendations) and I try to light up some letters on my globe.
I've found some example code (from GreatScott) but it isn't working pn me even if I just copy the code (not copying it in final project, just a guideline).
I think the reason why the code isn't working are those code lines which i have no clue about what they do..so if someone could explain it to me I'be happy.
I think it has something to do with the hall effect sensor he is using, I'm also using one but it is from an older project and is High when no magnet is near to him, the signal gets Low when the magnet is near to him.
I have to use an analog input to read the state of the sensor because the high signal of it isn't 5V, instead it is 4V which isn't enough that the Nano is recognizeing it as High(actually it sould do it but it won't).
This method worked for me in other projects with the hall sensor as well.
So if someone could explain me these lines and tell me how to change it if it has something to do with the hall effect sensor I'd be happy!
The hole .ino file is attached. For better understanding my misunderstanding is about these lines:

Did you cut/paste/write all the code at once?

You have said you have copied code, but have you written some code to check you I/O components in stages?

Do you have a simple bit of code that J****UST reads the Hall Device to prove you have it connected correctly.
Have you then got a bit of code that JUST checks that the interrupt works?

Have you got a bit of code that JUST tests the LEDs?

If not, then forget your code for the moment and start developing code, for your inputs and outputs confirmation.

Tom... :slight_smile:

I've testet all the components and everything is working. I've tested the led strip with an example code from the Apa102 library and the hall sensor is working because I've used it in older projects as well. Also I've checked it with the serial monitor.

But is it necessary to use the analog converter, because with 50 rotations per second it should be fast enough.

Also if the globe isn't spinning if i trigger the sensor nothing lights up when I replaced the code to fit with my hall sensor.

Basically I did this:

void setup() {
  FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS);
 pinMode(A0, INPUT);
  for (int i = 0; i < 38; i++) {
    leds[i] = CRGB ::Black;
  }
  FastLED.show();
}



void loop() {
int hall = analogRead(A0);
  if (hall <= 100) {
    for (m = 0; m < 5; m++) {
      for (i = 0; i < 8; i++) {
        if (G[i][m] == 1) {
          leds[i + 11] = CRGB::Red;
        }
        else {
          leds[i + 11] = CRGB::Black;
        }
      }
      FastLED.show();
      delayMicroseconds(wait);
    }

    for (int i = 0; i < 38; i++) {
      leds[i] = CRGB ::Black;
    }
    FastLED.show();
    delayMicroseconds(wait2);

I simply deleted all these lines I didn’t understand an replaced the High signal from the Hall with an analog value. In my opinion this code should also work. But even if the globe isn’t spinning and I’m triggering the sensor manually nothing lights up.

BuildBoy:
I've testet all the components and everything is working. I've tested the led strip with an example code from the Apa102 library and the hall sensor is working because I've used it in older projects as well. Also I've checked it with the serial monitor.

But is it necessary to use the analog converter, because with 50 rotations per second it should be fast enough.

Also if the globe isn't spinning if i trigger the sensor nothing lights up when I replaced the code to fit with my hall sensor.

Have you tested the interrupt with the Hall Device code on its own on the POV machinery.
That is have you "suck and see" if the interrupt on its own is fast enough, experiment, you won't damage anything.
Get the interrupt to trigger JUST one LED, to show if its syncing.
Tom... :slight_smile: