0

Neotrellis M4 Express Sixteen Step Sequencer Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Sat Aug 24, 2019 6:14 am

Hello Adafruit,

I recently purchased a Neotrellis M4 Express Kit and have run into an issue that I can't seem to figure out. I reached out on the Adafruit discord server for help and spoke with a community moderator/circuitpythonista named jerryn#2399 who was able to reproduce my problem, yet has no idea what is wrong. They recommended I post to this forum for assistance.

I'll try to include as much information as I can to be helpful. You can skip to the bottom if it seems like too much.

When I first got it, I followed the Adafruit Neotrellis M4 Express Overview and proceeded to setup the Arduino IDE first. I loaded some of the test codes. I particularly liked the Sixteen-Step Sequencer/Sampler. I played around with this for awhile and used the mic to record some samples of my voice.

Then, I set up circuit python by just double clicking the reset button and dragging adafruit-circuitpython-trellis_m4_express-en_US-4.1.0.uf2 onto the board in bootloader mode. Next, I unzipped the neotrellis_m4_default_files.zip and put the contents on the CIRCUITPY drive.

I messed around with the drum machine demo for awhile. This is where things maybe went wrong. I exported 1 or 2 of my own clips as .wav files from Audacity in stereo at 22KHz (although I'm not sure if they were 16-bit uncompressed) and renamed them voice01.wav and voice02.wav. Then I replaced the voice01.wav and voice02.wav that were on the CIRCUITPY drive with them and it reloaded the code instantly. The new sounds worked and I was pretty stoked.

Later, I reloaded the sixteen step sequencer (by way of .uf2 file/bootloader, not arduino IDE upload) and started playing with it.
This is where my problem lies. Now, all of the first "built in" samples work fine, but when I go into "write mode", hold the "sound select" button and press sample1(button9), it makes this terrible noise and continues until I unplug the neotrellis.

If I had to describe the noise, it sounds like it tries to run through and play every sound that has ever been on the board until they all start playing on top of one another and it gets really distorted until it sounds like you're listening to a phone line while it's trying to connect to a dial up internet connection. It gets so awful you just have to unplug it. If you don't, it just keeps playing sounds seemingly randomly forever.

There's a question in the FAQ/Troubleshooting section of the sixteen step sequencer guide I was following that seems to describe this exact issue. The recommended fix was to load circuit python on the board and delete any .wav files in the CIRCUITPY drive. I did this and the problem persists.

Since then, I have tried everything I can think of: reloading the arduino sketch, updating the bootloader, updating circuit python, updating arduino libraries, and recording new sounds over the mess while using the actual sketch(didn't work).

Jerryn recommended that I access the REPL via a terminal session and type:

import storage
storage.erase_filesystem()

which rebooted. I then opened the bootloader and put the sequencer back on and it STILL HAPPENS!

If I had to take a stab at what's going on, I think the sampler in the sketch is storing recording/samples in some place that I don't know how to access (not in the CIRCUITPY drive) but somewhere where some of my circuit python programs are also trying to store clips, and they're getting all mixed up. I think it's storing stuff in a variable called uint32_t or uint_8t or something in the QSPI flash memory. I found a few sketches that are supposed to wipe this memory, but I think they were written for M0 boards or something because I couldn't get one to work.

Anyway, if anyone is still reading, I would be thrilled, if you could give me some suggestions. I just want to make some beepy music and this is driving me crazy.

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by siddacious on Sun Aug 25, 2019 2:33 pm

Hi, just a heads up, I moved this post to the "Other Products from Adafruit" forum because it seems like it's an issue with the arduino sketch, not CircuitPython.

I'll forward this post to someone who should be able to better help you debug what the issue is.

siddacious
 
Posts: 126
Joined: Fri Apr 21, 2017 3:09 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit2 on Sun Aug 25, 2019 3:32 pm

hiya to clarify: the sampler code is in arduino - not circuitpython - was written a while ago and uses the *raw* chip to write/read data, it *doesnt* use the filesystem or files. so you wont be able to export/save waves to the QSPI flash and then use them within this project

adafruit2
Site Admin
 
Posts: 18652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Thu Aug 29, 2019 2:31 am

Hi, thanks for taking the time to answer this post. Unfortunately, I'm still having this issue. I am aware that the sampler code is in arduino and not circuit python. I'd like to clarify that I'm not trying "to export/save waves to the QSPI flash and then use them within this project". I apologize if it sounded that way. I was just trying to include information about everything that I have done with the board so far, although, I may have just overly complicated my original post. I'll try again.

All I am trying to do, is simply restore the sixteen step sequencer program to it's original functionality, without these noises saved onto buttons 9 - 16. Could someone please shed some light on how to erase what is saved on those buttons? Is there some way to clear/reset the "*raw*" chip?

Like I mentioned earlier, I've tried just recording new sounds to the buttons, which kind of works. Afterwards, when I "play" the button it will play the new sound, followed by every other sound that has ever been recorded in the sketch, and even some that I saved in the [https://learn.adafruit.com/trellis-m4-beat-sequencer/eight-step-simple-sequencer]Eight-Step Drummer[/url] which is really confusing/surprising.

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Thu Aug 29, 2019 5:42 am

Also, I'm not sure if this has anything to do with the issue I'm experiencing but, I was looking through the sixteen step sequencer code on github and just out of curiosity, I deleted line 55 <recorder.begin();> out of sixteen_step_sequencer.ino and re-uploaded it. It compiled ok and the whole program works except, obviously, the recording functionality. The point is, that terrible noise doesn't happen without recorder.begin().

I noticed that sampler.cpp, recorder.h, and recorder.cpp were all updated to the latest QSPI library about a month ago, while all the other code was last updated 10 months ago. Furthermore, there are a bunch of lines of code in recorder.cpp that are commented out. They all have to do with flash.eraseSector, flash.eraseBlock, etc.

Considering my problem is isolated to the recording functions, these functions were recently updated, and there are lines of code that have to do with erasing that are commented out, I don't think it's a coincidence. I feel like the answer is staring me right in the face, but I just don't know how to fix it and I could really use some guidance.

I know it seems like I'm obsessing over this, but I really liked playing with this sequencer, and I just want it to work properly again. If anyone can comment, I'd be really happy!

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit2 on Thu Aug 29, 2019 2:59 pm

it could very well be that part isnt working, we had to update the QSPI library and the original author of this code isn't at adafruit anymore so we've only been able to get basic functionality back and working.
you can always install the original UF2
https://learn.adafruit.com/trellis-m4-b ... rmware-3-4

adafruit2
Site Admin
 
Posts: 18652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by RajivPerseedoss on Tue Sep 03, 2019 6:16 am

Hi,
Have you been able to resolve this? I am having the exact same issue.

Thanks
R

RajivPerseedoss
 
Posts: 8
Joined: Thu Dec 14, 2017 5:39 am

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit2 on Tue Sep 03, 2019 12:06 pm

use the UF2 posted

adafruit2
Site Admin
 
Posts: 18652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Thu Sep 05, 2019 7:11 pm

Hey Everyone,

Rajiv, yes, I was able to resolve this issue.

First, just try the .uf2 like adafruit2 suggested. Maybe it will work. I doubt it.

If it doesn't, you need to fix the actual code. You can access it from the Sixteen-Step-Sample-Sequencer Adafruit Learn Page or directly on github here.

If you haven't already, you'll need to set up your Neotrellis M4 Express with the Arduino IDE. There's a nice guide for it here.

Also, assuming you've already got that set up, the code should already be in C:\Users\Whatever\Documents\Arduino\libraries\Adafruit_NeoTrellis_M4_Library\examples under sixteen_step_sequencer.

Once you have the IDE setup, open sixteen_step_sequencer.ino. Next, find the recorder.cpp tab (you might have to use the drop down arrow). There're a few lines of code in here that are commented out for some reason. If you delete the //'s in front of them, it should work.

On github they're lines 29, 30, 31, 34, 49 and 50. Leave 71 and 72 commented out.

This:
Code: Select all | TOGGLE FULL SIZE
//for(uint32_t i=0; i<REC_BLOCKS_PER_FILE; i++){
   //   flash.eraseBlock(BLOCK(slot*REC_FILESIZE) + i);
   //}


This:
Code: Select all | TOGGLE FULL SIZE
//flash.eraseSector(SECTOR(_currentAddr));


And this:
Code: Select all | TOGGLE FULL SIZE
  //if(_totalSize%SFLASH_SECTOR_SIZE == 0)
             //flash.eraseSector(SECTOR(_currentAddr));


And that's it! Just resave the code, it might say something about being read only and make you save it somewhere else.

If I was more tech savvy, I'd probably try to make a pull request to have them fix it on github but I'm not super familiar with how that works.
Good luck, I hope this helps.

And thanks again to all those at Adafruit who took the time to troubleshoot this with me.
Cheers!

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit2 on Thu Sep 05, 2019 7:14 pm

i dont understand why you think the uploaded/attached UF2 wouldn't work? its from a the original code :) did it not?

adafruit2
Site Admin
 
Posts: 18652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Thu Sep 05, 2019 7:27 pm

I'm not sure if you read my initial post but I tried that like 20 times. All the .uf2 does it reinstall the original code without having to use the Arduino IDE. The original code has those raw flash erase lines commented out. So the .uf2 is just a faster/more convenient way to install the same non-functioning code.

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit2 on Fri Sep 06, 2019 5:02 pm

oooh got it! ok we shall try your nifty changes! thank you :)

adafruit2
Site Admin
 
Posts: 18652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit_support_carter on Tue Sep 10, 2019 4:01 pm

Hey @Condropolis, I'm taking a look at this issue and the changes you made. To start, I've tried to recreate the original issue, but I'm not able to. Or I might not fully understand what the issue was / how to recreate it.

I tried the UF2 from the guide and it worked.

I also used Arduino and uploaded the example sketch from the NeoTrellis M4 library and it worked without modifications. Arduino IDE version is 1.8.9 and all libraries are latest versions using update through library manager. The two manually installed libraries (Audio and SdFAT) were wget'd from URLs in guide and then unzipped into Arduino lib folder.

For both uploads (UF2 and Arduino), I tried the built-in samples and they all played. I recorded something into each of the 8 record slots and they all played back OK. I then made a little sequence with a mix of built in and samples and it played OK.

Can you give me a simple way to recreate the issue? I'll try it out. Thanks.

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by Condropolis on Tue Sep 10, 2019 6:55 pm

@adafruit_support_carter

Alright, so I was able to recreate the issue through a short series of steps. I'm not sure what actually creates the issue and what might be redundant steps that don't have anything to do with it, so I'll just tell you exactly what I did.

1. Have the current/unaltered sixteen step sequencer program installed through some means (whether UF2 or IDE, I don't think it matters) and make sure you record some stuff, particularly on button 9 (the first recorded audio button slot).

2. Install the latest version of CircuitPython for this board on the Adafruit learn guide

adafruit-circuitpython-trellis_m4_express-en_US-4.1.0.uf2

3. Delete everything on the CIRCUITPY drive

4. Then download the neotrellis_m4_default_files.zip (on the same link above), unzip and drag the files onto CIRCUITPY drive to get to the default drum machine

5. Replace voice01.wav with your own sample. (drag a .wav on to the CIRCUITPY drive and rename it voice01.wav and delete the old one. Do the same with voice02.wav. I used one that I resampled in Audacity to Stereo, 22KHz, 16-bit uncompressed WAV format that was about 3 seconds for voice01 and a random sound from the Adafruit Samples sound_packs. They both worked in the drum machine program. Play with this for a minute.

6. Delete everything on the CIRCUITPY drive

7. Double click the reset button to get in bootloader mode and use the original .uf2 to install the sixteen step sequencer from the link that's mentioned earlier in this discussion by adafruit2.

8. Press the bottom left "write mode" button, then hold the "sound select" button and press "9(sample1)" button.
If you've done all this, than you should (or at least I) hear immediate higher pitched scratchy-squeally distortion for a second followed by a relatively organized string of noises that should sound very familiar one by one, then longer silence gaps with occasional noise blurts here and there until it's unplugged. I've gotten buttons 10 and 11 to do the same thing. *******This is the very best I can describe the issue.

From this stage, I simply could not get sound off of those buttons not matter how much re recording, resetting, turning off and back on, re installing, or updating I tried. If you try the .uf2 again, it still happens. If you try uploading from Arduino IDE, it still happens.
The only way I've been able to fix this is with the fix I described earlier by changing recorder.cpp from this:

Code: Select all | TOGGLE FULL SIZE
/*
 * recorder.cpp
 *
 *  Created on: Oct 23, 2018
 *      Author: dean
 */

#include <Arduino.h>
#include "recorder.h"
#include "Adafruit_SPIFlash.h"
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
Adafruit_SPIFlash flash(&flashTransport);

AudioInputAnalogStereo  Recorder::audioInput(PIN_MIC, 0);
AudioRecordQueue Recorder::queue1;
AudioConnection  patchCord1(Recorder::audioInput, 0, Recorder::queue1, 0);

void Recorder::begin()
{
  if (!flash.begin()){
   Serial.println("Could not find flash on QSPI bus!");
   __BKPT();
   while(1);
  }
}

void Recorder::startRecording(uint8_t slot)
{
   //for(uint32_t i=0; i<REC_BLOCKS_PER_FILE; i++){
   //   flash.eraseBlock(BLOCK(slot*REC_FILESIZE) + i);
   //}
   flash.eraseBlock(BLOCK(slot*REC_FILESIZE));
   _currentAddr = REC_FILESIZE*slot + SFLASH_SECTOR_SIZE;
   //flash.eraseSector(SECTOR(_currentAddr));
   _totalSize = SFLASH_SECTOR_SIZE;
   _slot = slot;
   queue1.begin();
}

void Recorder::stopRecording()
{
   queue1.end();
    while (queue1.available() > 0) {
       if(_totalSize < REC_FILESIZE - SFLASH_SECTOR_SIZE){
        flash.writeBuffer(_currentAddr, (byte*)queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*2);
        _currentAddr += AUDIO_BLOCK_SAMPLES*2;
        _totalSize += AUDIO_BLOCK_SAMPLES*2;

         //if(_totalSize%SFLASH_SECTOR_SIZE == 0)
             //flash.eraseSector(SECTOR(_currentAddr));
        if(_totalSize%SFLASH_BLOCK_SIZE == 0)
           flash.eraseBlock(BLOCK(_currentAddr));
       }
      queue1.freeBuffer();
    }
    // set the sample size
    flash.eraseSector(SECTOR(REC_FILESIZE*_slot));
    _totalSize -= SFLASH_SECTOR_SIZE;
    flash.writeBuffer((uint32_t)_slot*REC_FILESIZE, (byte*)&_totalSize, sizeof(uint32_t));
}

void Recorder::continueRecording()
{
  if (queue1.available() >= 1) {
   if(_totalSize < REC_FILESIZE - SFLASH_SECTOR_SIZE){
      //write buffer to QSPI
      flash.writeBuffer(_currentAddr, (byte*)queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*2);
      _currentAddr += AUDIO_BLOCK_SAMPLES*2;
      _totalSize += AUDIO_BLOCK_SAMPLES*2;

      //if(_totalSize%W25Q16BV_SECTORSIZE == 0)
         //flash.eraseSector(SECTOR(_currentAddr));
      if(_totalSize%SFLASH_BLOCK_SIZE == 0)
          flash.eraseBlock(BLOCK(_currentAddr));
   }

   queue1.freeBuffer();
  }
}



to this:

Code: Select all | TOGGLE FULL SIZE
/*
 * recorder.cpp
 *
 *  Created on: Oct 23, 2018
 *      Author: dean
 */

#include <Arduino.h>
#include "recorder.h"
#include "Adafruit_SPIFlash.h"
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
Adafruit_SPIFlash flash(&flashTransport);

AudioInputAnalogStereo  Recorder::audioInput(PIN_MIC, 0);
AudioRecordQueue Recorder::queue1;
AudioConnection  patchCord1(Recorder::audioInput, 0, Recorder::queue1, 0);

void Recorder::begin()
{
  if (!flash.begin()){
   Serial.println("Could not find flash on QSPI bus!");
   __BKPT();
   while(1);
  }
}

void Recorder::startRecording(uint8_t slot)
{
   for(uint32_t i=0; i<REC_BLOCKS_PER_FILE; i++){
      flash.eraseBlock(BLOCK(slot*REC_FILESIZE) + i);
   }
   flash.eraseBlock(BLOCK(slot*REC_FILESIZE));
   _currentAddr = REC_FILESIZE*slot + SFLASH_SECTOR_SIZE;
   flash.eraseSector(SECTOR(_currentAddr));
   _totalSize = SFLASH_SECTOR_SIZE;
   _slot = slot;
   queue1.begin();
}

void Recorder::stopRecording()
{
   queue1.end();
    while (queue1.available() > 0) {
       if(_totalSize < REC_FILESIZE - SFLASH_SECTOR_SIZE){
        flash.writeBuffer(_currentAddr, (byte*)queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*2);
        _currentAddr += AUDIO_BLOCK_SAMPLES*2;
        _totalSize += AUDIO_BLOCK_SAMPLES*2;

         if(_totalSize%SFLASH_SECTOR_SIZE == 0)
             flash.eraseSector(SECTOR(_currentAddr));
        if(_totalSize%SFLASH_BLOCK_SIZE == 0)
           flash.eraseBlock(BLOCK(_currentAddr));
       }
      queue1.freeBuffer();
    }
    // set the sample size
    flash.eraseSector(SECTOR(REC_FILESIZE*_slot));
    _totalSize -= SFLASH_SECTOR_SIZE;
    flash.writeBuffer((uint32_t)_slot*REC_FILESIZE, (byte*)&_totalSize, sizeof(uint32_t));
}

void Recorder::continueRecording()
{
  if (queue1.available() >= 1) {
   if(_totalSize < REC_FILESIZE - SFLASH_SECTOR_SIZE){
      //write buffer to QSPI
      flash.writeBuffer(_currentAddr, (byte*)queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*2);
      _currentAddr += AUDIO_BLOCK_SAMPLES*2;
      _totalSize += AUDIO_BLOCK_SAMPLES*2;

      //if(_totalSize%W25Q16BV_SECTORSIZE == 0)
         //flash.eraseSector(SECTOR(_currentAddr));
      if(_totalSize%SFLASH_BLOCK_SIZE == 0)
          flash.eraseBlock(BLOCK(_currentAddr));
   }

   queue1.freeBuffer();
  }
}


When I first loaded this altered sketch, it still makes the terrible noise the first time you try the button again, only now, when you record over it, it actually deletes any other audio assigned to the button and just records like it's supposed to.
I hope this post is more clear.

Condropolis
 
Posts: 6
Joined: Fri Aug 23, 2019 4:55 pm

Re: Neotrellis M4 Express Sixteen Step Sequencer Issue

by adafruit_support_carter on Tue Sep 10, 2019 8:07 pm

Thanks for all that info. I was able to recreate the issue. I think I see what might be going on. The filesystem is being altered by CircuitPython and then when you switch back to the Arduino sequencer it's not in a clean state. So when you try to play the recorded track, things get wonky.

The key is to re-record the track which essentially cleans up what's on the filesystem w.r.t. that track.

For Step 7, what if you use the Arduino sketch instead of the UF2, and use it as is with the commented out lines. And then make sure to re-record the track first before playing it back. That seemed to work for me. Both your version and the original essentially worked.

The trick seems to be to *not* jump straight into a playback after switching from CircuitPython back to the Arduino sketch.

Also, just to make sure, this is only an issue when cycling between CircuitPython and Arduino?

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.