JTK – Notes and Ramblings Things we have found …

1/13/2023

Yoda Lights Up

Filed under: Arduino,General — taing @ 4:25 pm

As a follow-up to Yoda Speaks, we now have Yoda Lights Up. We have added a Sparkfun WS2812 Thru-Hole RGB LED to Yoda’s hand. There is a helpful Sparkfun WS2812 Hook-up guide. It allows for easy setup with the Sparkfun Papa Soundie we are using for the sound playback.

The LED is connected to Vcc/+5vdc, GND and Pin 10. We chose to use the FastLED library for our setup. There is a wiki online to answer many of your questions. As for code, our example is pretty simple:

#include <FastLED.h>

#define DATA_PIN    10
#define NUM_LEDS    1
#define LED_TYPE    WS2812
#define COLOR_ORDER RGB

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}

void loop() {
  leds[0].setRGB(0,255,0);
// or
  leds = CRGB::Green;
  FastLED.show(); 
  delay(30);
}

Sparkfun points to some example code and the Adafruit NeoPixel library. Additional it is also recommended to add a series resistor(220 – 470 ?) on the data line and a filter capacitor(100µF – 1000µF) across the power lines if using more than a pixel of two. If you are using a large number of pixels there is a nice article on Large Power Loads and Daisy Chained LED Strips.

12/30/2022

Yoda Speaks

Filed under: Arduino,General — taing @ 11:49 am

It was finally time to put the Sparkfun Papa Soundie to work. The Sparkfun hook-up guide provides most of the details – a 3.3v ATmega328P paired with the VLSI‘s VS1000D audio codec IC. They have created an Arduino library to control the VS1000D. This can be downloaded as a zip (archive version).

For the really adventurous there is VSIDE from VLSI to reprogram the firmware in the VS1000D – there are application examples, source code samples and additional PC tools available. We archived a copy of the VS1000D programmers guide.

I supplemented the Papa Soundie with a small speaker and a PIR motion sensor, Sparkfun’s OpenPIR. The sensor is based around the NCS36000 PIR controller and will work with 3v to 5.75v. Sparkfun has created a hook-up guide, also.

Audacity made quick work of converting a few .wav and .mp3 sound clips of Yoda’s voice to the preferred Ogg Vorbis / .ogg format. The preinstalled firmware on the VS1000D wants to find files in either .ogg or .wav format on the microSD card. The files should be named AUDIOxx.OGG or FILESxx.WAV (xx is 00 thru 31). Unfortunately, you need to start with 00 and not skip any slots.

I based my project on the Hardware Example Project from the Sparkfun Hook-up Guide. I removed the code for the servo and added code to prevent immediate re-triggering and to randomly select the file to play. The random selection is configured not to repeat a file until all have played – card deal style.

#include "SparkFun_PapaSoundie.h"

  int motionStatusOld = LOW;
  int motionStatus = LOW;
  int sounds[] = {1, 2, 3, 4, 5};
  int len = 5;

#define PIR_DOUT 9 

PapaSoundie sfx = PapaSoundie();

void setup() {
  Serial.begin(115200);  // Serial is used to view Analog out
  // Analog and digital pins should both be set as inputs (not actually necessary for Analog):
  pinMode(PIR_DOUT, INPUT);
  Serial.println("Getting ready");
  sfx.begin();
}

void loop() {
  int rnd;
  int choice;
  motionStatusOld = motionStatus;
  motionStatus = digitalRead(PIR_DOUT);
  if (motionStatus == HIGH && motionStatus != motionStatusOld) {
    if (len > 1) {
      rnd = random(len);
      choice = sounds[rnd];
      sounds[rnd] = sounds[len-1];
      len = len - 1;
    } else {
      choice = sounds[0];
      len = 5;
        for ( int i = 0; i < len; ++i ){
          sounds[i] = i+1;
        }      
    }
    
    Serial.println(choice);
    
    
    sfx.playFileNumber(choice);
    delay(1000);
  }
}

The wiring is very basic – 5vdc and ground in on the VIN and GND pins, 3.3vdc and ground out to the sensor from the 3.3v and GND pins and the output of the sensor to pin D9.

Keep in mind the sensor does require a bit of time after power-up before being active. The LED on the sensor PCB will blink slowly during start-up. Once up and running the LED will indicate motion.

I think the next step might be to add an LED. Possibly the Sparkfun RGB addressable thru hole version. This is a thru hole 8mm version of the typical WS2812. Three are details in their WS2812 Guide. Adafruit has a very nice Arduino library for the WS2812.

Sound activated Yoda

Powered by WordPress