Pages: [1]   Go Down
Author Topic: Serial/MIDI declaration question  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,
I am working on project which in its default form communicates with a PC over the serial link to transfer speed data.

I am currently trying to add a function where it can switch and instead output the data in MIDI format through a different connector depending on a button state (but still using pins 0 and 1 to save input/outputs).

In my current program I set the serial (Serial.begin (9600)) in the void setup, my question is can I later declare the serial port to work as midi (Serial.begin(31250)) or can the serial port only be initialised once at one speed?

Many thanks in advance
Tom
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

48 views and no ideas? Come on people don't let me down  smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It may sound stupid, but did you try? You wouldn't break anything trying to Serial.begin() twice.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey thanks for the reply, yeah I have tried it and it will compile however I don't currently have access to the midi receiving hardware so cannot tell if it is working correctly, was hoping someone may know.

I guess I will have to wait for then, thanks anyway though
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 5
Posts: 998
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tommy, there is no problem with calling Serial.begin multiple times at multiple speeds.  To test, I made a little sketch that prints data at two different speeds:

Code:
void setup()
{
  Serial.begin(9600);
  Serial.println("Hello at 9600");
  delay(5000);
  Serial.begin(115200);
  Serial.println("Hello at 115200");
}
void loop(){}

When I set my serial monitor to 9600 I got reasonable text then garbage.  At 115K it was the other way around.

I think your only concern is whether 31250 works as a baud rate.

Good luck!

Mikal
Logged

Pages: [1]   Go Up
Jump to: