Go Down

Topic: Problem transfering MIDI commands through BlueTooth (Read 1 time) previous topic - next topic

akiskaps

Jun 05, 2019, 09:17 pm Last Edit: Jun 06, 2019, 01:12 pm by akiskaps
I am trying to build a simple daw controller using two potentiometers. I am using Hairless midi and LoopBe1Monitor. I managed to get it done through usb but now I want to add bluetooth(HC-05 or HC-06).

This is the code I am using. It has no errors and is uploaded fine. Although Hairless midi does not appear any error, the debug MIDI messages does not show anything.

Code: [Select]
/*LIBRARIES*/
#include <MIDI.h>
#include <SoftwareSerial.h>

/*GLOBAL VARIABLES*/
#define BTH_RX 0
#define BTH_TX 1

SoftwareSerial Bth(BTH_RX, BTH_TX);

//Potentiometers
int pinPot1 = A0;   int pot1State;   int lastPot1State;
int pinPot2 = A1;   int pot2State;   int lastPot2State;

MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  MIDI.begin();
  Bth.begin(57600);

  //Potentiometers
  pinMode(pinPot1, INPUT);
  pinMode(pinPot2, INPUT);
}

void loop() {
  readPotentiometers();
  delay(5);
}

/*Functions*/

void readPotentiometers(){
  pot1State = analogRead(pinPot1) / 8;   // Devide analog reads(0-1021) by 8 to get a range of 0-127 for MIDI
  pot2State = analogRead(pinPot2) / 8;
  checkPotentiometers();
}

void checkPotentiometers(){
  if(pot1State != lastPot1State) MIDImessage(176, 1, pot1State);
  lastPot1State = pot1State;
  if(pot2State != lastPot2State) MIDImessage(176, 2, pot2State);
  lastPot2State = pot2State;
}

void MIDImessage(byte command, byte data1, byte data2){
  Bth.write(command);
  Bth.write(data1);
  Bth.write(data2);
}


P.S. Is there any better program than hairless ?

Grumpy_Mike

Code: [Select]
#define BTH_RX 0
#define BTH_TX 1

SoftwareSerial Bth(BTH_RX, BTH_TX);

Why use the hardware UART pins for software serial. That is not going to work.

akiskaps

Code: [Select]
#define BTH_RX 0
#define BTH_TX 1

SoftwareSerial Bth(BTH_RX, BTH_TX);

Why use the hardware UART pins for software serial. That is not going to work.
Ok, I changed the TX and RX to pins 10 and 11. The BlueTooth is connected but hairless midi doesn't seem to recieving any data. Do i miss something to the code?

Grumpy_Mike

Quote
The BlueTooth is connected but hairless midi doesn't seem to recieving any data.
Have you set hairless to receive date from the bluetooth?

akiskaps

Have you set hairless to receive date from the bluetooth?
If you mean to select the Serial Port where I have connected the bluetooth(usb to enable bluetooth communication for my pc), yes. I dont know or see any other setting in the preferences. By the way thank you for your help!

Grumpy_Mike

#5
Jun 10, 2019, 05:38 pm Last Edit: Jun 10, 2019, 05:38 pm by Grumpy_Mike
I mean like this:-

If so then has the messages further down stream been routed?

akiskaps

I mean like this:-

If so then has the messages further down stream been routed?
Yes, it is like that you send in the picture.
I can't understand what you saying (Has the message further down stream been routed), but if you mean if i have checked the debug midi messages box, yes i have

Grumpy_Mike

Quote
I can't understand what you saying
Has the left hand side of that box been routed, in the screen dump the MIDI out is routed to IAC Driver Bus 1 and the MIDI in is not routed.

Are you on a Mac?

akiskaps

#8
Jun 10, 2019, 10:03 pm Last Edit: Jun 10, 2019, 10:04 pm by akiskaps
In the left is the com8, where I have connected the external usb bluetooth to my desktop and in midi out is the loopbe internal midi. I have also unchecked the mute of loopbe monitor. Thanks again I really apreciate that you trying to help me  :)

P.S. I am on windows 10

Grumpy_Mike

Quote
P.S. I am on windows 10
Ah, I am on a Mac myself. Have a look at this.
https://mitxela.com/projects/midi_over_bluetooth

With Hairless I don't think you will have to bit bang the serial protocol but it does tell you about the setup and getting Windows to see things.

akiskaps

#10
Jun 18, 2019, 05:17 pm Last Edit: Jun 18, 2019, 05:18 pm by akiskaps
I am really sorry for bothering you for no reason. I made the circuit once again from start and I realized that I had connected the Tx --> Tx and the Rx --> Rx. Now everything works as excepted, but the potentiometer readings are not stable(even when I am not turning the pots), have you any advice, on taking stable readings, or a link to share?

Grumpy_Mike

You can do two things.
1) Add a capacitor of 0.1uF between each pot's wiper and ground.

2) Only send out MIDI when the analogue readings has changed by a certain amount and only do the divide by 8 thing once you are ready to send out the MIDI:-

Code: [Select]
if(abs(pot1State - lastPot1State) > threshold ){
   MIDImessage(176, 1, pot1State>>3);
   lastPot1State = pot1State;
}


Where threshold is the number the raw analogue input has to change to the amount that works for your physical setup.

Go Up