Using messenger to decode serial data...

Hi guys,

Everyone on this forum has been so helpful over the past week or so.

I was wondering if someone could help me work out my problem...

I've got a Pro Mini transmitting accelerometer, potentiometer and button data over xbees to an Uno.

It basically sends the data like so:

acc xxx xxx xxx
cca xxx
ccb xxx
bta x
btb x

I'm then breaking the code down when it comes into the arduino, and trying to use the information as controller data for some MIDI out code I've got...

The code for the transmitter:

#include <Wire.h>
#include "nunchuck_funcs.h"

float accx,accy,accz,bta,btb,cca,ccb;

void setup()
{
    Serial.begin(31250);
    nunchuck_init();
}

void loop()
{
  nunchuck_get_data();
  accx = nunchuck_accelx();
  accy = nunchuck_accely();
  accz = nunchuck_accelz();
  bta = nunchuck_cbutton();
  btb = nunchuck_zbutton();
  cca = nunchuck_joyx();
  ccb = nunchuck_joyy();
  delay(1);
  nunchuck_get_data();

  if(accx != nunchuck_accelx() || accy != nunchuck_accely() || accz != nunchuck_accelz())
  {
    Serial.print("acc "); Serial.print((byte)accx,BYTE);
    Serial.print(" "); Serial.print((byte)accy,BYTE);
    Serial.print(" "); Serial.println((byte)accz,BYTE);
  }
  
  if(cca != nunchuck_joyx())
  {
    Serial.print("cca "); Serial.println((byte)cca,BYTE);
  }
  
  if(ccb != nunchuck_joyy())
  {
    Serial.print("ccb "); Serial.println((byte)ccb,BYTE);
  }

  if(bta != nunchuck_cbutton())
  {
    Serial.print("bta "); Serial.println((byte)bta,BYTE);
  }
  
  if(btb != nunchuck_zbutton())
  {
    Serial.print("btb "); Serial.println((byte)btb,BYTE);
  }
  


}

The code for the receiver:

#include <Messenger.h>


Messenger message = Messenger();

byte accx,accy,accz,bta,btb,cca,ccb;

void setup()
{
  Serial.begin(31250);    
  message.attach(messageCompleted); 
}

void messageCompleted()
{
  while (message.available()) {
    if (message.checkString("acc")) {
      accx = message.readInt();
      accy = message.readInt();
      accz = message.readInt();
      
    } else if (message.checkString("cca")) {
      cca = message.readInt();
     
      
    } else if (message.checkString("ccb")) {
      ccb = message.readInt();

      
    } else if (message.checkString("bta")) {
      bta = message.readInt();

      
    } else if (message.checkString("btb")) {
      btb = message.readInt();
      

      
    } else int temp = message.readInt();
  }
}

void loop()
{
  while ( Serial.available() ) message.process( Serial.read() );
  
  byte midiCtrl = cca;
  
    Midi_Send(0xB0,0x01,midiCtrl);
}

void Midi_Send(byte cmd, byte data1, byte data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

At the moment, I'm just trying to use one of the controls (cca - a potentiometer) as a test...

Can anybody help please!?

Thanks in advance,

Nick

Aside from the fact that you seem to be sending MIDI info OUT the same port that the Arduino is sending data IN on, and that you are sending data regardless of whether anything was received, you failed to mention exactly what your problem is. What is it you need help with?

Aside from the fact that you seem to be sending MIDI info OUT the same port that the Arduino is sending data IN on

This isn't a problem as the xbee is only using the in, and the MIDI is using the out.

I've tested it just sending a single byte over the Xbee's to control midi, and that works, so that's not a problem.

I hadn't actually thought about the using data despite checking it... Thanks for pointing it out, I've only been programming arduino a couple of weeks...

Ahh... How did I forget that!?

Basically, my problem is that after I've parsed the input, I can't get it to control the midi...

I'm wanting to get each variable (accx, cca, btb) to control different midi functions.

It'd be great if you could help. :).

I'm wanting to get each variable (accx, cca, btb) to control different midi functions.

It seems like you are getting each variable separately. What you do with that data is entirely up to you. Personally, I can't see the relationship between periodic acceleration data and any aspect of music, but that might simply be that the only musical instrument I can play is a stereo.