sensorium / Mozzi

sound synthesis library for Arduino
https://sensorium.github.io/Mozzi/
GNU Lesser General Public License v2.1
1.09k stars 187 forks source link

Compatability/Compilation Issues w/ Nano 33 BLE Sense #216

Open sacerd-OS opened 11 months ago

sacerd-OS commented 11 months ago

Board: Nano 33 BLE Sense Version: GitHub Latest Steps to Reproduce: Attempt to compile empty sketch onto Nano 33 BLE Sense with MozziGuts.h included

The issue seems to stem from the fact that Mozzi considers the Nano 33 BLE Sense to be of the MBED family (I don't know what this means so I can't interpret). In AudioConfigMBED.h, Mozzi therefore assumes the 33 BLE Sense is compatable with the Arduino AdvancedAnalog library, which it isn't and assumes the board has a pin A13 which it doesn't.

The result is failed compilation and what seems to be a bunch of issues related to the AdvancedAnalog library. Unfortunately this isn't my jam so I can't help fix.

tomcombriat commented 11 months ago

Related: #200 .

Is this the same board actually? I don't have one of these, but will try to have a quick look at some point (or someone else). Thanks for reporting!

sacerd-OS commented 11 months ago

Not my wheelhouse, but they don't appear to be the same. The sense is based on nRF52840 and the IOT is based on the SAMD21. The pin layouts seem different, at least. It seems to be in the mbed class of Arduinos, with its own separate listing as mbed_nano for compatability checks.

tfry-git commented 11 months ago

IIRC, the Nano 33 BLE used to work before we added the MBED port (for Arduino Giga/Portenta). Probably it's simply and over-eager hardware detection inside hardware_defines.h, then. Could you try modifiying that file? If you change this line https://github.com/sensorium/Mozzi/blob/cf9e173cd181f2a893f31923aaa0f2ec8e39efbc/hardware_defines.h#L59C6-L59C30 to #if (0), do things work?

If so, at least, we know what's going on, and just need to adjust that define.

sacerd-OS commented 11 months ago

IIRC, the Nano 33 BLE used to work before we added the MBED port (for Arduino Giga/Portenta). Probably it's simply and over-eager hardware detection inside hardware_defines.h, then. Could you try modifiying that file? If you change this line https://github.com/sensorium/Mozzi/blob/cf9e173cd181f2a893f31923aaa0f2ec8e39efbc/hardware_defines.h#L59C6-L59C30 to #if (0), do things work?

If so, at least, we know what's going on, and just need to adjust that define.

I get a different error, unfortunately

.../Mozzi/MozziGuts_impl_STM32duino.hpp:13:10: fatal error: HardwareTimer.h: No such file or directory

include "HardwareTimer.h"

     ^~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Compilation error: exit status 1

On version 1.10 I get an error that I'm missing (hardware_defines.h line 52), so it wasn't working on that version either.

tfry-git commented 10 months ago

I see now what you already pointed out long ago: The Nano 33 BLE is entirely different from the Nano 33 IoT, with a different CPU, and a different core, too. So it really seems we never supported the BLE so far, despite the fact that the IoT has been reported to work with Mozzi.

It is probably not going to be exceedingly difficult to provide at least basic support for the Nano 33 BLE, but we're currently in the middle of restructuring some internals, and so touching those parts of the code right now would add a lot of complexity. The restructuring will also add some more flexibility for configuration, and with some luck, I think the BLE may actually work out of the box in a PWM mode, with analog input disabled.

Feel free to remind us, should we forget to revisit this issue.

jonrichings commented 4 months ago

I've hit the same problem. Also using a couple of different nRF52840 modules. This is a growing family so it would be nice to have some support for them.

tfry-git commented 4 months ago

The following compiles with Mozzi 2.0, and might just work (but I don't have a 33 BLE to test with).

#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_EXTERNAL_TIMED
#define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_NONE
#define MOZZI_AUDIO_BITS 12  // wild guess at what might be supported. In case of trouble, try with 8
#include <Mozzi.h>
#include <Oscil.h>
#include <tables/sin2048_int8.h>

Oscil <SIN2048_NUM_CELLS, MOZZI_AUDIO_RATE> aSin(SIN2048_DATA);

void setup(){
  analogWriteResolution(MOZZI_AUDIO_BITS);
  pinMode(D9, OUTPUT);
  startMozzi(); // :)
  aSin.setFreq(440); // set the frequency
}

void audioOutput(AudioOutput out) {
  analogWrite(D9, out.l()+MOZZI_AUDIO_BIAS);
}

void updateControl(){
}
AudioOutput updateAudio(){
  return MonoOutput::from8Bit(aSin.next());
}

void loop(){
  audioHook();
}
jonrichings commented 4 months ago

Thanks for the try. I still get the same problem though. Looks like the required library, HardwareTimer.h is not available for the nRF52840 based boards.

tfry-git commented 4 months ago

What core are you using? I tested "Arduino Mbed OS Nano Boards".

jonrichings commented 4 months ago

Adafruit Feather nRF52840 Express and Sense. Since you asked I just tried it on Arduino Nano 33 BLE and that did compile. I can't say for sure it works since I have no speaker on that right now. Maybe it only works on Mbed boards?