Why a sketch works on an uno not a pro micro.

I have created a program that I can control my guitar amp like a midi foot pedal. I have to program working in my uno 3. I decided to go with a pro micro for the finished product inside of the foot pedal itself. But when I try to compile the same sketch or program I get a ‘‘call of overloaded ‘write(int)’ is ambiguous’’. I am not sure why I keep getting this. The issue appears to be with Serial.write(0x00) of the note off command the Pro Micro doesn’t like it. If I change it to Serial.write (byte()0x00)) the micro likes it but nothing happens on the amp it will not change the channels. Like I said if I use my Uno it works just fine. Any direction would be greatly appreciated.

This is my code.

#include <MIDI.h>
#include <SoftwareSerial.h>
const int BT1 = A0; // This is preset button 1
const int BT2 = A1; // This is preset button 2
const int LED1 = 11; // This is LED for preset 1
const int LED2 = 10; // This is LED for preset 2

void setup() {
pinMode (BT1, INPUT_PULLUP); //using internal pull down 10k resister to set BT1 to a high and as an input
pinMode (BT2, INPUT_PULLUP); //using internal pull down 10k resister to set BT2 to a high and as an input

pinMode(LED1, OUTPUT); // Making LED1 pin 11 as an output
pinMode(LED2, OUTPUT); // Making LED2 pin 10 as an output
Serial.begin(31250); // MIDI Baud rate is 31250 and using TX as the data out to the amp
}

void loop() {
int stateBT1 = digitalRead(BT1); //reading the intial state of BT1
int stateBT2 = digitalRead(BT2); // reading the intial state of BT2

// Preset 1
if (stateBT1 == 0) {
Serial.write (0x90); // preset 1 note on
Serial.write(0x05);
Serial.write(0x7F);
Serial.write (0x90); // preset 1 note off
Serial.write(0x05);
Serial.write(0x00);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);

}

// Preset 2
if (stateBT2 == 0) {
Serial.write(0x90); //preset 2 Note on
Serial.write(0x04);
Serial.write(0x7F);
Serial.write(0x90); //preset 2 Note off
Serial.write(0x04);
Serial.write(0x00);
digitalWrite(LED2, HIGH);
digitalWrite(LED1, LOW);

}

delay(500);

Why are you including SoftwareSerial if you are not using it? Calls to Serial use the pins 0/1 hardware serial port.

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]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Larbo44:
If I change it to Serial.write (byte()0x00)) the micro likes it but nothing happens on the amp it will not change the channels.

I guess you meant to write:

Serial.write(byte(0x00))

because that other thing wouldn’t even compile. I think casting to byte was the right thing to do and the problem with the amp is not related to that.

One significant difference between the Uno and the Pro Micro is that the Uno resets automatically when a connection is opened on Serial. The Pro Micro does not. This is why you will commonly see a line like this in setup():

while (!Serial) {}  // Wait for serial port to connect. Needed for native USB port only.

Try adding that after your Serial.begin() statement to see if it fixes the problem.

More info:
https://www.arduino.cc/reference/en/language/functions/communication/serial/ifserial/

Hello Larbo44

Serial.write (byte()0x00))

???????

Please post ALL your ACTUAL code.

Regards,
bidouilleelec

This is my full code that works on my Uno. I have tried to use while (!Serial) {} as suggested and that didn’t work. Yes I meant to say Serial.write(byte(0x00)). When I use (byte(0x00)) on the Pro Micro it will compile and upload to the board but will not change anything on the amp. When I compile and upload as it is written below to the Uno I am able to change amp presets back and forth. I figure it is an issue with the boards being different in some way.

#include <MIDI.h>
//#include <SoftwareSerial.h>
const int BT1 = A0;  // This is preset button 1
const int BT2 = A1;  // This is preset button 2
const int LED1 = 11; // This is LED for preset 1
const int LED2 = 10; // This is LED for preset 2


void setup() {
 pinMode (BT1, INPUT_PULLUP);   //using internal pull down 10k resister to set BT1 to a high and as an input
 pinMode (BT2, INPUT_PULLUP);   //using internal pull down 10k resister to set BT2 to a high and as an input

 pinMode(LED1, OUTPUT);         // Making LED1 pin 12 as an output
 pinMode(LED2, OUTPUT);         // Making LED2 pin 12 as an  output
 Serial.begin(31250);           // MIDI Baud rate is 31250 and using TX as the data out to the amp
  
}

void loop() {
 int stateBT1 = digitalRead(BT1); //reading the intial state of BT1
 int stateBT2 = digitalRead(BT2); // reading  the intial state of BT2


 // Preset 1
 if (stateBT1 == 0) {

   Serial.write (0x90);
   Serial.write(0x05);
   Serial.write(0x7F);
   Serial.write (0x90);
   Serial.write (0x05);
   Serial.write (0x00);
   digitalWrite(LED1, HIGH);
   digitalWrite(LED2, LOW);

 }

 else {
   // nothing is done here do not want to release of BT1 to execute anything
 }

 // Preset 2
 if (stateBT2 == 0) {     // stating if the state of BT2 goes low then execute the below MIDI command and set the proper LEDS if BT2 is still high do nothing
   Serial.write(0x90);   //preset 2 Note on
   Serial.write(0x04);
   Serial.write(0x7F);
   digitalWrite(LED2, HIGH);
   digitalWrite(LED1, LOW);
   Serial.write(0x90);  //preset 2 Note off
   Serial.write(0x04);
   Serial.write(0x00);
   digitalWrite(LED1, HIGH);
   digitalWrite(LED2, LOW);
 }


delay(500);
}[code]

How is the midi connected? Using Rx and Tx?

I'm not familiar with the Pro Micro but on a Leonardo you would have to use Serial1 instead of Serial when you use the Rx and Tx pins.

I am using the TX only transmitting to the amp dont care about the information coming back at this time. I am using the TX pin on the uno and micro.

I am using the TX pin on the uno and micro.

On the Uno, the TX pin is connected to the Serial instance.
On the Micro, the TX pin is connected to the Serial1 instance.

Paul you and sterretje are saying I need to change all my Serial.write commands to Serial1.write. I tried that for Serial.write(0x00); only and I was able to get it to compile. But I am taking it to make it work and control the amp I will need to use Serial1.

PaulS:
On the Uno, the TX pin is connected to the Serial instance.
On the Micro, the TX pin is connected to the Serial1 instance.

There's a fun gotcha!

Larbo44:
Paul you and sterretje are saying I need to change all my Serial.write commands to Serial1.write. I tried that for Serial.write(0x00); only and I was able to get it to compile. But I am taking it to make it work and control the amp I will need to use Serial1.

That is what they are saying.

I am thinking that this can easily be fixed with a one-line macro defined near the top of the program (untested):

#define Serial Serial1

possibly surrounded with a #if so that it only applies for the Pro Micro and the Leonardo (and any others that need it).

Definitely a gotcha not sure it was a fun one lol.

Also will I need to change the Serial.begin(31250); to Serial1.begin(31250); I am guessing I do from what I have seen from other forums and posts about the two.

Everything that was Serial in the Uno code now needs to be Serial1.

Awesome thanks.

I wan't reply and let everyone l=know that changing everything to serial1 was the fix. I was able last night to use the pro micro to control the amp like I want it to. Now comes the fun part building the pedal its self. I want to thank everyone for their comments and help I do appreciate it. I am new at all this Arduino and coding stuff but have learned a lot so far. I have a few more project on the horizon that will be very challenging but looking forward to it.

adwsystems:
Calls to Serial use the pins 0/1 hardware serial port.

Not on a Pro Micro! “Serial” is the USB port on the Pro Micro. You have to use Serial1 for the hardware serial port. I suspect that is the problem.