Teensy 4.0 breadboard performance

Weird glitchy behavior I assume is power related?

Config:

// 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 "v4_config.h"
#define NUM_BLADES 1
#define NUM_BUTTONS 2
#define VOLUME 2200
const unsigned int maxLedsPerStrip = 30;
#define CLASH_THRESHOLD_G 1.0
#define ENABLE_AUDIO
#define ENABLE_MOTION
#define ENABLE_WS2811
#define GYRO_CLASS MPU6050
#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<30,  WS2811_GRB>(), CONFIGARRAY(presets) },
};
#endif


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

Serial Monitor:

Sdcard found..
blade= 0
WS2811 Blade with 30 leds.
Failed to open: presets.ini
Failed to open: presets.tmp
Style RAM = 216
Scanning sound font: TeensySF done
Activating polyphonic font.
Activating SmoothSwing V2
Accent Swings NOT Detected: 
unit = 0 vol = 0.50, Playing TeensySF/boot.wav
channels: 1 rate: 44100 bits: 16
Welcome to ProffieOS $Id: ce12a06a1e236b5101ec60c950530a9a4719a74d $. Type 'help' for more info.
Audio underflows: 21
Amplifier off.
I2C TRY
I2C pullups found, initializing...
Motion setup ... done.
EVENT: Aux-Pressed#1 millis=6593
EVENT: Aux-Pressed millis=6593
EVENT: Aux-Released#1 millis=6714
EVENT: Aux-Released millis=6714
EVENT: Aux-Shortclick#1 millis=6714
EVENT: Aux-Shortclick millis=6714
Failed to open: presets.ini
Failed to open: presets.tmp
Style RAM = 232
Scanning sound font: TeensySF done
Activating polyphonic font.
Activating SmoothSwing V2
Accent Swings NOT Detected: 
DISPLAY: blue
unit = 0 vol = 0.50, Playing TeensySF/font.wav
channels: 1 rate: 44100 bits: 16
Amplifier off.
EVENT: Power-Pressed#1 millis=10135
EVENT: Power-Pressed millis=10135
EVENT: Power-Released#1 millis=10260
EVENT: Power-Released millis=10260
EVENT: Power-Shortclick#1 millis=10260
EVENT: Power-Shortclick millis=10260
Ignition.
unit = 0 vol = 0.00, Playing TeensySF/hum01.wav
channels: 1 rate: 44100 bits: 16
unit = 1 vol = 0.50, Playing TeensySF/out01.wav
channels: 1 rate: 44100 bits: 16
humstart: 1890
unit = 2 vol = 0.00, Playing TeensySF/swingl02.wav
channels: 1 rate: 44100 bits: 16
unit = 3 vol = 0.00, Playing TeensySF/swingh02.wav
channels: 1 rate: 44100 bits: 16
Motion chip timeout, reboot motion chip!
Motion setup ... done.
Motion chip timeout, reboot motion chip!
Motion setup ... done.
Playing TeensySF/swingh02.wav
channels: 1 rate: 44100 bits: 16
Playing TeensySF/swingl02.wav
channels: 1 rate: 44100 bits: 16
unit = 3 vol = 0.00, Playing TeensySF/swingl07.wav
channels: 1 rate: 44100 bits: 16
unit = 2 vol = 0.00, Playing TeensySF/swingh07.wav
channels: 1 rate: 44100 bits: 16
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Motion chip timeout, reboot motion chip!
Motion setup ... failed.
Battery voltage: 0.00
Motion chip timeout, reboot motion chip!
Motion setup ... 

Not sure what’s going on here, but here are a few possibilities:

  1. The teensy4 support is quite immature, so there might be bugs there.
  2. Someone also told me that the MPU6050 support might be buggy, but didn’t offer more details, so I’m not sure if that’s true or not. If you have an LSM6DSM to try with, see if that works better maybe?
  3. Did you update v4_config.h for the different motion chip?
  4. 30 neopixels are going to draw 1-2A, which is a lot for the poor breadboard. I think you should connect the neopixel +/- directly to the power supply. Then connect - and data to the breadboard.
  5. Both teensy3 and proffieboards have i2c implementations that lets me do retries and resets when things don’t work properly, Teensy4 currently does not, so motion chip problems may behave worse on Teensy4 than on others

3… Yes.
4… Tried this direct with a 3A 5v supply, no change.

a few hours later

2/5… Yes… when I remove the MPU it stabilizes

LSM6DSMs seem to be out of stock most places

But that same MPU was working with the Teensy3, right?

I cant say that - I switched to a 6050 that handled 5v and not just 3.3… so Ill get back to you

Just confirmed. Whichever 6050 I use its crappy. The 3.2 teensy was fine.

That kind of implies that it’s the i2c code that needs work, although it could be a combination of things. Like maybe a bad connection or bugs in the MPU6050 causes problems, and less-than-ideal i2c code freezes instead of resetting properly. I’m going to look into it, just not entirely sure when I’ll have the time…

No worries at all - this is just to help you - I am going to use 3.2s for the moment

@jeremylaurenson - do you have your code and/or wiring posted anywhere? Or are you just using the latest master + that config you posted?

I’m experimenting with the same thing, but with a teensy v4.1. I have only teensy + MAX98357A connected, I can play “batt” and “beep”… but playing audio files only gives a brief crackle, and if I keep going it eventually resets. I suspect the built-in SD card reader isn’t playing nice, but I’m curious if there’s anything else you did to get it working (even though yours is glitchy, it’s still more than what I’m getting).

Thanks!

I didnt draw it up because I am falling back to the 3.2 ( https://jeremy.laurenson.com/lightsaber )

The latest I have is this:

My whole ProffieOS code for this:
https://jeremy.laurenson.com/lightsaber/Teensy40.zip

Just an FYI, I’m hacking away at this trying to get Teensy 4 + MPU6050 to work. What I’m finding:

  • Very simple MPU6050 demo code works just fine (MPU6050 IMU code works with Arduino but not TEENSY 4.0)
  • I can transplant that code into proffieos (replacing most of mpu6050.h), and it works fine, until…
  • If I enable audio, then it starts to fail/timeout/lock up (this is with I2S / MAX98357A)

Looks like mpu6050 uses i2c libs which use standard Wire.h under the hood, while the audio code does a custom DMA-based i2s? Since both work fine on their own, maybe there’s something about the i2c that interferes with the i2s code?

If you run the same code, but disconnect the amplifier, does it work better?
The amplifer can put a lot of noise into the circuit, which might be causing problems.

Are you using the latest code from github? I recently fixed a bug which caused micros() to return the wrong value on teensy boards. I ended up spending several hours cutting away pieces from ProffieOS until I figured out what the problem was…

If you cobble the MP6050 demo code together with the audio library wav player demo, do you get the same problem? Or does it work? The ProffieOS audio code should have roughly the same behavior as the teensy audio library.

It’s possible that the i2c and i2s code interferes with each other somehow, but I haven’t noticed any problems with the LSM6DSO motion chip that I use in my Teensy 4.1 setup…

I just tried disconnecting the amplifier. Results:

  • If I remove only VCC/GND from amp, I get the same problems (motion locks up after a few seconds)
  • If I remove all pins from amp, motion works fine
  • If I remove data/clock pins from amp (but leave VCC/GND connected), motion works fine

So it’s possible that when the amp is enabled & powered it puts too much noise into the system. Should I try some capacitors on VCC and/or GND for this?

It’s still also possible it’s software related, will try that next.

Since CPU->Amplifier is one-way communication, there is definitely something wire or power related going on. I think there is still a software issue with recovery though.

In my setup, I power motion from 3.3v, but I power the amplifier from 5v (VIN).
Capacitors may also help, although the breakout boards might already have some of those.

Pull up resistors! I put some (4.7k) on SCL/SDA, and motion is rock solid (have it humming for a few minutes now). Pulled them off and immediately lost motion. Looks like the teensy’s weak built-in pull ups really are too weak.

From Paul:

For I2C, the internal pullup resistors are activated on Teensy 4.0. That is different than Teensy 3.x, where they are not used. The internal pullup resistors are much weaker than the recommended range (1K to 4.7K) for I2C, so it’s not a good practice to use only the internal pullups. But unlike Teensy 3.x where I2C will not work at all (why NXP designed those chips to not allow the internal pullups in I2C mode is a mind boggling mystery), on Teensy 4.x the pins can and do by default (using the Wire lib) have their weak pullups active, so you can usually get a 100 kbit/sec I2C chip to work without adding resistors.

It looks like a legitimate difference in wiring teensy 4 vs. the older 3.

So this works now with no LED blade (just sound & motion). Now when I add a single WS2812B test pixel, it fails as soon as the LED turns on. Will have to debug that tomorrow, but this is still very promising.

Doesn’t your MPU6050 breakout board have pullups?

Weirdly, it does. I have a blue MPU6050 breakout board, like this: MPU-6050 Triple-axis Accelerometer Gyroscope 6 DOF Module

It does appear to have 2.2k pull up resistors onboard, which falls in the right range. It also has an onboard 3.3v regulator. I’ll have to double check, but I think was doing external pull-up to 5v, whereas the onboard pullups may be to 3.3v. Let me recheck what my wiring was.

And all this may be a red herring; maybe adding the resistors makes things more stable, but the problem still lies elsewhere (like the amp noise you mentioned). Have to do more tests, I really want to have teensy 4.x working.

I found a LSM6DS3 breakout for sale and I’m trying to get it to work with the teensy 4.1. I have it wired up, but it doesn’t seem to want to connect.

I have it wired up simply:
GND->GND
VCC->VIN (this breakout has onboard 3.3V LDO, I can power VIN 5v or 3V directly, I’ve tried both)
Teensy pin 19 → SCL
Teensy pin 18 → SDA
(I’ve also tried with Teensy 2 → INT, but that’s optional right?)

I’ve disabled audio/ws2812/SD card, only doing motion:

#define ENABLE_MOTION
#define GYRO_CLASS LSM6DS3H
...
  motionSensorInterruptPin = -1,      // motion sensor interrupt
  i2cDataPin = 18,                   // I2C bus, Used by motion sensors
  i2cClockPin = 19,                  // I2C bus, Used by motion sensors

The sketch times out trying to initialize the motion chip (this log says WS2811 blade, but most recent tests are with non-WS2811 enabled)

Sdcard found..
blade= 0
WS2811 Blade with 30 leds.
Failed to open: presets.ini
Failed to open: presets.tmp
Style RAM = 216
Scanning sound font: TeensySF done
Activating polyphonic font.
Activating SmoothSwing V2
Accent Swings NOT Detected: 
unit = 0 vol = 0.50, Playing TeensySF/boot.wav
channels: 1 rate: 44100 bits: 16
Welcome to ProffieOS $Id: ce12a06a1e236b5101ec60c950530a9a4719a74d $. Type 'help' for more info.
Audio underflows: 7
Amplifier off.
I2C TRY
I2C pullups found, initializing...
Motion chip ... Motion chip timeout, trying auto-reboot of motion chip!
Motion chip ... Motion chip timeout, trying auto-reboot of motion chip!

This happens at the very first step:

I2C_READ_BYTES_ASYNC(WHO_AM_I, databuffer, 1);

I’m going to try debugging this outside proffieos, with some simple wire.h commands. But just checking that I’m not missing something obvious with my wiring/setup?

I don’t recognize that particular breakout board, so I can’t tell if the wiring is correct or not. Also, I don’t know if the chip is wired for ID 0x6A or 0x6B. ProffieOS expects 0x6A, but you can change it here:

(Just change 106 to 107)

I’ve also been buying a few different accelerometer/gyroscope chips for evaluation recently since the ST ones are hard to find.

Yes - I definitely needed to use address 107.

But also - super embarrassing, I had this connected to the WRONG GND! I only soldered a few pins, the bottom ground was unconnected - floating voltage. Like I said, embarrassing.

I have things nearly working now, just some audio pops/crackles. Seems to be related to poor breadboard wiring/low voltage? Will debug tomorrow, very tired now!

Thanks for the help!!!

PS. Which motion chips are you investigating? Looking on digikey & others shows low stock of nearly everything, and on JLCPCB parts it shows only a tiny handful in stock, including the
LSM6DS3TR-C and LSM6DSLTR. For breakout boards I can find MPU6050 and this LSM6DS3… fine for a quick saber (like I’m making), but less useful for a real PCB-based saber board.