Go Down

Topic: NewSoftSerial does not name a type (Read 7731 times) previous topic - next topic

mstadtler

I downloaded this code from Sparkfun

I get this error "NewSoftSerial does not name a type"

I downloaded the NewSoftSerial file to the library with all the other files.

I have #include <NewSoftSerial.h> in mysketch

What am I missing?

Quote
/*
2-12-2011
Spark Fun Electronics 2011
Nathan Seidle

This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

This code works with the VS1053 Breakout Board and controls the VS1053 in what is called Real Time MIDI mode.
To get the VS1053 into RT MIDI mode, power up the VS1053 breakout board with GPIO0 tied low, GPIO1 tied high.

I use the NewSoftSerial library to send out the MIDI serial at 31250bps. This allows me to print regular messages
for debugging to the terminal window. This helped me out a ton.

5V : VS1053 VCC
GND : VS1053 GND
D3 (SoftSerial TX) : VS1053 RX
D4 : VS1053 RESET

Attach a headphone breakout board to the VS1053:
VS1053 LEFT : TSH
VS1053 RIGHT : RSH
VS1053 GBUF : GND

When in the drum bank (0x78), there are not different instruments, only different notes.
To play the different sounds, select an instrument # like 5, then play notes 27 to 87.

To play "Sticks" (31):
talkMIDI(0xB0, 0, 0x78); //Bank select: drums
talkMIDI(0xC0, 5, 0); //Set instrument number
//Play note on channel 1 (0x90), some note value (note), middle velocity (60):
noteOn(0, 31, 60);

*/
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code

byte note = 0; //The MIDI note value to be played
byte resetMIDI = 4; //Tied to VS1053 Reset line
byte ledPin = 13; //MIDI traffic inidicator
int instrument = 0;

void setup() {
  Serial.begin(57600);

  //Setup soft serial for MIDI control
  mySerial.begin(31250);

  //Reset the VS1053
  pinMode(resetMIDI, OUTPUT);
  digitalWrite(resetMIDI, LOW);
  delay(100);
  digitalWrite(resetMIDI, HIGH);
  delay(100);
}

void loop() {

  talkMIDI(0xB0, 0x07, 120); //0xB0 is channel message, set channel volume to near max (127)

/*
  //Demo Basic MIDI instruments, GM1
  //=================================================================
  Serial.println("Basic Instruments");
  talkMIDI(0xB0, 0, 0x00); //Default bank GM1

  //Change to different instrument
  for(instrument = 0 ; instrument < 127 ; instrument++) {

    Serial.print(" Instrument: ");
    Serial.println(instrument, DEC);

    talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

    //Play notes from F#-0 (30) to F#-5 (90):
    for (note = 30 ; note < 40 ; note++) {
      Serial.print("N:");
      Serial.println(note, DEC);
     
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
      noteOn(0, note, 60);
      delay(50);

      //Turn off the note with a given off/release velocity
      noteOff(0, note, 60);
      delay(50);
    }

    delay(100); //Delay between instruments
  }
  //=================================================================
*/

  //Demo GM2 / Fancy sounds
  //=================================================================
  Serial.println("Demo Fancy Sounds");
  talkMIDI(0xB0, 0, 0x78); //Bank select drums

  //For this bank 0x78, the instrument does not matter, only the note
  for(instrument = 30 ; instrument < 31 ; instrument++) {

    Serial.print(" Instrument: ");
    Serial.println(instrument, DEC);

    talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

    //Play fancy sounds from 'High Q' to 'Open Surdo [EXC 6]'
    for (note = 27 ; note < 87 ; note++) {
      Serial.print("N:");
      Serial.println(note, DEC);
     
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
      noteOn(0, note, 60);
      delay(50);

      //Turn off the note with a given off/release velocity
      noteOff(0, note, 60);
      delay(50);
    }

    delay(100); //Delay between instruments
  }

/*
  //Demo Melodic
  //=================================================================
  Serial.println("Demo Melodic? Sounds");
  talkMIDI(0xB0, 0, 0x79); //Bank select Melodic
  //These don't sound different from the main bank to me

  //Change to different instrument
  for(instrument = 27 ; instrument < 87 ; instrument++) {

    Serial.print(" Instrument: ");
    Serial.println(instrument, DEC);

    talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

    //Play notes from F#-0 (30) to F#-5 (90):
    for (note = 30 ; note < 40 ; note++) {
      Serial.print("N:");
      Serial.println(note, DEC);
     
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
      noteOn(0, note, 60);
      delay(50);

      //Turn off the note with a given off/release velocity
      noteOff(0, note, 60);
      delay(50);
    }

    delay(100); //Delay between instruments
  }
*/
}

//Send a MIDI note-on message.  Like pressing a piano key
//channel ranges from 0-15
void noteOn(byte channel, byte note, byte attack_velocity) {
  talkMIDI( (0x90 | channel), note, attack_velocity);
}

//Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity) {
  talkMIDI( (0x80 | channel), note, release_velocity);
}

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
  digitalWrite(ledPin, HIGH);
  mySerial.print(cmd, BYTE);
  mySerial.print(data1, BYTE);

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
  //(sort of: http://253.ccarh.org/handout/midiprotocol/)
  if( (cmd & 0xF0) <= 0xB0)
    mySerial.print(data2, BYTE);

  digitalWrite(ledPin, LOW);
}


liuzengqiang

Please fix your post first.

Use code not quote:

Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

PaulS

Did you restart the IDE after downloading NewSoftSerial?

Open a new sketch. Use Tools + Import Library..., and select NewSoftSerial. If that is not an option, you didn't install NewSoftSerial correctly (in the right place).

If that is the case, you need to either install it correctly, or tell us what OS and what version of the IDE you are using, so we can help you determine where the files go.
The art of getting good answers lies in asking good questions.

mstadtler

A restart is all that was needed.

Thanks

StaticDet5

I'm having the exact same problem.

I've gone so far as to completely delete my Arduino directories, Documents directory, and reinstall.  I've tried on two different computers.

It looks like the libraries are in the same place (I've been able to use other libraries that I have downloaded).  I just keep getting back:
'NewSoftSerial' does not name a type
Code: [Select]
SoftwareSerialExample:2: error: 'NewSoftSerial' does not name a type
SoftwareSerialExample.cpp: In function 'void setup()':
SoftwareSerialExample:10: error: 'mySerial' was not declared in this scope
SoftwareSerialExample.cpp: In function 'void loop()':
SoftwareSerialExample:16: error: 'mySerial' was not declared in this scope
SoftwareSerialExample:19: error: 'mySerial' was not declared in this scope


The code that I'm using is essentially the SoftwareSerialExample:
Code: [Select]
#include <NewSoftSerial.h>

NewSoftSerial mySerial(2, 3);

void setup() 
{
  Serial.begin(57600);
  Serial.println("Goodnight moon!");

  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.print((char)mySerial.read());
  if (Serial.available())
    mySerial.print((char)Serial.read());
}


I needed to change the name back to "NewSoftSerial" because the library that I am hoping to use (Serial_LCD, from this thread:  http://arduino.cc/forum/index.php?topic=60802.new;topicseen#new) has not been adapted for the new SoftwareSerial or Arduino 1.0.

I am using Arduino 23 (I have tried version 22 as well) with an Arduino Uno.

Thanks!

PaulS

Quote
I needed to change the name back to "NewSoftSerial" because

What does this mean? What name did you change back to NewSoftSerial?
The art of getting good answers lies in asking good questions.

StaticDet5

When you look at the code you'll see that the library has been renamed from the current Arduino 1.0 version, SoftwareSerial to NewSoftSerial (which is the old name of the library, before it was incorporated into Arduino 1.0 core code).

Go Up