10

I copied this program and am having trouble with the void downFrequency function (I think).

This is for Arduino Uno. Here are the compiler errors:

Compiling 'MY_dds' for 'Arduino Uno'

MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : stray '\342' in program
MY_dds.ino : stray '\200' in program
MY_dds.ino : stray '\223' in program
MY_dds.ino : : In function 'void downFrequency()':
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
Error compiling

Here is the program:

#include <stdio.h>
#include <dds.h>
#include <LiquidCrystal.h>

#define RESET 13
#define data_pin 12
#define load_pin A5
#define clock_pin A4
#define clock_hz 120000000LL
#define calibrationValue -0.0400000 // This is a value we change to calibrate
                                    // our particular chip more accurately
#define buttonPin A0

// chip, data_pin, load_pin, clock_pin, clock_hz
dds ddschip(DDS9850, data_pin, load_pin,  // Set my dds up with 120 MHz
            clock_pin, clock_hz);         // onboard crystal

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// Some variables to use in our program
long toFrequency = 14070000;
long currentFrequency;
long maxFrequency = 40000000;
long minFrequency = 0;
int incrementNumber = 6;
int maxprogramnumber = 6; // Don't forget to increase the menu numbers here!!
int programnumber = 1;

void setup()
{
  Serial.begin(9600);
  Serial.println("Beginning Setup");

  // Set up the LCD’s number of columns and rows:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("T.Robb V0.1b "); // Print a little message
  lcd.setCursor(0, 1);
  lcd.print(" DDS Sine wave ");
  delay(2000);

  // Set up pins
  pinMode(RESET, OUTPUT);
  pinMode(data_pin, OUTPUT);
  pinMode(load_pin, OUTPUT);
  pinMode(clock_pin, OUTPUT);
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);

  ddschip.calibrate(calibrationValue); // This is a value we change to calibrate
                                       // our particular chip more accurately
  ddschip.setfrequency(toFrequency);
  lcd.clear();
}

void loop()
{
  if(toFrequency >= maxFrequency)
  {
    (toFrequency = maxFrequency);
  }

  if(toFrequency <= minFrequency)
  {
    (toFrequency = minFrequency);
  }

  ddschip.setfrequency(toFrequency);
  currentFrequency = toFrequency;

  switch(incrementNumber)
  {
    case 0:
      Serial.println("increment amount is 1 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 1 Hz");
      break;

    case 1:
      Serial.println("increment amount is 10 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 10 Hz ");
      break;

    case 2:
      Serial.println("increment amount is 100 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 100 Hz ");
      break;

    case 3:
      Serial.println("increment amount is 1 000 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 1 kHz");
      break;

    case 4:
      Serial.println("increment amount is 10 000 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 10 kHz");
      break;

    case 5:
      Serial.println("increment amount is 100 000 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 100 kHz");
      break;

    case 6:
      Serial.println("increment amount is 1 000 000hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 1 MHz");
      break;

    default:
      Serial.println("increment amount is 100 Hz");
      lcd.setCursor(0, 0);
      lcd.print("Change By 100 Hz ");
      break;
  }

  lcd.setCursor(0, 1);
  lcd.print("Freq is "); // Print to LCD
  lcd.setCursor(8, 1);
  lcd.print(currentFrequency);

  Serial.println(incrementNumber); // Temporary for debugging delete me

  Serial.print("Current frequency is set to: ");
  Serial.println(currentFrequency);

  while((analogRead(buttonPin))>=1000) // Do nothing while no buttons pressed to chill out
  {
  }

  delay(5);
  if (analogRead(buttonPin)>=100 && analogRead(buttonPin) <= 200) // We have pushed up
  {
    upFrequency();
    delay(300);
  }

  if(analogRead(buttonPin)>=200 && analogRead(buttonPin) <= 400) // We have pushed down
  {
    downFrequency();
    delay(300);
  }

  if ((analogRead(buttonPin)) <= 50) // We have pushed right
  {
    incrementNumber++;
    delay(300);
  }

  if(analogRead(buttonPin) >= 400 && analogRead(buttonPin)<=600) // We have pushed left
  {
    incrementNumber–;
    delay(300);
  }

  if(incrementNumber > 6) // This is where the menu goes around and around
  {
    incrementNumber = 0;
  }
  if(incrementNumber < 0)
  {
    incrementNumber = 6;
  }

  delay(100);
  lcd.clear();
}

void upFrequency()
{
  Serial.println("Going UP Frequency");
  switch(incrementNumber)
  {
    case 0:
      toFrequency = (toFrequency + 1);
      break;

    case 1:
      toFrequency = (toFrequency + 10);
      break;

    case 2:
      toFrequency = (toFrequency + 100);
      break;

    case 3:
      toFrequency = (toFrequency + 1000);
      break;

    case 4:
      toFrequency = (toFrequency + 10000);
      break;

    case 5:
      toFrequency = (toFrequency + 100000);
      break;

    case 6:
      toFrequency = (toFrequency + 1000000);
      break;

    default:
      toFrequency = (toFrequency + 10);
      break;
  }

}


void downFrequency()
{
  Serial.println("Going DOWN Frequency");
  switch(incrementNumber)
  {
    case 0:
      toFrequency = (toFrequency – 1);
      break;

    case 1:
      toFrequency = (toFrequency – 10);
      break;

    case 2:
      toFrequency = (toFrequency – 100);
      break;

    case 3:
      toFrequency = (toFrequency – 1000);
      break;

    case 4:
      toFrequency = (toFrequency – 10000);
      break;

    case 5:
      toFrequency = (toFrequency – 100000);
      break;

    case 6:
     toFrequency = (toFrequency – 1000000);
     break;

    default:
      toFrequency = (toFrequency – 10);
      break;
  }

}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marc Howard
  • 101
  • 1
  • 1
  • 3
  • What is the name of the source file above, and what is the exact command that you are using to try and compile it ? – Paul R Sep 02 '13 at 12:16
  • 3
    When you say "copied", what do you mean? As in, perhaps, Ctrl-C from a PDF file? – trojanfoe Sep 02 '13 at 12:17
  • unable to compile lack of header files.LiquidCrystal.h,dds.h – Gangadhar Sep 02 '13 at 12:17
  • What kind of extension is `ino`? Shouldn't a source file have the extension `c`or `CC` so the compiler knows what language to expect? – Klas Lindbäck Sep 02 '13 at 12:19
  • Pual R: The source file is MY_dds.ino. Im pushing the Build Solution button of Atmel Studio with the Visual Micro plug-in to compile. – Marc Howard Sep 02 '13 at 12:25
  • trojanfoe: I did a right clik copy from a web page and the a control v to paste it into my Atmel Studio program. – Marc Howard Sep 02 '13 at 12:27
  • Well it looks like you've picked-up some spurious characters during the copy. Get a purer copy of the source and try again. – trojanfoe Sep 02 '13 at 12:28
  • Paul R: extension ino is used for Arduino microcontrollers – Marc Howard Sep 02 '13 at 12:29
  • 1
    Although in this case you did get an answer, please note for future reference: posting over 200 lines of poorly formatted code and expecting us to go through it to find a poorly specified error isn't nice. – Nik Bougalis Sep 02 '13 at 12:51
  • Yes the error was poorly specified because if I knew the error I would have corrected it myself. Blame the error codes - not me. – Marc Howard Sep 02 '13 at 13:03
  • This is a FAQ. The canonical question is *[Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332)*. All questions of this type can be analysed in exactly the same way: The sequence of numbers are (usually) octal. Convert them to hexadecimal and search for the UTF-8 sequence to find the Unicode [code point](https://en.wikipedia.org/wiki/Code_point). It can be searched directly (and replaced) by using regular expression search (in this case, using `\x{Unicodepoint}`) in text editors capable of search with regular expressions. – Peter Mortensen Aug 03 '21 at 22:26
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen May 23 '23 at 15:49

4 Answers4

23

You've somehow ended up with "en dash" characters, rather than normal minus signs, in the downFrequency function.

Make sure you're editing using a text editor, not a word processor; and for each of these:

toFrequency = (toFrequency – 1);
                           ^

delete the marked character, and retype as a normal minus sign.

(If you're interested in the gory details, the "dash" character is Unicode 2013, encoded in UTF-8 as three bytes with octal values 324,200,223, which is why you see those numbers in the error messages.)

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
13

The compiler is complaining that there are non-ASCII characters in your source file.

My octal fu is rusty, but it looks like UTF-8 to me. 342 200 223 is 0xE2 0x80 0x93 which is Unicode code point "EN DASH." This code was given a minus sign makeover by a text editor with a degree in cosmetology.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
5

Probably your double quote symbols (") were wrong. Please check if they are actually ", and not .

Siddhartha Ghosh
  • 2,988
  • 5
  • 18
  • 25
  • I too have encountered a same issue with ". – user-ag Apr 27 '15 at 06:39
  • Re *"Probably your double quote symbols (") were wrong"*: Nope. Only [EN DASH](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128), AKA Unicode code point U+2013 (nine instances). And a ***single*** [RIGHT SINGLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8212&number=128) AKA Unicode code point U+2019. They can be searched (and replaced) for by using the regular expressions `\x{2013}` and `\x{2019}`, respectively, in any modern text editor or IDE. Note: Different in Visual Studio Code (and probably others): `\u2013` (instead of `\x{2013}`) – Peter Mortensen May 23 '23 at 15:48
  • cont' - The single RIGHT SINGLE QUOTATION MARK is in comments (`// Set up the LCD’s number of columns and rows:`) and probably doesn't affect compilation. – Peter Mortensen May 23 '23 at 15:48
1

Simple copy always mess up the source code.

One can check the "stray" problem via cat -A yoursrc.c.

To me, I usually reformat the code by Vim in two steps.

vim yoursrc.c
:%!tr -cd '[:print:]\n'

Then compile, gcc yoursrc.c.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LinconFive
  • 1,718
  • 1
  • 19
  • 24