Euclidean Polyrhythm generator - code and details

From circuitbending to homebrew stompboxes & synths, keep the DIY spirit alive!

Moderators: Kent, Joe., luketeaford, lisa

Post Reply
User avatar
mmelnick
No melody, no harmony
Posts: 1051
Joined: Fri Oct 02, 2009 12:22 pm
Location: Springfield Gardens NYC

Post by mmelnick » Thu Aug 23, 2012 10:34 pm

This looks really cool, and I see it says "in stock" at Analoguehaven. has anyone bought one yet or tried it out? Any opinions or things to say about it? Just curious. I might get one!
matthewmelnick.com
metrono.me
bloodofazombie.com
darksidenyc.com
myworld.ebay.com/brooklyn_collectables

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Fri Feb 07, 2014 7:07 am

Necro-thread resuscitation!


I cleaned up Tombola's code a bit and imported a much better encoder-reading library. Now the encoders work great! I also made a schematic and included much-needed diode input-protection.

This is a cheap and relatively easy little project.

EDIT: Offset added. New info below.



To recap:


$1.80 USD - LED Matrix
$2.88 USD - Arduino Nano with USB
$3-6 USD - 3x EC11 Encoders with switches

http://www.ebay.com/itm/Nano-V3-0-ATmeg ... 5b09753d75

http://www.ebay.com/itm/5PCS-Rotary-enc ... 2a39ab4040


The rest I recommend ordering from Tayda for about $5:

- 6x 5.1V Zener diodes (protects inputs by limiting voltages both over and under 0-5V)
- 6x 200 Ohm resistors (one for each input/output)
- 6x Jacks (4 gates outs, 1 clock in, reset in)
- SPST button (if you want a reset switch)
- 4x 15k resistors

Extras: There's a possibility of adding another 4 analog/digital ins for future CV/gate usage. for CV control, I recommend using 2x 1N5819's per CV input. I'll draw a schematic for that later.

And here are the latest files:

http://sneak-thief.com/modular/Tombola_ ... n_v0.5.zip

(Arduino sketch, LED & Midi libraries & schematic)

Notes:

- I included a modified LED library in case you have an LED-matrix which runs backwards.

- Tombola's code doesn't always recall the flash memory properly when rebooted

- These two libraries are needed and included in my zip:

- LedControl
http://playground.arduino.cc/Main/LedControl

- Encoder
http://www.pjrc.com/teensy/td_libs_Encoder.html

Image

Image
Last edited by sneak-thief on Thu May 28, 2015 8:22 am, edited 5 times in total.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Fri Feb 07, 2014 7:22 am

When the rhythms are playing, the display flips between page 1 (steps 1-8) and page 2 (steps 9-16).

Here's what the display shows...

Row 1: What step is Output 1 playing
Row 2: Output 1 Pattern (steps 1-8 or 9-16)

Row 3: What step is Output 2 playing
Row 4: Output 2 Pattern (steps 1-8 or 9-16)

Row 5: What step is Output 3 playing
Row 6: Output 3 Pattern (steps 1-8 or 9-16)

Row 7: Which channel is selected

- 2 dots on the left for Channel 1
- 2 dots in the middle for Channel 2
- 2 dots on the right for Channel 3


Row 8: Current triggers

1. Input trigger
2. -
3. Output 1 trigger
4. Output 1 off-beat trigger (all the steps when Output 1 isn't playing)
5. Output 2 trigger
6. -
7. Output 3 trigger
8. -


* When you have Channel 1 selected and you rotate the N- and K-knobs, Rows 1 and 2 will respectively show the pattern length (N) or pattern density (K).

The same goes for Channel 2 (Rows 3 and 4) and Channel 3 (Rows 5 and 6)
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

Jarno
Super Deluxe Wiggler
Posts: 2794
Joined: Mon Nov 15, 2010 6:34 am
Location: Rosmalen, NL

Post by Jarno » Fri Feb 07, 2014 8:59 am

Ace!
I have a couple of nano's gathering dust, this will be perfect. Only need to get the display and a couple of encoders.

:tu:

User avatar
Spandex
Lovely cloakroom, lovely cloaks
Posts: 245
Joined: Sun Oct 16, 2011 7:48 am
Location: Nottingham, UK

Post by Spandex » Fri Feb 07, 2014 10:05 am

Nice work :)

Did you use analogRead because the digital pins were used up with the matrix/encoders? What sort of speed do you get?

I read somewhere that you can significantly increase the speed of analogRead by setting a the prescale register. The trade off is that you lose accuracy but if you're only using them for pulse detection, that shouldn't matter.
http://forum.arduino.cc/index.php/topic,6549.0.html

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Fri Feb 07, 2014 10:08 am

BTW, it'd be ridiculously easy to add midi-out to this: 1 220Ohm resistor and a DIN jack.

Add the midi library and embed a midi-note send for each pulse and it's done.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Fri Feb 07, 2014 10:22 am

Spandex wrote:Nice work :)

Did you use analogRead because the digital pins were used up with the matrix/encoders? What sort of speed do you get?

I read somewhere that you can significantly increase the speed of analogRead by setting a the prescale register. The trade off is that you lose accuracy but if you're only using them for pulse detection, that shouldn't matter.
http://forum.arduino.cc/index.php/topic,6549.0.html
1. Thanks for the link! I didn't do much speed-testing - it seems to go into low-audio rate (~120Hz) but I'm not that interested given this particular application.

Tombola originally mapped that analog pin to the trigger input. I guess it seemed logical to him at the time, since as you mentioned all the digital pins were taken.

However, just for kicks I put the CS (aka Load) pin for the MAX7219 LED matrix to Analog 5 and it works fine. I just put this the setup:

pinMode(A5, OUTPUT);

That means if the digital input is more reliable/faster, that it can be used instead of the analog input that Tombola chose for the trigger :)


2. I noticed the occasional missed trigger that he mentioned, so I tried to reconfigure the analog pin as a digital pin:
// Sync toggle routine
int synctoggle=0;
pinMode(A2, INPUT);



if((digitalRead(A2)==HIGH) && (synctoggle == 0)) {
Sync();
synctoggle=1;
}

if((digitalRead(A2)==LOW) && (synctoggle == 1)) {
synctoggle=0;
}

This gave me the same results. However, once I used a better encoder-reader, those missed-trigger problems went away (for now) so it's still using analogRead on the A2 pin for the trigger input.


3. Future enhancements:

- There are four leftover analog pins that could be used for CV control. I'm not sure what would be the best use of these pins: you could have 3 CV-ins controlling N, K and offset of one channel... or N/K of each channel. Hard to say yet.

- The reset pin can be shared with a trigger input using the same diode-protection from the schematic.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
oberkorn
Veteran Wiggler
Posts: 629
Joined: Tue Jan 18, 2011 6:30 am
Location: Sverige
Contact:

Post by oberkorn » Sat Feb 08, 2014 8:01 am

wow. nice work indeed
I'll have a second look at this project soon I think
you have to pay for the music but the noise is free

User avatar
aladan
Desperately Seeking Sondra
Posts: 551
Joined: Tue Feb 14, 2012 12:52 am
Location: Adelaide, Australia

Post by aladan » Sat Feb 08, 2014 8:07 am

sneak-thief wrote:Necro-thread resuscitation!


I cleaned up Tombola's code a bit and imported a much better encoder-reading library. Now the encoders work great! I also made a schematic and included much-needed diode input-protection.

The rhythm offset function still hasn't been implemented, ie. being able rotate a rhythm pattern forward or backward. Anybody want to give it a try?

It's a pretty cheap experiment:

- Arduino Nano 3.0: $7.50 USD
http://www.ebay.com/sch/?_nkw=arduino%2 ... 3539516696

- LED Matrix: $3.37 USD
http://www.ebay.com/itm/400373209766?ss ... 1439.l2649

....
Thanks for this post, sneak-thief. I didn't realise how cheap and easy this module would be to build; just hit the buy button on all the parts and now really looking forward to it!

:tu:

Cheers,
A.

User avatar
NS4W
Super Deluxe Wiggler
Posts: 1233
Joined: Thu Jan 12, 2012 11:42 am

Post by NS4W » Sat Feb 08, 2014 8:32 am

Somebody should make a kit for this project...

User avatar
KnobHell
Super Deluxe Wiggler
Posts: 1129
Joined: Sat Jan 28, 2012 3:00 pm
Location: SLC

Post by KnobHell » Sun Feb 09, 2014 12:03 am

Search for the trigger happy project we did in DIY.

You'll want to make your input and outputs tolerant to voltages over 5 volts. I also did away with the arduino board and went straight to a 328p to cut down on the cost.

Everything is documented on the tread.

Len
Misspelling: brought to you by autocorrect.

The KnobHell Website

KnobHell Soundcloud

KnobHell Youtube Channel

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Sun Feb 09, 2014 1:30 am

KnobHell - thanks for the suggestion.

For anyone that wants to go the super-safe route, please refer to the Trigger Happy ins and outs:

http://knobhell.com/TriggerHappy/main.pdf


That said, didn't you see the diode clamp I added on the input? As for the outputs, this is the diy-wild west. I'll let someone else take it from here ;)

Yes, an op-amp input buffer is the best, but in my 9 years of experience building diy synths and microcontroller units that interface with it, diodes have never let me down.

You can always substitute the regular silicon diodes for 1N5819 Shottky diodes if you want an even faster clamp.

Here's a spice simulation that shows what I'm talking about:

http://www.eevblog.com/forum/projects/p ... a#msg21840
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
KnobHell
Super Deluxe Wiggler
Posts: 1129
Joined: Sat Jan 28, 2012 3:00 pm
Location: SLC

Post by KnobHell » Mon Feb 10, 2014 11:22 pm

Yep, saw the diodes.

You may also want to limit the current on the outputs to to protect them from dead shorts.

I'm just sort of a traditionalist when it comes to my engineering.. :despair:
Misspelling: brought to you by autocorrect.

The KnobHell Website

KnobHell Soundcloud

KnobHell Youtube Channel

User avatar
ABC
Common Wiggler
Posts: 146
Joined: Fri Jun 29, 2012 7:35 pm
Location: The Street, Metaverse

Post by ABC » Fri Feb 14, 2014 7:28 am

This is exactly what I've been looking for. Did this ever get made as a kit/gain supplemental documentation?
bewilderbeast.bandcamp.com

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Fri Feb 14, 2014 7:30 am

There is no kit.

The supplemental documentation is in my two posts:

viewtopic.php?p=1451228#1451228

viewtopic.php?p=1451244#1451244

The pattern +/- offset is not yet implemented in software. It would be great if someone could help out and add it to the code. I'm too busy right now.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
mono-poly
Le Cheff
Posts: 5423
Joined: Fri Nov 21, 2008 3:40 pm
Location: Rotterdam, Netherlands

Post by mono-poly » Sat Jun 21, 2014 9:48 am

Anyone got a clue where i can order the right encoders?
In europe please.
Maybe Conrad?
The farad is the captain of my print.

http://www.mono-poly.nl
http://www.noodlebar.org

WTB blue lantern purple vco

User avatar
mono-poly
Le Cheff
Posts: 5423
Joined: Fri Nov 21, 2008 3:40 pm
Location: Rotterdam, Netherlands

Post by mono-poly » Sat Jun 21, 2014 10:00 am

The farad is the captain of my print.

http://www.mono-poly.nl
http://www.noodlebar.org

WTB blue lantern purple vco

User avatar
oberkorn
Veteran Wiggler
Posts: 629
Joined: Tue Jan 18, 2011 6:30 am
Location: Sverige
Contact:

Post by oberkorn » Fri Jul 18, 2014 8:57 am

re-ressurecting the thread; have all the parts except the encoders, can't find "ALPS ENC11" anywhere, only EC11E, not sure if its the same part,
also where do I get the small chicklet PCBs used on the encoders in the pic?
:help: :despair:
you have to pay for the music but the noise is free

lnn
Learning to Wiggle
Posts: 12
Joined: Wed May 14, 2014 10:37 am

Post by lnn » Sun Jul 27, 2014 8:40 am

sneak-thief, Did you embed the pattern offset already? If not I can help, will receive my parts in two weeks. Will probably extend it with midi as well, since I'm not a modular guy (yet). How about dumping this on github (gists?) to make contributions easier?

BTW First post!

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Sun Jul 27, 2014 11:43 am

1. lnn: No, I haven't got around to adding the offset to the code yet :S So nice first post - that's the DIY spirit :)

I don't have any time to dump this on github yet so feel free if you like!

Adding MIDI should be ridiculously easy using the MIDIbus Arduino library.


2. The difference between Alps EC11 and EC12 refers only to the housing:

http://www.soselectronic.com/?str=676

They're both usually either 12 or 24 pulses/detents per 360 degree rotation.

Make sure to get an encoder with a switch as it will save you space on the front panel.


3. The Alps pots in my pictures were from eBay and are an automotive version came with the pcb attached to it.


4. NOTE: LED matrixes seem to come in 2 versions. I think you can only tell after you plug it in!

Mine goes left to right when oriented with the chip on the right - but Tombola's goes left to right with the chip on the bottom.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

lnn
Learning to Wiggle
Posts: 12
Joined: Wed May 14, 2014 10:37 am

Post by lnn » Sun Jul 27, 2014 3:20 pm

sneak-thief Ok will see what I can do. Haven't done C/embedded/imperative programming for a while, but guess I'll manage. Will make a Github repo.

I've been amazed by Polyrhythmus (check the video) recently and would like to make a sort of hardware equivalent.

User avatar
Barcode
Ultra Wiggler
Posts: 843
Joined: Sun Nov 20, 2011 12:12 pm
Location: The Wasatch Front

Post by Barcode » Sun Jul 27, 2014 5:12 pm

I totally forgot about this project. Just picked up the parts to build 2 of these for about $20.00. :tu:

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Tue Jan 27, 2015 5:04 am

I'm trying to take a crack at adding Offset to this affordable little project.

The three (up to) 16-step euclidean patterns are stored as single concatenated bytes.

I just want to be able to offset the patterns up to 15 positions, eg:
0 offset:
1001100000000100

1 offset:
0100110000000010

2 offset:
0010011000000001

...

15 offset:
001100000000101
What's the best way to bitshift (rotate) to the right in Arduino?

This is the code that generates the Euclidean patterns:

http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

User avatar
mxmxmx
Super Deluxe Wiggler
Posts: 2243
Joined: Thu May 31, 2012 1:54 am
Location: berlin

Post by mxmxmx » Tue Jan 27, 2015 6:16 am

not sure about the best way, but something along these lines should do? (more or less ... *)
uint16_t shift(uint8_t _s, uint16_t _data) { // rotate by _s

uint16_t tmp = _data << _s;
tmp = tmp | (_data >> (0x10 -_s));
return tmp;
}

* ... well, this shifts to the left, you'd just have to flip around the shift operators.


fwiw, though i haven't seen any formal proofs, this is supposed to be equivalent to the more common kind of algorithms (CLK_COUNTER just counts a/the/some clock signal ... ):


uint8_t _euclid(uint8_t _n, uint8_t _k, uint8_t _offset) {

uint8_t _out;

if (_k >= _n ) _k = _n - 1;
_out = ((CLK_COUNTER + _offset) * _k) % _n;

return = (_out < _k) ? 1 : 0;

}

User avatar
sneak-thief
Ultra Wiggler
Posts: 970
Joined: Sun Feb 20, 2011 11:13 am
Location: Berlin

Post by sneak-thief » Tue Jan 27, 2015 7:32 am

I tried the first example and this is what it's giving me:
1000010000100000 - Original 16-step pattern
100001000001 - Offset 1
1000010000010 - Offset 2
10000100000100 - Offset 3
100001000001000 - Offset 4


The other issue is dealing with patterns that are less than 16 bits when the pattern length is reduced :-/

Here's what that code does with an 8-step pattern:
10001000 - Original 8-step Pattern
100010000 - Offset 1
1000100000 - Offset 2
10001000000 - Offset 3
100010000000 - Offset 4

The classic rotate-right algorithm seems to be this but it's giving me weird results:

unsigned int rightRotate(int shift, unsigned int value) {
return (value >> shift) | (value << (sizeof(value) * 16 - shift));
}


1000010000100000 - Original 16-step Pattern
100001000010000 - Offset 1
10000100001000 - Offset 2
1000010000100 - Offset 3
100001000010 - Offset 4
...it also doesn't make a difference if I use "uint16_t rightRotate(int shift, uint16_t value)" instead.
http://involucija.org - post-industrial euphoric deprogramming. LP coming soon on a+w.

Post Reply

Return to “Music Tech DIY”