Hagiwo 6ch drum sequencer + 4x4 matrix keypad

Hi everyone! This is my first post on this forum, a couple of months ago I started to build diy modules and including a module from @Hagiwo (https://note.com/solder_state/n/n17c69afd484d), but I found it very uncomfortable to control (personally for me, no offense to Hagiwo), and I decided to try to add a matrix keyboard to control the steps of the sequences, I’m happy to report that I got it! I am not an expert in programming, but I have some basic knowledge, the code works stably and no problems are observed, but the code itself may be written incorrectly, that’s why I turn to this forum).

Friends, let’s make an effort together to finalize the code of this module, so that our community has a simple, convenient, and most importantly Cheap trigger sequencer for our drum modules!

Here are my ideas for finalizing this project:

  1. remove some functionality (AUTO mode) to make room for other functionality.
  2. Add Fill mode in MANUAL mode
  3. Make it possible to store/save patterns written in MANUAL mode.
  4. Add a live performance mode (so that you can mute individual channels from the keyboard and play some effects like fill or random steps).

Also on the arduino nano pins A6 and A7 are left unused, they can be used for example for buttons “FUNC” or “LIVE” or “RESET”.

Hagiwo code: https://note.com/solder_state/n/n17c69afd484d
MY sourse code: GitHub - Kozak-derezak00/drum_trig_seq_6ch: in this project is a module 6 channel trig sequencer from Hagiwo, but with the addition of me matrix keyboard 4x4 to control the steps of the sequences, the code is very raw and not attractive but WORKABLE, sketch uses 97% of the resource arduino nano.

6 Likes

4 Likes

ive got me some of these button matrices, thats a neat use case :slight_smile:

1 Like

Let me start by saying that you should not be discouraged by the suggestions I’m going to make here. As a long time programmer who at one point in time also wrote his first program, I know that ones early programs are not ones best. So, keep on going, you can learn a lot by doing and by looking at code written by others.

There are large sections with IF statements that are almost repetitions of one another. By this I mean there is a lot of code that is repeated although the code contains only small changes.

The repeated code can be simplified by using a loop or a combination of a table and a loop where all of these small changes are built into one or more variable. Let me give an example of using a loop. If you look at this bit of code (this is only an extract):

if (bitRead(ch1_step, 15 ) == 1) {
     display.print("*");
   }
   else {
     display.print("_");
   }

   if (bitRead(ch1_step, 14 ) == 1) {
     display.print("*");
   }
   else {
     display.print("_");
   }

   if (bitRead(ch1_step, 13 ) == 1) {
     display.print("*");
   }
   else {
     display.print("_");
   }

This “if-else” is repeated 15 times and can be reduced to 6 lines using a for loop:

for (byte stepNr = 15; stepNr >= 0; stepNr--) {
  if (bitRead(ch1_step, stepNr) == 1 {
   display.print("*"); 
 } else {
   display.print("_"); 
}

The variable stepNr will change with every cycle of the loop and therefore all 16 individual if-statements are executed as they were in the original code.

But there is one more step you can make here.
Since in the present code this section is repeated for ch1_step up until ch6_step, you can add another loop, an outer loop, which loops over chX_step, like this:

for (int chStep = 1; chStep < 6; chStep++) {
  for (byte stepNr = 15; stepNr >= 0; stepNr--) {
    if (bitRead(ch1_step, stepNr) == 1 {
     display.print("*"); 
   } else {
     display.print("_"); 
  }
}

Please check that the start and end conditions of both loops correspond to your code. I’ve not checked this. I merely want to illustrate the use of the 2 loops here.

In this way the number of lines of code is reduced quite a bit. The thing that often occurs when copying code parts and locally adapting them is that one is prone to introduce errors which van be hard to spot. Given that we now have 8 lines in stead of more than 100 (for this part), the odds of introducing an error that you will not be able to spot easily are much smaller. Furthermore, the code is simpler to read, easier to debug and to expand.

There are multiple parts of the code that could benefit from a looping-approach like this.
You will find that you can free up quite a bit of memory once you apply this method and it make your code easier to read.

7 Likes

this looks awesome and after building the original, a very welcome addition!

The one I built is from GitHub - mzuelch/CATs-Eurosynth: Analog Synth Eurorack Modules which also includes schematic and kicad files so it should be pretty simple to add your modification to his version. I may give that a go after the hols.

2 Likes

Built the original but I think there’s something fishy going on. If I power it off USB the display structure looks fine except that every single step is filled with a star (*). Is it supposed to boot like this?

Then if I plug this into my case’s 5V supply things get really erratic but that might be more of a solder issue somewhere. Or would there be any other reason why this works from USB but not directly from 5V input pin?

Are you connecting your +5 V supply to the VIN pin or the 5V pin? Should be the latter. If you were using the +12 V supply it’d be VIN, where the onboard regulator would convert it to +5 V, which would be available at the 5V pin; but the regulator needs at least about +7 V. Alternatively a regulated +5 V supply can be connected to the 5V pin.

If that is what you’re doing then it should work the same as with USB power.

1 Like

Did some resoldering here and there and got this working for a couple of clock pulses until it froze completely. When switching the 5v power off and on again I noticed that Nano’s onboard led kept blinking and some current was even flowing to my panel led as it was also blinking dimly when there was no 5v power applied. After that I soldered another bat43 diode on the +5v line as polarity protection and now this seems to work.

I used the 5V pin all the way but now this got me thinking if that was why I never got the big button to work properly.

I also made the Hagiwo 6 channel gate sequencer. I believe the 6 channel gate sequencer and the euclidean sequencer are the same, in terms of the hardware. But i have another thing/issue with the first one. It sometimes will not start when powering on the rack. After a while, can be 1 week of even 1 month, when powering on my rack, the oled display shows nothing. So when uploading the sketch again everything works like before. Does anyone have encountered this behaviour? Apperantly the arduino nano loses its programming.

1 Like

Is there a digital pin floating (fix in code), the reset button manky (clean and check solder joint) or memory is fecked (replace the whole microcontroller).

Maybe try a reset and clear?

2 Likes

Replaced the whole nano for a new one. Reset only resets the start position during playback. It does not erase my own programming (thats what i expected), so reset switch probably ok, i can check the code once more for floating pins.

Anyway, this is how i set things up. Why stressing the voltage regulator with 12v which is the max input voltage? I used an 9v regulator connected to the VIN pin of the Arduino Nano.

Then for the outputs from the Nano, i didnt had bat43 diodes. Instead of using the 470 ohms resistors and clamping diodes, for each output i used 1n4148 diodes connected to the non-inverting inputs of an tl74 and tl072 so that the signals are buffered. Lastly connected 1k resistors to the opamps outputs for protection

1 Like

Hi Jos,

If its ok with you i like to volunteer for making the Hagiwo code better (with respect for Hagiwo) to make these changes as per you provided. Making the if else lines shorter and compacter. Can i just copy and paste and make the nessesary changes?

1 Like

Could it be a connection or display issue? I’d check your jumpers to the display.

2 Likes

Oh, no problem, go ahead.

1 Like

Hi JaggedNZ. It could be but i guess not because if it was only the display, my drum modules would keep on playing right?. When this outtage happens, the whole module does not start (can not see the Arduino’s led’s).

Next time when this happens i will connect the module outside my rack and power it up to see if there is any activity on the Arduino. Maybe this way is can narrow down the cause.

For now i have solved it by uploading the sketch to a brandnew Arduino. Lets see when things occurs again.:+1:

Ok i have some spare time left so i will dig in and i will upload the code here for anyone who wants to have it. In the meantime, if there are any improvements or nice additions to have just let me know.

Is there a list of new features that could be implemented to this gate sequencer? Adding more patterns or fills? Can the reset button be used to trigger fills? Can each channel be converted to midi channels so that you can route it back to your DAW? That sort of things.

1 Like

And it happened again just now!

Hagiwo’s gate sequencer does not start, oled display stays pitch black. So i build out the module and at that point the POW led only stays on.

Then when i pressed the reset button. All lights started to flicker. RX, TX, and L (except POW)

Wtf? What could possibly causing this? How can it work like for weeks and then suddenly it does not. Its not logical to me at least. There is something happening during boot or something that it loses its programming. So after uploading the sketch everything works like it should so this basically rules out any shorts or broken components (i think).

Windows is really starting to PISS ME OFF!!

Restart over and over again, restarting IDE over and over. Its fckg 2025!!

ARDUINO NANO FOUND ON COM6

Still throwing me errors….

I have contacted my supplier. Apperantly i had a batch of 5 and 3 of them where broke. I think im gonna replace all my nano’s into expensive original ones instead of cheapy ass clones. They just suck (sorry for my language here) but come on..

1 Like

This is what I like to call the Temu tax.

2 Likes

Nanos are known to be a pain in the arse, so many dodgy versions of Nano, 8mhz, 16mhz etc, Chinese interface chips, I very rarely use a Nano if I can help it. One of my Hagiwo builds fails to start now and then.

2 Likes

I’ve had similar issues but mostly solved with a dedicated IDE in a virtual Linux pc. I had several versions of this setup and then switched to running Platform IO on visual studio which handles version control and hardware changes with ease. I’ve seen board tester code for the Uno and Leonardo; perhaps there’s one for the nano?

Ultimately it was the nano issues that lured me to the ESP32 and Pico.

1 Like