Go Down

Topic: Problems Midi Wirelless Arduino + Xbee (Read 503 times) previous topic - next topic

wesleyfranca

Aug 05, 2019, 04:20 pm Last Edit: Aug 12, 2019, 04:17 am by surbyte Reason: Code tag added
Hi friends, I am developing a midi wireless communication project using 2 one arduinos, 2 xbee sheld and two xbee s2c transmitters, in the process, I made the xbees peer configuration via xctu software, tested the communication and was successfully performed, they talk to each other! however, when I connect xbees to shield and arduino communication just doesn't happen, I wonder if they could help me with solving this problem! (I already did the arduino communication tests without xbees and it was also successful!) follow the codes used!

**Transmitter Code**

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

uint8_t ssRX = 10;
uint8_t ssTX = 11;

// set up a new serial object
SoftwareSerial mySerial (ssRX, ssTX);

byte in_buffer[1024]; //maximum number of bytes arrived in one cpu cycle
unsigned int received_bytes;

void setup(){
 Serial.begin (9600); //XBEE transmission
 mySerial.begin(31250); //CABO MIDI transmission
 received_bytes=0;

 while (!Serial) {
   ; // Espera a porta serial conectar. Necess├írio para USB nativa
 }
}

void loop(){
   
 if(mySerial.available() > 0)
 {
     received_bytes=mySerial.available();
     for (int i=0;i<received_bytes;i++)
       in_buffer[i]=mySerial.read();  //save in the buffer all bytes arrived from MIDI port
     
     //write all bytes arrived in the present cycle (so, the input is decoupled from the output)
      for (int i=0;i<received_bytes;i++)
     {
       Serial.write(in_buffer[i]);
     }
       
     //reset the counter of received bytes in the cycle
     received_bytes=0;
 }
}



**Receptor Code**
Code: [Select]

#include <SoftwareSerial.h>
#include <MIDI.h>

uint8_t ssRX = 10;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 11;

// set up a new serial object
SoftwareSerial mySerial (ssRX, ssTX);

void setup(){
 Serial.begin (9600); //XBEE transmission
 mySerial.begin(31250);//CABO MIDI transmission
 
 //led 13 used for debug
 pinMode(13, OUTPUT);
 digitalWrite(13, LOW);
}

void loop(){
   if(mySerial.available() > 0){
     
   digitalWrite(13, HIGH);
   Serial.write(mySerial.read()); //receives the midi messages via XBEE...and send it to Synth
   digitalWrite(13, LOW);
 }
 if (Serial.available()) {
    digitalWrite(13, HIGH);
    mySerial.write(Serial.read());
    digitalWrite(13, LOW);
 }
 //Test function
 //SendAllNotes();
}
////////////////////////////////////////////////////////////////////////////////////////////
//
// MIDI HELPER FUNCTIONS (taken from http://arduino.cc/en/Tutorial/Midi?from=Tutorial.MIDI)
//
////////////////////////////////////////////////////////////////////////////////////////////

void SendAllNotes() {
 // play notes from F#-0 (0x1E) to F#-5 (0x5A):
 for (int note = 0x1E; note < 0x5A; note ++) {
   //Note on channel 13 (0x9C), some note value (note), middle velocity (0x45):
   digitalWrite(13, HIGH);
   MIDICommand(0x9C, note, 0x45);
   delay(100);
   digitalWrite(13, LOW);
   //Note on channel 13 (0x9C), some note value (note), silent velocity (0x00):
   MIDICommand(0x9C, note, 0x00);  
   delay(100);
   
 }
}

//  Send a midi command.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void MIDICommand(int cmd, int pitch, int velocity) {
 Serial.write(cmd);
 Serial.write(pitch);
 Serial.write(velocity);
}



Go Up