Using Serial Connection between Nano Every and Leonardo/Pro Micro)

Hi all,

I am currently working on a USB Midi device that requires the Nano Every due to the number of pins/interrupts required (no other board I have found fullfills my requirements).
I have finished the code and have it all working beautifully. The only issue is that the Nano Every does not support Native USB, meaning that I need to run two separate programs on my computer to convert the serial data from the arduino to MIDI data that my Music Program can understand (I currently have to use "hairless Midi bridge").

Therefore, My plan is to send the serial data from the Nano Every to an ATmega32u4 (e.g. Leonardo or Pro Micro) which will act as my MIDI USB device that can natively be recognized by any computer and receive midi data.

To test this concept I set up an Arduino Nano Every and a Pro Micro to send and receive a simple "hello" using the Serial Communication example explained here:

Unfortunately nothing works. I have tried many examples and I just cant seem to get it to work.
To varify that the RX and TX pins even work, I used the Serial Examples of the program Processing.org. That works fine.

In the Example above, when I check the serial Monitor, I can see it sending "hello", however when I check the Serial Monitor on the receiving Board, the Serial Monitor stays empty (and yes, I made sure that the pins are connected correctly TX to RX and RX to TX and I even added GRD to GRD).

Can anyone please help me out and explain why that might be the case and what I need to do to get it working?

Kind Regards,
-CB

Is the Leonardo (32U4) sketch using Serial1 ?

The link does not reveal how or what you tested.

Adding to @runaway_pancake, the 32U4 based boards as well as the Nano Every use Serial1 for communication over RX/TX.

Number of pins is usually not a good argument to choose a processor / board; there are port expanders (SPI or I2C), shift registers and for analog inputs there are multiplexers.

As there is no good description of your project, it's difficult to judge the need for interrupts.

Thanks for the reply, I'll give you a little bit more context.

I'm working on a MIDI Controller to control different software parameters while recording or playing live. These parameters are controlled with 3 Linear faders (Analogue Potentiometers). Each fader has a Channel (CC) and a value (from 0-127). The user can view these values on a small 32x64px display.

Using a rotatry encoder, the user can enter a "menu" in which you can first select one of the three faders, to once the switch is activated, you enter a sub-menu in which you can change the CC Channel of that slider.

Finally, there is an Ultrasonic Sensor onboard. If you long-press the rotary encoder while in the standard view, you enter the "Ultrasonic" mode which allows you to use your hand has a "potentiometer" (e.g. raise and lower your hand to send the same 0-127 steps to the software).

Here is an Image of my 3D printed prototype:

The link does not reveal how or what you tested.

Right. I used the "SerialWrite" and "SerialRead" examples from Processing.org which include arduino code so that you can varify that the serial data is successfully sent and received from the arduino.

Number of pins is usually not a good argument to choose a processor / board;

Im still new to arduino, and I asked in the forum and other places but unfortunately never received a reply as to which board to use, or what alternate route to go to get it all to work including midi.

From my understanding the only difference in code is that I add the 1 after Serial, correct?
e.g.:

char Mymessage[5] = "Hello"; //String data
  void setup() {
    // Begin the Serial at 9600 Baud   
    Serial1.begin(9600);
  }

  void loop() {
    Serial1.write(Mymessage,5); //Write the serial data
    delay(1000);
  }

So I tried that using the example code and I still cant get it to spit out any serial information on the receiving serial monitor :frowning: Not sure what I'm overlooking...

Show both your codes, please.

It's not only Serial.begin() that you need to change; all use of Serial needs to change to Serial1. Both on the 32U4 board and the Nano Every.

As far as I can tell, that's what I did :confused:
Here is the sending code (Nano Every):

char Mymessage[5] = "Hello"; //String data
  void setup() {
    // Begin the Serial at 9600 Baud   
    Serial1.begin(9600);
  }

  void loop() {
    Serial1.write(Mymessage,5); //Write the serial data
    delay(1000);
 
  }

And the receiving Code (32U4):

char Mymessage[10]; //Initialized variable to store recieved data
  
  void setup() {
    // Begin the Serial at 9600 Baud
    Serial1.begin(9600);
  }
  
  void loop() {
    Serial1.readBytes(Mymessage,5); //Read the serial data and store in var
    Serial1.println(Mymessage); //Print data on Serial Monitor
    delay(1000);
  }

Thanks for taking the time. This is the final puzzle piece to a year-long project :s

OK, my mistake. Everything that you want to see on the serial monitor needs to stay on Serial. So the 32U4 code

char Mymessage[10]; //Initialized variable to store recieved data
  
void setup() {
  // Begin the Serial at 9600 Baud
  Serial1.begin(9600);
  Serial.begin(9600);
  while(!Serial);
}
  
void loop() {
  Serial1.readBytes(Mymessage,5); //Read the serial data and store in var
  Serial.println(Mymessage); //Print data on Serial Monitor
  delay(1000);
}

The while(!Serial); is needed if you don't want to miss the first messages while the USB communication channel between the 32U4 and the PC is being established.

Oh my goodness, it works, thank yo uso much!!!!!!

This is fantastic and explains why nothing that I have been trying for the past few days has been working. Your help is very much appreciated!

You seem quite knowledgeable, so may I ask, if you see an issue with my setup (using two controllers/chips) for my controller instead of e.g. a single MIDI Compatible board with a bridge to support the additional interrupts or other functionalities I require from the ardiuno Nano?

Thanks, but I often have my doubts about that :wink: I have no knowledge about MIDI.

From your description in post #4, I don't see a reason to use 2 boards; a Micro/Leonardo/ProMicro should be able to handle that. It's only 3 potentiometers, a rotary encoder (which possibly explains the use of interrupts) and an ultrasonic sensor.

So I just did some thinking and it turns out that I am using 3 interrupts.
2 for the Rotary Encoder (one for switch pin and one for the rotation) and the third interrupt is being used for the Ultrasonic Sensor. I honestly cant remember why we are using it there anymore, but I do recall it not working well without the interrupt setup system I have going on... :confused:

Button presses usually don't require interrupts. Does it really matter if your code reacts in a few milliseconds or that it takes 50 milliseconds to react?

I can imagine that the standard ultrasonic code gives you grief if you want a reasonable response time.

And you are aware that most (or all depending on processor) IO pins can be used with pin change interrupt?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.