Errors when porting from Mega2560 to Due

Can someone help please; my sketch has been working and compiling perfectly for Mega2560 but I get the following errors when compiling for Due. First part of errors and sketch only pasted because it exceeds a character limit!

Arduino: 1.8.5 (Windows 10), Board: "Arduino Due (Programming Port)"

F:\Documents\Arduino\Channelizer Due\Rack_1 - Copy\Rack_1\Rack_1.ino: In function 'void loop()':

Rack_1:284: error: invalid conversion from 'byte {aka unsigned char}' to 'midi::MidiType' [-fpermissive]

portLo);

^

In file included from F:\Documents\Arduino\libraries\arduino_841278\src/MIDI.h:258:0,

from F:\Documents\Arduino\Channelizer Due\Rack_1 - Copy\Rack_1\Rack_1.ino:8:

F:\Documents\Arduino\libraries\arduino_841278\src/MIDI.hpp:133:6: error: initializing argument 1 of 'void midi::MidiInterface<SerialPort, _Settings>::send(midi::MidiType, midi::DataByte, midi::DataByte, midi::Channel) [with SerialPort = HardwareSerial; _Settings = midi::DefaultSettings; midi::DataByte = unsigned char; midi::Channel = unsigned char]' [-fpermissive]

void MidiInterface<SerialPort, Settings>::send(MidiType inType,

^

Rack_1:292: error: invalid conversion from 'byte {aka unsigned char}' to 'midi::MidiType' [-fpermissive]

7);

^

In file included from F:\Documents\Arduino\libraries\arduino_841278\src/MIDI.h:258:0,

from F:\Documents\Arduino\Channelizer Due\Rack_1 - Copy\Rack_1\Rack_1.ino:8:

#include <MIDI.h>
#include <button.h>
#include <midi-utils.h>
#include <ntools.h>
#define USE_OLED_64_ADAFRUIT
#include <XLCD.h>
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_RESET);

long timeoutLimit = 375000;//approx 1250 per second or 75,000 per minute
long timeoutCount = 0;
bool turnOnDisplay = true; 
bool displayIsOn = true;



#define MODE_IDLE 0
#define MODE_SPLIT 3

#define UNISON (keySplit == 21)

byte _note = 0;
byte Data1T;
byte Data1Lo;
byte Data1Hi;
byte Data2;
boolean CC33 = false; //set if midi CC33 incoming - don't send to Peak!
byte shrunkData1Lo;
byte shrunkData1Hi;
byte shrunkData1T;
byte shrunkData2;
String drawData1;
String drawData2 = "flabs   ";
byte portT = 7;
float denominator = 4;
int fourteenBit;
byte MidiType;

byte Mode =  MODE_IDLE;
byte lastMode =  MODE_IDLE;


// reduce screen flickering

boolean needsUpdate = true;
boolean doSkip = false;
boolean dataToDisplay = false;



// to avoid hangs, the keydowns are counted, if > 0 the blue LED is lid
int keysDown = 0;


//Default split point: Lower zone 0 (C-1) to 35 (B2); Upper zone 36 (C3) to 127 (G9)
// changed to start in UNISON Mode
byte keySplit = 21;


Button _upLower(53);      //increase the lower output Channel
Button _downLower(51);    //decrease the lower output Channel
Button _upUpper(47);      //increase the upper output Channel
Button _downUpper(45);    //decrease the upper output Channel
Button _setSplit(43);     //ask for note on Keysplit or return to Unison mode if pressed with no note entered
Button _panic(49);        //parachute
Button upperTransUp(35);  
Button upperTransDown(37);  
Button lowerTransUp(39);  
Button lowerTransDown(41);  


MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,    MIDI);

boolean toggleA = false; //panel switch A  shrinks range of Pitch Bend wheel for Mini D on Channel 6
boolean toggleB = false; //panel switch B  echo's everything on Ch 6 to Ch 7 so that Odyssey and mini D are treated as single synth and PB etc. goes to both

byte portHi;
byte portLo;
byte transposeHi;
byte transposeLo;
char whoAmI;  //which of four Arduinos in the rack am I? A,B,C,D.

void setup() {
 LCD_BEGIN
 //Serial.begin(9600);

 lcd << L(3, 1) << F("Channelizer");
 lcd << L(3, 2) << F("By Steve Hunt");
 lcd << L(3, 3) << F("");
 lcd << L(3, 4) << __DATE__ ;
 lcd << L(3, 5) << __TIME__ ;


 pinMode(23,INPUT_PULLUP);
 pinMode(25,INPUT_PULLUP);
 pinMode(27,INPUT_PULLUP);
 pinMode(29,INPUT_PULLUP);
 pinMode(31,INPUT_PULLUP);
 pinMode(33,INPUT_PULLUP);

 lcd.display();

 delay (800);

 MIDI.begin(MIDI_CHANNEL_OMNI);
 MIDI.turnThruOff();

 
 if ( digitalRead(27)== LOW ) whoAmI = 'A';
 else if ( digitalRead(29)== LOW ) whoAmI = 'B';
 else if ( digitalRead(31)== LOW ) whoAmI = 'C';
 else if ( digitalRead(33)== LOW ) whoAmI = 'D';
 else whoAmI = 'Z';

//First power-on state:

//whoAmI = 'C';

 switch (whoAmI) {
   case 'A':
     portHi = 1;
     portLo = 0;
     transposeHi = 0;
     transposeLo = 0;
     break;
   case 'B':
     portHi = 2;
     portLo = 0;
     transposeHi = 0;
     transposeLo = 0;
     break;
   case 'C':
     portHi = 3;
     portLo = 0;
     transposeHi = 0;
     transposeLo = 0;
     break;
   case 'D':
     portHi = 6;
     portLo = 0;
     transposeHi = 0;
     transposeLo = 0;
     break;
   default:
     portHi = 5;
     portLo = 0;
     transposeHi = 0;
     transposeLo = 0;     
 }

}

void loop()
{
 timeoutCount++;
 if (timeoutCount > timeoutLimit)
   {
   display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3C (for the 128x64)
   display.ssd1306_command(SSD1306_DISPLAYOFF); // To switch display off
   turnOnDisplay = false;
   displayIsOn = false;
   timeoutCount = 0; //prevents overflow
   }
 if (turnOnDisplay)
   {
     display.ssd1306_command(SSD1306_DISPLAYON); // To switch display back on
     displayIsOn = true;
   }
 lastMode = Mode;
 CC33 = false;
 if (MIDI.read())
 {
   Data1Lo = Data1Hi = Data1T = MIDI.getData1();
   Data2 = MIDI.getData2();
   MidiType = MIDI.getType();
   switch (MidiType)
   {
     case midi::NoteOn:
       keysDown++;
       timeoutCount = 0;
       _note = MIDI.getData1();
       if (Mode == MODE_SPLIT)
       {
         keySplit = _note;
         portT = portHi;
         lastMode = MODE_SPLIT;
         Mode = MODE_IDLE;
         needsUpdate = true;
         goto cont;
       }
       else
       {
         Data1Lo += transposeLo;
         Data1Hi += transposeHi;
         if (_note < keySplit)
         {
           portT = portLo;
           Data1T = Data1Lo;
         }
         else
         {
           portT = portHi;
           Data1T = Data1Hi;
         }
       }
       if (keysDown > 24) keysDown = 0;

       noteSend();
       
       break;



     case midi::NoteOff:
       timeoutCount = 0;
       if (!displayIsOn)  turnOnDisplay = true;
       _note = MIDI.getData1();
       Data1Lo += transposeLo;
       Data1Hi += transposeHi;


       if (_note < keySplit)
       {
         portT = portLo;
         Data1T = Data1Lo;
       }
       else
       {
         portT = portHi;
         Data1T = Data1Hi;
       }
       keysDown--;
       if (keysDown < 0) keysDown = 0;

       
       noteSend();
       
       break;

     case midi::AfterTouchPoly:        // = 0xA0,
     case midi::ControlChange:         // = 0xB0,
        if (MIDI.getData1() == 33 )  CC33 = true;  //CC33 dropped so that Numa mod wheel doesn't fool Peak into changing osc 1 lfo shape ammount at extreme of mod wheel range
           portT = portHi;                 // anything except note ons and offs are sent to PortHi - unless Unison mode...
           if (UNISON)
     {
       // if we are in UNISON Mode, we forward all cc etc to both ports
       if (portLo && !(portLo == 5 && CC33)) // ie skip if we've selected midi channel 0 or if (CC33 and Peak)
       {
         //if (!(portLo == 7 && portHi == 6 && toggleB)) //don't echo out on Ch7 if also echoing on other zone
         {
           if (portLo == 6 && toggleA) {Data1Lo = shrunkData1Lo; Data2 = shrunkData2;}
           
         MIDI.send(MidiType,
                   Data1Lo,
                   Data2,
                   portLo);
         }
       
         if (portLo == 6 && toggleB) // toggleB echo's everything on Ch6 to Ch7 as well
         {
         MIDI.send(MidiType,
                   Data1Lo,                     
                   Data2,
                   7);
         }

       }
       if (portHi && !(portHi == 5 && CC33)) // ie skip if we've selected midi channel 0  or if (CC33 and Peak)
       {
         if (portLo != portHi) //so if both zones are same channel don't send duplicate notes or CC
         {
          MIDI.send(MidiType,
                    Data1Hi,
                    Data2,
                    portHi);
           if (portHi == 6 && toggleB) // toggleB echo's everything on Ch6 to Ch7 as well
         {
         MIDI.send(MidiType,
                   Data1Hi,                     
                   Data2,
                   7);
         }
         }
       }
     }

midi.h attached

MIDI.h (9.65 KB)

Your problem starts here:

byte MidiType;

It's bad behavior to use a type name as a variable name. The returned value is of type MidiType (an enum) and not of type byte. The AVR compiler backend might just spit some warnings, for the SAMD backend it's an error. Rename that variable and give it the type "MidiType" and the compiler will be happy with that.

Thanks. I've tried what I think you mean but I obviously don't understand! I replaced all instances of MidiType with a new name MidiInputType

eg

MidiInputType = MIDI.getType();

and

MIDI.send(midi::MidiInputType,
Data1Lo,
Data2,
portLo);

and declared this at the start like

MidiType MidiInputType;

which I thought would declare the variable type as MidiType, but the compiler says

'MidiType' does not name a type

Is there a correct way to declare MidiInputType as type MidiType or what am I doing wrong? Many thanks

The declaration looks almost good but you missed the namespace. Correctly it should read:

midi::MidiType MidiInputType;

The send call is then

MIDI.send(MidiInputType,
                    Data1Lo,
                    Data2,
                    portLo);

Thanks pylon, it compiles fine now and I've learned a few things. Cheers.