Conversione byte to string

Buongiorno.
Avrei la necessità di convertire dei byte letti da un mixer midi (berhinger BCF2000) e trasmormarli in stringa.
Come si fa la conversione ?

Grazie, Alberto

Ciao!

senza usare lo StringObject puoi definire un array di char e salvare byte per byte in tale array:

char rx_buffer[10];
int buffer_pos = 0;

nel loop di ricezione

rx_buffer[buffer_pos++] = byte_ricevuto;

al termine dovrai mettere il carattere '\0' per terminare la stringa

Io ho fatto così ma mi da sempre ?$d$?$d$

char rxbuffer[10];
int buffer_pos = 0;

void loop()
{
  if (Serial.available() > 0)
  {
    while (Serial.available() > 0)
    {
      rxbuffer[buffer_pos++] = Serial.read();
    }
        mySerial.print (rxbuffer);
  }
}

ciao

questo riceve i caratteri, ogni 9 termina la stringa e la stampa

char rxbuffer[10];
int buffer_pos = 0;

void loop()
{
  if (Serial.available() > 0)
  {
      rxbuffer[buffer_pos++] = Serial.read();
     if(buffer_pos == 9 {
       rx_buffer[buffer_pos] = '\0';
       mySerial.print (rxbuffer);
      buffer_pos == 0;
}
  }
}

Il fatto è che non so quanti byte il mixer butta fuori.
Come faccio a capirlo ?

Sul pc vedo dei valori sempre diversi anche se premo lo stesso pulsante.
Può essere perchè ricevo sulla porta midi a 31250 e spedisco sulla seriale ciò che ricevo dalla midi a 9600 ?

Grazie, Alberto

Ti segnalo l'esistenza della libreria Midi --> Arduino Playground - MIDILibrary
ed di uno shield: http://www.robot-italy.com/product_info.php?products_id=1396 (anche se con 1 connetore risolvi)
Guarda anche --> http://arduino.cc/en/Tutorial/Midi

MIDI is a serial protocol that operates at 31,250 bits per second. The Arduino's built-in serial port (all of them on the Mega as well) can send data at that rate.
MIDI bytes are divided into two types: command bytes and data bytes. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, and amount of pitch bend, and so forth. For more details, see the MIDI specification, or one of the many MIDI Protocol Guides on the Web.

ciao

devi guardare il protocollo MIDI (che non conosco), sarà sicuramente definita la lunghezza massima del pacchetto dati e magari quale byte indica la "fine" del pacchetto... altrimenti come dice Paolo puoi usare le librerie già pronte...

Sto usando la midi library così:

#include <MIDI.h>

#define LEDOFF 6   		// LED pin verde OFF
#define LEDON 7   		// LED pin rosso ON

byte GD1;
byte GD2;

void setup() {
  pinMode(LEDON, OUTPUT);
  pinMode(LEDOFF, OUTPUT);  
  Serial.begin(9600);
  MIDI.begin();            	// Launch MIDI with default options

}
// Per funzionare con bcf200 deve essere aperto midiox e l'interruttore sulla sparkfun impostato a run
// Il loop non parte finchè non si muove un controllo sulla bcf per creare un segnale 
// Per la programmazione impostare lo switch su prg
void loop() {
  if (MIDI.read()) {
 
    digitalWrite(LEDON,HIGH);     // Blink the LED
    MIDI.send(ControlChange,81,100,1);  // Invia CC Numero controllo=81 Valore del controllo=100 Canale=1 
    digitalWrite(LEDOFF,LOW);    	
    
    delay(1000);		// Wait for a second
    digitalWrite(LEDOFF,HIGH);     // Blink the LED    
    MIDI.send(ControlChange,81,20,1);  // Invia CC Numero controllo=81 Valore del controllo=20 Canale=1 
    delay(1000);		// Wait for a second
    digitalWrite(LEDOFF,LOW);    	
  }
}

Esiste un modo per leggere il messaggio midi che viene ritornato trasformato in stringa leggibile ?
Ho visto che che esiste nella libreria MIDI.getData1 e MIDI.getData2 come byte ma non so come usarli e come trasformarli in ascii

Grazie, Alberto