Error Serial1 was not declared in this scope

HI All -

Advance thanks for your time reading this post, and suggestions.

Enclosing the code, getting the error Error Serial1 was not declared, how to go around solving this?

Best,

Ramesha

#include <Wire.h>
#include <EEPROM.h>
#include <VL6180X.h>
#include <SoftwareSerial.h>
SoftwareSerial levelSensor(10, 11); // RX, TX
#define LED 13
VL6180X sensor;
float dist, sens;
int count;
uint32_t currentMillis;
uint32_t previousMillis;
float duration;
void setup()
{
  Wire.begin();
  sensor.init();
  sensor.configureDefault();
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 90);
  sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 150);
  sensor.setTimeout(500);
  sensor.stopContinuous();
  delay(500);
  sensor.writeReg(0x10A, 0x08);
  sensor.startRangeContinuous(100);
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.flush();
  Serial1.flush();
  //  levelSensor.begin(4800);

  //ideas
  // Look at docs to see how to improve accuracy
  // only use samples that converged
  // look into whether samples are used twice or other issues with the uncoltrolled loop
  // allow more variability in the output of the sensor and average in the mcu
  // measure drift by connecting to the CNC machine to get precise moves

  count = 500;
}
void(* resetFunc) (void) = 0;
void loop()
{
  sens = sensor.readRangeContinuous();
  if (sens < 255)
  {
    if ( abs(sens - dist) > 10.0) {
      dist = sens;
    }
    dist = .995 * dist + .005 * sens;
  }
  count = count --;
  if (count == 0)
  {
    count = 1;
    //  Serial.print("\t Range: ");
    //    Serial.println(dist);
  }

  {
    if (dist >= 40.00 && dist <= 120.00)
    { currentMillis = millis();

    }
    if (dist >= 120.00 ) {
      Serial.println("\t Measurement Complete");
      exit;
    }
    if (dist < 40.00) {
      Serial.println("distance <40");
      exit;
    }

    void duration_data(void);
    {
      duration = (currentMillis / 1000.0);
      Serial.print("distance");
      Serial.print("\t\t");
      Serial.println(dist);
      Serial.print("Duration secs   ");
      Serial.print("\t");
      Serial.flush();
      Serial.println(duration);
      if (Serial.available()) {      // If anything comes in Serial (USB),
        Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 0 & 1)
      }
      duration = 0;
      //      levelSensor.print(duration);
      delay(300);
    }
  }
}





//

FCM_SerialCommunication_timeStopCrossin.ino (2.27 KB)

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

aarg:
You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Thanks for pointing out.

(deleted)

(deleted)

rockwellramesha:
Enclosing the code, getting the error Error Serial1 was not declared, how to go around solving this?

You have not told us what Arduino board you are using. Serial1 does not exist on an Uno or nano

...R

Robin2:
You have not told us what Arduino board you are using. Serial1 does not exist on an Uno or nano

...R

I'm working with Nano

I did see example of 04. communication - SerialPassThrough

change all instances of 'Serial1' to 'levelSensor'. Tidy up all the serial references and verify the baud rate of the level Sensor (is it really 4800)?

aarg:
change all instances of 'Serial1' to 'levelSensor'. Tidy up all the serial references and verify the baud rate of the level Sensor (is it really 4800)?

4800 codeline is commented

but now I'm getting error Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\User\AppData\Local\Temp\arduino_build_199960\sketch: Access is denied.
Error compiling for board Arduino Nano.

#include <Wire.h>
#include <EEPROM.h>
#include <VL6180X.h>
#include <SoftwareSerial.h>
//SoftwareSerial levelSensor(10, 11); // RX, TX
#define LED 13
VL6180X sensor;
float dist, sens;
int count;
uint32_t currentMillis;
uint32_t previousMillis;
float duration;
void setup()
{
 Wire.begin();
 sensor.init();
 sensor.configureDefault();
 sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 90);
 sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 150);
 sensor.setTimeout(500);
 sensor.stopContinuous();
 delay(500);
 sensor.writeReg(0x10A, 0x08);
 sensor.startRangeContinuous(100);
 Serial.begin(9600);
 levelSensor.begin(9600);
 Serial.flush();
 levelSensor.flush();
 //  levelSensor.begin(4800);

 //ideas
 // Look at docs to see how to improve accuracy
 // only use samples that converged
 // look into whether samples are used twice or other issues with the uncoltrolled loop
 // allow more variability in the output of the sensor and average in the mcu
 // measure drift by connecting to the CNC machine to get precise moves

 count = 500;
}
void(* resetFunc) (void) = 0;
void loop()
{
 sens = sensor.readRangeContinuous();
 if (sens < 255)
 {
   if ( abs(sens - dist) > 10.0) {
     dist = sens;
   }
   dist = .995 * dist + .005 * sens;
 }
 count = count --;
 if (count == 0)
 {
   count = 1;
   //  Serial.print("\t Range: ");
   //    Serial.println(dist);
 }

 {
   if (dist >= 40.00 && dist <= 120.00)
   { currentMillis = millis();

   }
   if (dist >= 120.00 ) {
     Serial.println("\t Measurement Complete");
     exit;
   }
   if (dist < 40.00) {
     Serial.println("distance <40");
     exit;
   }

   void duration_data(void);
   {
     duration = (currentMillis / 1000.0);
     Serial.print("distance");
     Serial.print("\t\t");
     Serial.println(dist);
     Serial.print("Duration secs   ");
     Serial.print("\t");
     Serial.flush();
     Serial.println(duration);
     if (Serial.available()) {      // If anything comes in Serial (USB),
       levelSensor.write(Serial.read());   // read it and send it out levelSensor (pins 0 & 1)
     }
     duration = 0;
     //      levelSensor.print(duration);
     delay(300);
   }
 }
}

(deleted)

I think you also have ‘serialprint ln’

Should be ‘1’ not ‘ln’

rockwellramesha:
4800 codeline is commented

Why? What is the purpose?

spycatcher2k:
Save, close, reopen.

now getting this error!

Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

exit status 1
'levelSensor' was not declared in this scope

#include <Wire.h>
#include <EEPROM.h>
#include <VL6180X.h>
//#include <SoftwareSerial.h>
//SoftwareSerial levelSensor(10, 11); // RX, TX
#define LED 13
VL6180X sensor;
float dist, sens;
int count;
uint32_t currentMillis;
uint32_t previousMillis;
float duration;
void setup()
{
  Wire.begin();
  sensor.init();
  sensor.configureDefault();
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 90);
  sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 150);
  sensor.setTimeout(500);
  sensor.stopContinuous();
  delay(500);
  sensor.writeReg(0x10A, 0x08);
  sensor.startRangeContinuous(100);
  Serial.begin(9600);
  levelSensor.begin(9600);
  Serial.flush();
  levelSensor.flush();
  //  levelSensor.begin(4800);

  //ideas
  // Look at docs to see how to improve accuracy
  // only use samples that converged
  // look into whether samples are used twice or other issues with the uncoltrolled loop
  // allow more variability in the output of the sensor and average in the mcu
  // measure drift by connecting to the CNC machine to get precise moves

  count = 500;
}
void(* resetFunc) (void) = 0;
void loop()
{
  sens = sensor.readRangeContinuous();
  if (sens < 255)
  {
    if ( abs(sens - dist) > 10.0) {
      dist = sens;
    }
    dist = .995 * dist + .005 * sens;
  }
  count = count --;
  if (count == 0)
  {
    count = 1;
    //  Serial.print("\t Range: ");
    //    Serial.println(dist);
  }

  {
    if (dist >= 40.00 && dist <= 120.00)
    { currentMillis = millis();

    }
    if (dist >= 120.00 ) {
      Serial.println("\t Measurement Complete");
      exit;
    }
    if (dist < 40.00) {
      Serial.println("distance <40");
      exit;
    }

    void duration_data(void);
    {
      duration = (currentMillis / 1000.0);
      Serial.print("distance");
      Serial.print("\t\t");
      Serial.println(dist);
      Serial.print("Duration secs   ");
      Serial.print("\t");
      Serial.flush();
      Serial.println(duration);
      if (Serial.available()) {      // If anything comes in Serial (USB),
        levelSensor.write(Serial.read());   // read it and send it out levelSensor (pins 0 & 1)
        levelSensor.println;
      }
      duration = 0;
      //      levelSensor.print(duration);
      delay(300);
    }
  }
}

(deleted)

spycatcher2k:

//SoftwareSerial levelSensor(10, 11); // RX, TX

remove //

Note that it was not in the first code post. :slight_smile:

spycatcher2k:

//SoftwareSerial levelSensor(10, 11); // RX, TX

remove //

Thanks that resolved one issue! now I'm not receiving the data at the other controller, code is as under

//Nano reciever
// read two ints from a Uno
// see Uno_transmitter.ino

#include <SoftwareSerial.h>
const byte Rx = 10;
const byte Tx = 11;
//uint32_t f;
int val=0;
SoftwareSerial levelReceiver(Rx, Tx); // RX, TX

void setup() {

  Serial.begin(9600);
  levelReceiver.begin(9600);
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
}

void loop() {
  {
    Serial.read();
    levelReceiver.read();
    levelReceiver.println("\n");
  };


  //delay(300);
  //}
}

Well, it really looks just like you're coding without looking at any documentation or working examples.

aarg:
Well, it really looks just like you're coding without looking at any documentation or working examples.

I, couldn't find a suitable document, please advise a link

rockwellramesha:
I, couldn't find a suitable document, please advise a link

If you look at the sticky threads at the top of this forum, you will find a great collection of such links. Every Arduino function and language feature is also documented on this website under the "resources" tab.

aarg:
If you look at the sticky threads at the top of this forum, you will find a great collection of such links. Every Arduino function and language feature is also documented on this website under the "resources" tab.

aarg - appreciate your support, you have been so patient and kind.