'Serial 1' was not declared in this scope - Yosemite 10.10

Status
Not open for further replies.

j4mes

New member
I foolishy updated to Yosemite. My code was working fine before. I'm trying to use hardware serial, and now even the example code won't compile.

I'm getting the following errors:


teensy_HWSERIAL_example.ino: In function 'void setup()':
teensy_HWSERIAL_example:6: error: 'Serial1' was not declared in this scope
teensy_HWSERIAL_example.ino: In function 'void loop()':
teensy_HWSERIAL_example:16: error: 'Serial1' was not declared in this scope
teensy_HWSERIAL_example:19: error: 'Serial1' was not declared in this scope


the code used:

// set this to the hardware serial port you wish to use
#define HWSERIAL Serial1

void setup() {
Serial.begin(9600);
HWSERIAL.begin(9600);
}

void loop() {
int incomingByte;

if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print("USB received: ");
Serial.println(incomingByte, DEC);
HWSERIAL.print("USB received:");
HWSERIAL.println(incomingByte, DEC);
}
if (HWSERIAL.available() > 0) {
incomingByte = HWSERIAL.read();
Serial.print("UART received: ");
Serial.println(incomingByte, DEC);
HWSERIAL.print("UART received:");
HWSERIAL.println(incomingByte, DEC);
}
}
 
Use File > Preferences to turn on verbose info while compiling.

That won't fix the problem, but it will give more info.
 
Use File > Preferences to turn on verbose info while compiling.

That won't fix the problem, but it will give more info.

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard /var/folders/mg/rsg1qy093fg4n3hynx89bb800000gn/T/build6602330031028804840.tmp/teensy_HWSERIAL_example.cpp -o /var/folders/mg/rsg1qy093fg4n3hynx89bb800000gn/T/build6602330031028804840.tmp/teensy_HWSERIAL_example.cpp.o
teensy_HWSERIAL_example.ino: In function 'void setup()':
teensy_HWSERIAL_example:6: error: 'Serial1' was not declared in this scope
teensy_HWSERIAL_example.ino: In function 'void loop()':
teensy_HWSERIAL_example:16: error: 'Serial1' was not declared in this scope
teensy_HWSERIAL_example:19: error: 'Serial1' was not declared in this scope
 
Use File > Preferences to turn on verbose info while compiling.

That won't fix the problem, but it will give more info.

I want to know what should I do... I've got the same error as mentioned above, and I am new to programming and to Arduino... so help will be greatly apreciated.

Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Nano, ATmega328"

Build options changed, rebuilding all

Using library TextFinder in folder: C:\Users\Alex\Documents\Arduino\libraries\TextFinder (legacy)

Using library Time in folder: C:\Users\Alex\Documents\Arduino\libraries\Time (legacy)

Using library Timer-master in folder: C:\Users\Alex\Documents\Arduino\libraries\Timer-master (legacy)

Using library Adafruit GFX Library in folder: C:\Users\Alex\Documents\Arduino\libraries\Adafruit-GFX-Library-master

Using library Adafruit ST7735 Library in folder: C:\Users\Alex\Documents\Arduino\libraries\Adafruit-ST7735-Library-master

Using library SPI in folder: E:\Programs\Arduino\hardware\arduino\avr\libraries\SPI

Using library DHT sensor library in folder: C:\Users\Alex\Documents\Arduino\libraries\DHT-sensor-library-master



E:\Programs\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IE:\Programs\Arduino\hardware\arduino\avr\cores\arduino -IE:\Programs\Arduino\hardware\arduino\avr\variants\eightanaloginputs -IC:\Users\Alex\Documents\Arduino\libraries\TextFinder -IC:\Users\Alex\Documents\Arduino\libraries\Time -IC:\Users\Alex\Documents\Arduino\libraries\Timer-master -IC:\Users\Alex\Documents\Arduino\libraries\Adafruit-GFX-Library-master -IC:\Users\Alex\Documents\Arduino\libraries\Adafruit-ST7735-Library-master -IE:\Programs\Arduino\hardware\arduino\avr\libraries\SPI -IC:\Users\Alex\Documents\Arduino\libraries\DHT-sensor-library-master C:\Users\Alex\AppData\Local\Temp\build8529747721185559282.tmp\sketch_jun14a.cpp -o C:\Users\Alex\AppData\Local\Temp\build8529747721185559282.tmp\sketch_jun14a.cpp.o

sketch_jun14a.ino:37:20: error: 'Serial1' was not declared in this scope
sketch_jun14a.ino: In function 'void setup()':
sketch_jun14a.ino:49:3: error: 'Serial1' was not declared in this scope
sketch_jun14a.ino: In function 'void ClockSYNC()':
sketch_jun14a.ino:110:3: error: 'Serial1' was not declared in this scope
'Serial1' was not declared in this scope


also the code I have looks like this:

#include <TextFinder.h>
#include <Time.h>
#include "Timer.h"

//Setup for 1.8 TFT displays
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

#define cs 10
#define dc 9
#define rst 8

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);

//Setup for DHT22 sensor
#include "DHT.h"
#define DHTTYPE DHT22 // DHT 22
#define DHTPIN 7 // what pin we're connected to
DHT dht(DHTPIN, DHTTYPE);

float to;
int ho;



TextFinder finder(Serial1);
long pctime; //variable that stores time readed by ES8266
Timer t; //instantiate the timer object




double tmp;
String tmpl,tmpld;

void setup()
{
Serial1.begin(115200);//connection to ESP8266
//Serial.begin(115200); //serial debug


//Set mode for ES8266 wifi board
Serial1.println("AT+RST");
Serial1.println("AT+CWMODE=1");
delay(500);//delay after mode change
Serial1.println("AT+RST");
//connect to wifi network
boolean b=false;
while (b!=true){
Serial1.println("AT+CWJAP=\"|YOUR WIFI-ID\",\"YOUR PASSWORD\"");
if(Serial1.find("OK")){
//Serial.println("OK WIFI");
b=true;
}
else
{
// Serial.println("NOK WIFI");
b=false;
}
}


setSyncProvider(requestSync);//defines the function responsabel for the time sincronization
setSyncInterval(60);//sync interval

//1.8 TFT setup
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
tft.drawRect(0,0,128,45,ST7735_BLUE);
tft.fillRect(0,0,128,45,ST7735_BLUE);


ClockSYNC();//initial sincroization of the clock

t.every(500, digitalClockDisplay);//evry 500ms display the clock
dht.begin();
termometre(dht.readTemperature(),dht.readHumidity(),15);//display the left termometer
}

void loop(){

t.update();



}

time_t requestSync()
{
ClockSYNC();
return 0; // the time will be sent later in response to serial mesg
}

void ClockSYNC(){

//create start command
String startcommand = "AT+CIPSTART=\"TCP\",\"www.roroid.ro\", 80"; //443 is HTTPS, still to do

Serial1.println(startcommand);


//test for a start error
if(Serial1.find("Error")){
Serial.println("Error on start");
return;
}

//create the request command
String sendcommand = "GET http://www.roroid.ro/php/ceas.php HTTP/1.0\r\n\r\n\r\n";//works for most cases

//send
Serial1.print("AT+CIPSEND=");
Serial1.println(sendcommand.length());



if(Serial1.find(">"))
{
//delay(1000);

}
else
{
Serial1.println("AT+CIPCLOSE");
Serial.println("Timeout");
return;
}



Serial1.print(sendcommand);

if(Serial1.find("SEND OK")){
finder.find("TIMP=");
pctime=finder.getValue();
pctime=pctime+7200;
setTime(pctime);
//Serial.println(pctime);
return;
}

}


void digitalClockDisplay(){
// digital clock display of the time
String timp,data;

if (hour()<10)
timp=timp+"0";
timp=timp+String(hour());
timp=timp+":";
if (minute()<10)
timp=timp+"0";
timp=timp + String(minute());
timp=timp+":";
if (second()<10)
timp=timp+"0";

timp=timp + String(second());

char charBuf[12];
if(tmpl!=timp){
tft.setCursor(15, 10);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(2);
tmpl.toCharArray(charBuf, 12) ;
tft.print(charBuf);
tft.setCursor(15, 10);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
//tft.setTextWrap(true);
timp.toCharArray(charBuf, 12) ;
tft.print(charBuf);
tmpl=timp;
}

data=String(day())+"/"+String(month())+"/"+String(year());
if (tmpld!=data){
tft.setCursor(35, 30);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(1);
tmpld.toCharArray(charBuf, 12) ;
tft.print(charBuf);
tft.setCursor(35, 30);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
//tft.setTextWrap(true);
data.toCharArray(charBuf, 12) ;
tft.print(charBuf);

tmpld=data;
}
termometre(dht.readTemperature(),dht.readHumidity(),15);
}

void termometre (float t,int h, float ics1)
{
//draw thermometer from left screen
tft.drawRect(ics1-4,50,9,91,ST7735_WHITE);
tft.drawCircle(ics1,149,10,ST7735_WHITE);
for (int a = 0; a < 10; a++)
{
tft.drawLine(ics1-5,60+8*a,ics1-7,60+8*a,ST7735_WHITE);
tft.drawLine(ics1+5,60+8*a,ics1+7,60+8*a,ST7735_WHITE);
}
tft.drawLine(ics1-10,140,ics1+10,140,ST7735_WHITE);
tft.drawLine(ics1-10,100,ics1+10,100,ST7735_BLUE);
tft.setCursor(15 + ics1, 97);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(1);
tft.print("0 C");
tft.setTextSize(1);
tft.setCursor(21 + ics1, 89);
tft.print("o");

//display humidity
if (ho!=h)
{
tft.setCursor(35 + ics1, 120);
tft.setTextSize(3);
tft.setTextColor(ST7735_BLACK);
tft.print(ho);
tft.setCursor(35 + ics1, 120);
tft.setTextSize(3);
tft.setTextColor(ST7735_BLUE);
tft.print(h);
ho=h;
}
//display temp
if (to!=t)
{
tft.setCursor(20 + ics1, 60);
tft.setTextSize(3);
tft.setTextColor(ST7735_BLACK);
tft.print(to);
tft.setCursor(20 + ics1, 60);
tft.setTextSize(3);
tft.setTextColor(ST7735_MAGENTA);
tft.print(t);
to=t;
}


tft.setCursor(80 + ics1, 120);
tft.setTextSize(3);
tft.setTextColor(ST7735_BLUE);
tft.print("%");

double y1=-0.8*t+100;


tft.fillCircle(ics1,149,8,ST7735_RED);
tft.drawRect(ics1-2,y1, 5, 50+t,ST7735_RED);
tft.fillRect(ics1-2,y1, 5, 50+t,ST7735_RED);
tft.drawPixel(20,50,ST7735_RED);

}
 
Looks like you've got Tools > Boards set to Arduino Nano.

Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Nano, ATmega328"

Of course Serial1 is going to be undefined, since Nano doesn't have Serial1.

Change Tools > USB Type to the Teensy model you're using.
 
Status
Not open for further replies.
Back
Top