Go Down

Topic: Arduino Octapad Serial Monitor Error  (Read 377 times) previous topic - next topic

Sanjaan

Aug 11, 2018, 10:09 am Last Edit: Aug 14, 2018, 07:56 am by Sanjaan
I made arduino octapad Using CD4051 analog IC. But Serial Monitor and hairless MIDI-SERIAL software not work properly. Serial Monitor values are unreadable (like ???[][][]).
i used 115200 baud .
how can i fix that.


Code: [Select]

unsigned char PadNote[16] = {47,18,32,38,43,13,45,17,21,36,0,44,0,19,0,21};       
unsigned char status;
int PadCutOff[16] = {200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200};   
int MaxPlayTime[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};       
#define  midichannel 0;                 
boolean activePad[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};     
int PinPlayTime[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};             
boolean VelocityFlag  = true;           
int analogPin[2] = {A0,A1};
int pin = 0;
int hitavg = 0;
int pad = 0;
int r0 = 0;
int r1 = 0;
int r2 = 0;
int count = 0;
int multiplex1[8];
int multiplex2[8];

//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  Serial.begin(115200);                                  // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************

void loop(){

  readSensors(0);
  readSensors(1);
  checkSensors(0);
  checkSensors(1);
}
void readSensors (int analogPin) {
  for(count=0; count <= 7; count++)
  {
    r2 = bitRead(count,0);
    r1 = bitRead(count,1);
    r0 = bitRead(count,2);
    digitalWrite(5, r0);
    digitalWrite(6, r1);
    digitalWrite(7, r2);
    if(analogPin==0) {
    multiplex1[count] = analogRead(analogPin);
  }
  else if(analogPin==1) {
    multiplex2[count] = analogRead(analogPin);
  }
  }
}
 
void checkSensors (int analogPin) {
  for(int pin=0; pin <=7; pin++) {
    if(analogPin==0) {
    hitavg = multiplex1[pin];
    pad=pin;
    }
    else if(analogPin==1) {
    hitavg = multiplex2[pin];
    pad=pin+8;
    }
   
    if((hitavg > PadCutOff[pad])) {
      if((activePad[pad] == false)) {
        if(VelocityFlag == true) {
          hitavg = (hitavg /-1);
        }
        else {
          hitavg = 127;
        }
        MIDI_TX(144,PadNote[pad],hitavg);
        PinPlayTime[pad] = 0;
        activePad[pad] = true;
      }
      else {
        PinPlayTime[pad] = PinPlayTime[pad] + 1;
      }
    }
    else if((activePad[pad] == true)) {
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
      if(PinPlayTime[pad] > MaxPlayTime[pad]) {
       activePad[pad] = false;
       MIDI_TX(128,PadNote[pad],0);
      }
    }
  }
}

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
}

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.


Serial.write() writes binary data. So you will see the characters that represent the ASCII codes for status, PITCH, and VELOCITY. If you want to see the text representation of those values you would do something like this:
Code: [Select]
  Serial.println(status);
  Serial.println(PITCH);
  Serial.println(VELOCITY);


But I don't know what sort of data your MIDI software is expecting. For that, the Serial.write() may well be the correct code and the Serial.println() statements will corrupt the MIDI data. Even so, it might be worth doing it just to verify with Serial Monitor that things are working as expected. Keep in mind that the serial port can only be open by one program at a time. So if you open Serial Monitor that will likely block your MIDI software from accessing the data from the Arduino.

See:

Go Up