element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Build a Present
  • Challenges & Projects
  • Project14
  • Build a Present
  • More
  • Cancel
Build a Present
Blog Singing Traditional Christmas star – Blog#2 Testing LED strip
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 28 Dec 2021 3:37 PM Date Created
  • Views 1265 views
  • Likes 11 likes
  • Comments 1 comment
  • Arduino_MKR_ZERO
  • buildapresentch!
  • pir
  • apa102
  • i2s
  • buildapresentch
Related
Recommended

Singing Traditional Christmas star – Blog#2 Testing LED strip

carmelito
carmelito
28 Dec 2021

This is a continuation, of my first blog for the Singing Traditional Christmas star, using the Arduino MKR ZERO. As part of this blog my mission is to add LEDs to the star inside before wrapping it up with butter paper. And I will also have to think of a way to add the speaker to one of the spokes of the star, so that the sound can be heard clearly.

For the LEDS, I know I mentioned in my previous blog post that I would use NeoPixels, but I don't have a strip which means I would have to chain the single NeoPixels which will get messy, so instead of chaining NeoPixels together one by one, I planned to use APA102 strip that I had in my kit.

Here is the updated circuit.

MKRZero adding APA102 Led strip

The APA102 LED strip connection to the Arduino MKR ZERO

  • VCC of the LED strip is connected to 5V on the Arduino MKR ZERO

  • GND connected GND

  • DI on the LED strip is connected to pin 11 SDA of the Arduino MKR ZERO

  • CI on the LED strip is connected to pin 12 SCL

PIR sensor is connected to pin 1 on the Arduino MKR Zero

Here are the connection details for the Adafruit I2S 3W Class D Amplifier Breakout MAX98357A and Arduino MKR ZERO

  • VIN on the I2S amplifier connected 5V of the Arduino MKR Zero

  • GND connected GND

  • LRC connected to pin 3

  • BCLK connected to pin 2

  • DIN connected to pin A6

Refer to the previous blog post, for the Arduino IDE setup for the MKR boards, and to add the Arduino Sound Library. In addition, for the APA102 LED strip you will have to install the APA102 library

Arduino APA102 Library

Here is the code uploaded to the Arduino MKR ZERO

#include "Arduino_APA102.h"
#include <SD.h>
#include <ArduinoSound.h>

int ledPin = LED_BUILTIN;  // LED to check if some is detected
int pirPin = 1;   // PIR pin
int pirStat = 0;  // PIR status
// Setting up APA102 
int dataPin = 11;
int clockPin = 12;
int totalLEDs = 5; //change this to the number of LEDs in the star
//Construct object, Arduino_APA102(nLEDS, data line, clock line)
Arduino_APA102 leds(totalLEDs, dataPin, clockPin);
int i,j = 0;

// filename of wave file to play
const char filename[] = "MUSICO.WAV";
// variable representing the Wave File
SDWaveFile waveFile;
void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(pirPin, INPUT); 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // setup the SD card, depending on your shield of breakout board
  // you may need to pass a pin number in begin for SS
  Serial.print("Initializing SD card...");
  if (!SD.begin()) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // create a SDWaveFile
  waveFile = SDWaveFile(filename);
  
  // check if the WaveFile is valid
  if (!waveFile) {
    Serial.println("wave file is invalid!");
    while (1); // do nothing
  }
  // print out some info. about the wave file
  Serial.print("Bits per sample = ");
  Serial.println(waveFile.bitsPerSample());
  long channels = waveFile.channels();
  Serial.print("Channels = ");
  Serial.println(channels);
  long sampleRate = waveFile.sampleRate();
  Serial.print("Sample rate = ");
  Serial.print(sampleRate);
  Serial.println(" Hz");
  long duration = waveFile.duration();
  Serial.print("Duration = ");
  Serial.print(duration);
  Serial.println(" seconds");

  // adjust the playback volume
  AudioOutI2S.volume(95);
  // check if the I2S output can play the wave file
  if (!AudioOutI2S.canPlay(waveFile)) {
    Serial.println("unable to play wave file using I2S!");
    while (1); // do nothing
  }

}

void loop() {
 pirStat = digitalRead(pirPin); 
 if (pirStat == HIGH) {            // if motion detected
   digitalWrite(ledPin, HIGH);  
   Serial.println("starting playback");
   AudioOutI2S.play(waveFile);

 } 
 else {
   digitalWrite(ledPin, LOW); // turn LED OFF if we have no motion
   Serial.println("Errr...");
   j = AudioOutI2S.isPlaying();
  //check if playback is still going on
   if (AudioOutI2S.isPlaying()) 
   {
      Serial.println("playback going on..");
    //running LEDs
      leds.begin();
      for(i=0; i < totalLEDs; i++)
      {
        leds.setPixelColor(i ,255,0,0);
        leds.show();
        delay(100);
      }
      for(i=0; i < totalLEDs; i++)
      {
        leds.setPixelColor(i ,0,255,0);
        leds.show();
        delay(100);
      }
      for(i=0; i < totalLEDs; i++)
      {
        leds.setPixelColor(i ,0,0,255);
        leds.show();
        delay(100);
      }
      
   }
   Serial.println(j);
     for(i=0; i < totalLEDs; i++)
      {
        leds.setPixelColor(i ,0,0,0);
        leds.show();
        delay(10);
      }
 }
delay(100);
}

Now before I get to the difficult part of the build, that is dressing up the star and hiding the components, here is a quick diffusion test of the LED strip - APA102, with one spoke of the star dressed with butter paper.

Star LED strip diffusion 1Star LED strip diffusion 2Star LED strip diffusion 3

  • Sign in to reply

Top Comments

  • scottiebabe
    scottiebabe over 3 years ago +4
    I like how the butter paper (I think locally we call it https://en.wikipedia.org/wiki/Parchment_paper, ) diffuses the LEDs, it looks really good! I will have to remember this idea.
  • scottiebabe
    scottiebabe over 3 years ago

    I like how the butter paper (I think locally we call it https://en.wikipedia.org/wiki/Parchment_paper,) diffuses the LEDs,  it looks really good! I will have to remember this idea.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube