USING THE ARDUINO UNO and LIS3DHTR to send MIDI to ableton

Hey, as a total newbie I need for an art installation an Accelerometer as MIDI-Controller for Ableton...working with an Macbook Pro 2019 on OS 12.6.7 I came up (with a lot of forum reading and CHATgpt, thanks so far) with that bit of Code, but since hairless midi isn´t supported anymore, I cant get my head around a Solution. Here the code, mybe someone can help or has some hints?
Thanks a lot:

#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

void printMIDIMessage(byte status, byte data1, byte data2) {
  Serial.print("Status: 0x");
  Serial.println(status, HEX);
  Serial.print("Data1: 0x");
  Serial.println(data1, HEX);
  Serial.print("Data2: 0x");
  Serial.println(data2, HEX);
}

Adafruit_LIS3DH lis;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  
  MIDI.begin("glazed");  // Initialize MIDI library
  MIDI.turnThruOff(); // Turn off MIDI Thru feature

  if (!lis.begin(0x19)) {
    Serial.println("Unable to initialize the LIS3DHTR sensor.");
    while (1);
  }

  lis.setRange(LIS3DH_RANGE_2_G);
  lis.setDataRate(LIS3DH_DATARATE_100_HZ);
}

void loop() {
  sensors_event_t accelEvent;
  lis.getEvent(&accelEvent);

  int16_t x = (int16_t)accelEvent.acceleration.x;
  int16_t y = (int16_t)accelEvent.acceleration.y;
  int16_t z = (int16_t)accelEvent.acceleration.z;

  Serial.print("X: ");
  Serial.println(x);
  Serial.print("Y: ");
  Serial.println(y);
  Serial.print("Z: ");
  Serial.println(z);

  

  // Scale acceleration values to the MIDI note range (0-127)
  int noteX = map(x, -32768, 32767, 0, 127);
  int noteY = map(y, -32768, 32767, 0, 127);
  int noteZ = map(z, -32768, 32767, 0, 127);

  // Send MIDI note values to Ableton
  MIDI.sendNoteOn(noteX, 127, 1);
  MIDI.sendNoteOn(noteY, 127, 1);
  MIDI.sendNoteOn(noteZ, 127, 1);

  delay(50);

  while (MIDI.read()) {
    byte status = MIDI.getType();
    byte data1 = MIDI.getData1();
    byte data2 = MIDI.getData2();

    printMIDIMessage(status, data1, data2);
  }
}

Hello futuretenze

Welcome to the worldbest Arduino forum ever.

I assume that you have written the programme by yourself, then it is quite easy to find the error:

There's a trick to figuring out why something isn't working:

Use a logic analyzer to see what happens.
Put Serial.print statements at various places in the code to see the values of variablesand determine whether they meet your expectations.

Have a nice day and enjoy coding in C++.

Hints for what? You haven't said what the code should do. You haven't said what the problem is with it.

I promise the code now does just what it is written to do. I don't want to have to read through it and try to guess what you actually want from what it does.

Please describe the project so we know what it is. Please describe the problem. What does this code do or not do that doesn't meet your expectations?

Oh, sorry. The code should take the float data of the LIS3DHTR sensor and turn it into MIDI-Data, then sending it to an IAC-Bus fpor further use in Ableton. Additional Serial.print should allow me to test weather the sensor is working and to check the MIDI-Data. Compiling went fine, it also uploads to the Board and runs, but the Sserial monitor shows question marks all over (although the baudrate fits), also I have no MIDI-Data coming in or out (neither in ableton, nor in MIDI Monitor). Since I heard about Hairless MIDI as a Serial MIDI brigde does not work any more on OSX 12.6 and newer, I´m searching some advise to get a Serial MIDI Bridge working. Thanks a lot.

Thi would help if you gave a link to this sensor, the data sheet says

3-axis MEMS accelerometer, ultra-low-power, ±2g/4g/8g/16g full scale, high-speed I2C/SPI digital output, embedded FIFO, high-performance acceleration sensor, LGA 16 3x3x1.0 package

So what sort of data do tou want out of it and what do you want to send in terms of MIDI data?
The best way of getting MIDI into Ableton is to use a Leonardo or Micro processor along with one of a number of USB MIDI libraries, these can appeared as inputs to the MIDI monitor program for the Mac.

Do you want to send control or sound information.

I don't see how that code would do anything useful, even if you had hairless installed on your computer.

1 Like

The plan is basically to use the sensor as MIDI-controller, so when I move the Sensor, it should be able to control an envelope on a Synth like Cutoff etc. I thought by translating the coordinates given by the sensor into MIDI Data it could work, but it doesn´t.. So I´ll try the Leonardo with an MIDIUSb Library, let´s see. Thanks a lot so far :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.