Teensy 4.0 build for kids

It’s possible to use the audio out that’s on the teensy. It’s not the best quality, but it works. The sound comes out on A14. For teensysaber V1 and teensysaber V2, this is how it worked. The sound on A14 is pretty weak though, so you would need an analog amplifier, or possibly something like a self-powered speaker to listen to it. (or headphones)

I’m a big fan of the MAX98357A though. It is a digital all-in-one class D dac-and-amplifier. Basically, it’s an H-bridge driven with ~400kHz PWM, which then gets all nicely smoothed out in the speaker.

Btw, if you hook up a MAX98357A, make sure to keep the wires short, as high-frequency signals tends to get muddled in longer cables. Same thing goes for the SD card. Bad connections with high resistance can also cause problems.

To me, the nice thing about digital signals, is that when they work, they work perfectly. Analog signals are always subject to noise, so it’s really easy for it to work “so-so”, which can be very annoying.

Teensy 4.0 is not currently 100% supported in ProffieOS.

Does neopixals work with the 4.0 and sound board??? without the motion.

No, ProffieOS does not have support for neopixels on a Teensy 4.x yet.
Shouldn’t be overly difficult to add though.

May just need to do this with a TeensySaber board since storage is the next issue for playing sounds.

The teensysaber boards certainly makes this easier, but I’m not sure if it’s the most educational. Also, there’s not an easy way to find lots of them right now. Basically you would need to make them yourself if you wanted to scale up.

There are a lot of SD breakout boards on the market that could work, like for instance this one:

You just have to solder some pins to it.

When I built my first teensy-based saber, I used this one:

https://www.pjrc.com/store/sd_adaptor.html

It’s not actually meant for a Teensy 3.2, but that doesn’t matter if you’re breadboarding anyways. I used it because it’s small.

The other alternative would be to use a Teensy 3.5, which has an SD card reader on it.

I feel like this might be relevant here as well:

This is my breadboard of a V3 proffieboard, not nearly as neat as yours though. :slight_smile:

1 Like

Work in progress: https://jeremy.laurenson.com/lightsaber/

1 Like

Very nice. :slight_smile: Please let us know if you need any help!

Ok, yesterday my AMP/DAC as well as MicroSD card units and external power boards came in.
(see end of post for parts)

Problem 1: SDCard Info

I connected the SDCard board up, with a new sketch with CD on D10 running at 24MHz on the teensy 3.2 and it as detected fine, including querying card size, FAT etc.

#include <SD.h>
#include <SPI.h>

Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 10;    

void setup()
{
  Serial.begin(9600);
  Serial.print("\nInitializing SD card...");

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present."); 
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  if (volumesize < 8388608ul) {
    Serial.print("Volume size (bytes): ");
    Serial.println(volumesize * 512);        // SD card blocks are always 512 bytes
  }
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 2;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  

}


void loop(void) {
  
}

I then moved the chipSelect to pin 0 and reloaded the Teensy code at full speed.
Should I be seeing anything in the serial monitor? I dont seem to be.


#ifdef CONFIG_TOP
#include "v3_config.h"
#define NUM_BLADES 1
#define NUM_BUTTONS 2
#define VOLUME 2200
const unsigned int maxLedsPerStrip = 26;
#define CLASH_THRESHOLD_G 1.0
#define ENABLE_AUDIO
#define ENABLE_MOTION
#define ENABLE_WS2811
#undef ENABLE_STATE
#endif

1 Like

I don’t think it really says anything to indicate that the SD card was found. Usually the easiest way to check if the sd card is working is to use the “dir” command in the serial monitor.

If the SD card is NOT found, ProffieOS should say “sd card not found” through the speaker. Assuming you have a speaker of course. :slight_smile:

Hell yes I have a speaker :slight_smile:

Does it work?
If you’re not sure, the “beep” command is a good way to test the speaker that doesn’t require an SD card.

Audio is up, playing beeps etc, but finding files is not:

Battery voltage: 4.41
Whut? :dir
TeensySF/
Playing hum01.wav
File hum01.wav not found.
Amplifier off.
Battery voltage: 4.38

Of course hum01.wav IS in the TeensySF directory

$Id: lightsaber.ino,v 1.312 2019/03/16 21:51:20 hubbe Exp $
Battery voltage: 4.40

Was there a different structure for v3?

When I type effects it comes back straight away “done listing effects”

Also:


In file included from /Volumes/Pegasus R4i/Software/Sabers/Tutorial/06 LightSaber Audio/lightsaber/lightsaber.ino:721:0:
/Volumes/Pegasus R4i/Software/Sabers/Tutorial/06 LightSaber Audio/lightsaber/common/current_preset.h: In member function 'void CurrentPreset::SaveAt(int)':
/Volumes/Pegasus R4i/Software/Sabers/Tutorial/06 LightSaber Audio/lightsaber/common/current_preset.h:110:19: warning: 'tmp.CurrentPreset::preset_num' may be used uninitialized in this function [-Wmaybe-uninitialized]
       preset_num++;
                   ^
/Volumes/Pegasus R4i/Software/Sabers/Tutorial/06 LightSaber Audio/lightsaber/common/current_preset.h:231:19: note: 'tmp.CurrentPreset::preset_num' was declared here
     CurrentPreset tmp;
                   ^
Sketch uses 152316 bytes (58%) of program storage space. Maximum is 262144 bytes.

This is a seriously old version of ProffieOS, back from before it was called ProffieOS.
Note that you do not need to use such an old version, ProffieOS has changed name, but it still supports TeensySaber configurations.

Also, I just noticed that you’re missing #define ENABLE_SD in your config file.

This doesn’t do anything, as there is generally no need to #undef anything, and there is no ENABLE_STATE define in ProffieOS.

Threw in 5.9

No sdcard found.
blade= 0
WS2811 Blade with 26 leds.
Failed to open: presets.ini
Failed to open: presets.tmp
Scanning sound font: TeensySF done
Activating polyphonic font.
Welcome to ProffieOS, type 'help' for more info.
I2C TRY
I2C pullups found, initializing...
Motion setup ... done.
Amplifier off.
TeensySF
Done listing files.
Battery voltage: 26.20
v5.9
Installed: Jan  6 2022 19:49:57

Ill check the wiring again in the am

I ordered a few adapters from PJRC so I have the “real deal” as well… time to wait a few days again

This obviously isn’t good.
It should work though.

Could you post your entire config file?

I suspect crappy aftermarket SDCard boards…

// This is a sample configuration file.
// This saber has:
//   o TeensySaber V3 hardware.
//   o Two buttons
//   o An XP-E2 RGB LED star.
// If you have a saber similar to this one, make a copy and use the copy.
// This is also the default configuration file. Pre-programmed boards will
// use this configuration file.

#ifdef CONFIG_TOP
#include "v3_config.h"
#define NUM_BLADES 1
#define NUM_BUTTONS 2
#define VOLUME 2200
const unsigned int maxLedsPerStrip = 26;
#define CLASH_THRESHOLD_G 1.0
#define ENABLE_AUDIO
#define ENABLE_MOTION
#define ENABLE_WS2811
#define ENABLE_SD
#endif

#ifdef CONFIG_PRESETS
Preset presets[] = {
  { "TeensySF", "tracks/mars.wav",
    StyleNormalPtr<CYAN, WHITE, 300, 800>(), "cyan"},
  { "TeensySF", "tracks/mars.wav",
    StylePtr<InOutSparkTip<EASYBLADE(BLUE, WHITE), 300, 800> >(), "blue"},
  { "TeensySF", "tracks/mars.wav",
    StyleNormalPtr<RED, WHITE, 300, 800>(), "red"},
  { "TeensySF", "tracks/mars.wav",
    StylePtr<InOutHelper<EASYBLADE(OnSpark<GREEN>, WHITE), 300, 800> >(), "green"},
  { "TeensySF", "tracks/mars.wav",
    StyleNormalPtr<WHITE, RED, 300, 800, RED>(), "white"},
  { "TeensySF", "tracks/mars.wav",
    StyleNormalPtr<AudioFlicker<YELLOW, WHITE>, BLUE, 300, 800>(), "yellow"},
  { "TeensySF", "tracks/mars.wav",
    StylePtr<InOutSparkTip<EASYBLADE(MAGENTA, WHITE), 300, 800> >(), "magenta"},
  { "TeensySF", "tracks/mars.wav",
    StyleStrobePtr<WHITE, Rainbow, 15, 300, 800>(), "strobe"}
};
BladeConfig blades[] = {
{0, WS2811BladePtr<26, WS2811_ACTUALLY_800kHz | WS2811_GRB>(), CONFIGARRAY(presets) },
};
#endif


#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_POWER, powerButtonPin, "pow");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
#endif

Possibly, but if it works with another sketch, then it ought to work with ProffieOS too, assuming the chip select is wired correctly. One thing to look out for is that if the SD card stays powered when the teensy reboots (perhaps because of getting programmed) it’s possible for the SD card to end up in a state where the teensy can’t talk to it. It doesn’t generally happen on real sabers because of kill keys/kill switches, but it can be a problem for a prototype like this.

The other sketch was pretty specific at 24MHz and such. Ill wait for the other units.

In the meantime, I am done with videos and schematics up to the basic sound piece, things are looking better: https://Jeremy.laurenson.com/lightsaber

It could simply be that the wires are too long.
I see that the sketch you used before initializes the sd card with SPI_HALF_SPEED. I’m not sure what speed that is, but it’s entirely possible that the way that ProffieOS initializes the SD card uses a higher speed, which may not work as well if the wires are too long. At 20 Mhz, the quality and length of the wires starts to matter…