Help modifying teensy drum machine

Hey,

I was just wondering if anyone could suggest how I could modify this to add clock out?

I want to use my modular for the melody, so happy to lose the bass melody feature…

I have seen the ‘crum drum’, which looks great, but would prefer to be able to modify it and do my own thing slightly.

It looks like part of the code has been automatically generated, but I wasn’t sure how or what tool was used.

Hi,

I think the audio part was probably generated with this Audio System Design Tool for Teensy Audio Library (pjrc.com)

That said, it looks like pin 32 is free, so you could set that as a digital output, and then find the bit of the code that deals with the sequencer, probably somewhere near here, and adjust it to toggle pin 32. You’d have to take some care on whether you wanted triggers or gates, but it should be doable.

Cheers

2 Likes

Thanks, that makes sense.

From a bit of googling, I think a way to do what you suggest is to create a variable which is the original tempo in milliseconds, then use that to delay a toggle?

Would this work?

clockspeed = 60000 / tempo

void setup() {
pinMode(37, OUTPUT);
}

void loop() {
digitalWrite(37, !digitalRead(37));
delay(clockspeed);
}

Actually, would the resulting clock be going half speed? Would I need to double ‘clockspeed’ for the pulse to be in time?

I think pin 32 is getting used to do play/pause, but 37 looks free.

Yeah, I’m not sure the schematic matches the code - in the schematic both 37 and 32 look unconnected, but now I’m looking a little more closely at the code it looks like they’re both used. Maybe you could use pin 13, I think that’s connected to the onboard LED, but it shouldn’t get in the way of anything and would blink in time.

Maybe something like this in the code would do the trick, inside the if that checks if playstate is true.

int clock = tempo / 2.0;
int clock_timer = 1;
int clock_val = 0;

if (millis() - clock > clock_timer) {
  clock_val = clock_val ^ 1;
  digitalWrite(whateverpin, clock_val);
  clock_timer = millis();
}

We’re dividing the tempo by 2, so it goes twice as fast - then we’re toggling it with an XOR.

Cheers

1 Like

Thanks, that’s really helpful. I have very little coding experience, so I’m not entirely sure I can follow what your code is doing… but I will start buying parts and give it a go!

Looking over the code and schematic, I think they’ve missed the play/pause button and the play/pause indicator LED from both the schematic and stripboard. Which accounts for 32 and 37.

When I get to building it, I’ll double check all the pins line up between the code and everything else, but either way I think there’s enough to go on to figure it out.

I don’t think it’s a good idea to include any delays into the main loop, especially on a drum machine for timing, you are just asking for problems

Better to initialize a counter at the same time you set the output high and then increment the counter in the loop until it reaches a set number of ms then set the output low

I agree 32 & 37 are in use for play LED and PLAY/PAUSE

Whats wrong with using pins 0 or 1, they are normally used for MIDI or serial 1 but they don’t seem to be in use at all on this design.

He’s also wasted a ton of pins for buttons and pots etc, I would add a couple of 74HC165 shift registers and read in upto 16 buttons/switches with 3 pins instead of 16.

1 Like

Doesn’t surprise me about the schematics and code, I built his poly6 design from GitHub, it left a lot to be desired in terms of schematics and code. I’m no expert but I produce something slightly better.

1 Like

Thanks craigyb.

Just for clarity, it sounds like you’re saying don’t do my initial idea but jaradical’s code should work? Or were you suggesting a different approach entirely?

With regards to freeing up pins on the teensy, is the benefit of that being able to implement more features if I wanted, or is there a performance benefit to using fewer pins?

I didn’t like your code with delays in, never a good idea in a loop.

I’ve not studied Jaradicals code, maybe it will work.

I have just implemented a clock LED and output from an incoming midi clock and basically I turn the light on when I see a clock message and then count in millisec and when its greater than 40ms I turn it off again. Of course I count 24 clock cycles each time to cope with the 24PPQN before each light on event.

As for freeing up pins, of course you dont need to in this design as 0, 1 and 13 are available, but if you needed more options in the future then a shift register can give you lots and lots of inputs or outputs depending on what type are used with 3 wires per inputs or outputs. I use the RoxMux library to support inputs and outputs.

1 Like

Thanks, that makes sense

I would also like to mention that his schematic is very poor, he puts VCC on some switches, but no mention of VCC as a source and on a Teensy 4.1 VCC would be the 3.3V pin, not 5V. Als the pots pins 1 & 3 are just floating in mid air and are 100K in value, obviously they connect between 0v and VCC 3.3V which he does note at the top of the diagram, but its not super clear and the value should really be 10K lin for a Teensy, not super important, but recommended. He then says except the tempo knob, well how does the tempo knob connect, I presume he means that there are some resistors possibly from the legs to VCC and ground but he doesn’t show them or state values.

Also, not 100% sure about this, but some of the pots don’t match their numbers in the schematics

A9 and A10 seem reversed, A9 is HH tone and A10 is reverb.

A15 is shown as delay time, but is coded as Swing and no mention of swing.

Delay time actually reads A0 the tempo knob

1 Like

Hmm ok. Thanks for the heads up.

It’s almost exactly what I was looking for in terms of a drum machine to go alongside my modular.

I’ll have a think whether it’s worth what sounds like quite a lot of working out or if I look elsewhere.

The released version of this, the crum drum, looks great but it a bit too much money for me at the minute. There’s also a few complaints about power supply noise which has put me off a little…

Ok, the tempo pot is connected in reverse, top to ground, bottom to vcc, but he could have just mapped that…

tempo = map(tempo, 0, 1023, 1023, 0);

Would have reversed the value easily enough.

It seems the crum drum is a slightly more polished version with clock out and in, also it has a DAW connection which suggests it supports usbMIDI.