Atmel Studio + Arduino and LiquidCrystal

Hi all,

I'm a beginner with Arduino and programming.

I have a problem. I want to use a LCD dispay (LCD Keypad Shield for Arduino).
I wrote a program in Arduino enviroment:

/*
    Keypad Shield 1602 LCD

  The circuit:
 * LCD RS pin to digital pin 8
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7
 * LCD BL pin to digital pin 10
 */

#include <LiquidCrystal.h>

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

void setup()
{
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Hello world");
}

void loop()
{
}

It works.

And now I have tried to do the same at the Atmel Studio, I have added a library for LCD dispaly (LiquidCrystal.h) at AVR/GNU C compiler
and at AVR/GNU C++ compiler.
I have set Atmel Studio by those videos: Tutorial Arduino + Atmel Studio 6 (Parte 1) - YouTube and Tutorial Arduino + Atmel Studio 6 (Parte 2) - YouTube

Here is my code:

#define F_CPU 16000000
#define ARDUINO 101
#include "Arduino.h"
#include "LiquidCrystal.h"

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

void setup()
{
        LiquidCrystal;  // here is probably a mistake
        lcd.clear();
        lcd.begin(16, 2);
        lcd.setCursor(0,0);
        lcd.print("Hello world");
        lcd.setCursor(0,1);
        lcd.print("Welcome");
}

void loop()
{

}

When I build this code, Atmel Studio write me:
Error 1 expected unqualified-id before '.' token

I think a problem is in void setup() part, I don't know what I have to do for correct function of this code.
At he attachment you find my project (1602LCD.rar).

Please, could you help me?

Thank you.

1602LCD.rar (14.2 KB)

Please, could you help me?

I can give you a very broad outline of your problem but one of the more experienced C programmers will have to fill in the (very large) blanks.

Basically the Arduino uses a combination of C and C++ as its code basis but the Arduino IDE does a lot of the background work for you, including generating the main() function which is required by every C program.

If you poke around enough in your Arduino folders you should be able to find the actual C program created by the Arduini IDE and compare that to your sketch to see some of what has happened.

When you use the AVR Studio IDE you must do all the background work yourself and use libraries that are supported by that environment. I do not think that the Arduino libraries fall into that category but even if they do you still have to tell the IDE where to find them.

Don

What do you intend to accomplish with the line you think is wrong?

Remove it and you should be fine.

to liudr: I removed and a I get five errors:
Error 1 undefined reference to LiquidCrystal::clear()' Error 2 undefined reference to LiquidCrystal::begin(unsigned char, unsigned char, unsigned char)'
Error 3 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)' Error 4 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)'
Error 5 undefined reference to `LiquidCrystal::LiquidCrystal(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

any help?

From reply #1:
"Basically the Arduino uses a combination of C and C++ as its code basis but the Arduino IDE does a lot of the background work for you, including generating the main() function which is required by every C program."

So, where is main() in your Atmel Studio version of the program?

"If you poke around enough in your Arduino folders you should be able to find the actual C program created by the Arduini IDE and compare that to your sketch to see some of what has happened."

Have you done this?

Don

OK, just realized you used double quotation instead of brackets

#include <LiquidCrystal.h>

Hi Don,

I understand what you mean, but I'm beginner with Arduino and C language. I don't know how to do it.

I poke in my Arduino folders, but I didn't the actual C program created by the Arduino IDE.
Something I do wrong.

Hi Liudr,

I did it, but I get the same errors:

Error 1 undefined reference to LiquidCrystal::clear()' Error 2 undefined reference to LiquidCrystal::begin(unsigned char, unsigned char, unsigned char)'
Error 3 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)' Error 4 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)'
Error 5 undefined reference to `LiquidCrystal::LiquidCrystal(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

I poke in my Arduino folders, but I didn't the actual C program created by the Arduino IDE.
Something I do wrong.

My information is based on the older versions of the IDE. Check out this (http://smileymicros.com/blog/2011/02/10/where-is-the-arduino-hex-file/) and see if it helps. He is looking for the 'hex' file but the 'cpp' file should be nearby. Don't forget that you have to look for the file before you close the IDE.

Don

@Liudr

Did you overlook the fact that he is trying to use the Arduino library from within Atmel Studio? Maybe (probably) I am the one who is confused.

Don

floresta:
@Liudr

Did you overlook the fact that he is trying to use the Arduino library from within Atmel Studio? Maybe (probably) I am the one who is confused.

Don

My mistake. I suppose a generic IDE will need #include <Arduino.h> as well, assuming all the library files are in library folders. Then you also need the main().

I recommend you open a sample code with Atmel Studio, make sure it compiles and works, then add code to it to try the liquid crystal library.

bonatius:
Hi Liudr,

I did it, but I get the same errors:

Error 1 undefined reference to LiquidCrystal::clear()' Error 2 undefined reference to LiquidCrystal::begin(unsigned char, unsigned char, unsigned char)'
Error 3 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)' Error 4 undefined reference to LiquidCrystal::setCursor(unsigned char, unsigned char)'
Error 5 undefined reference to `LiquidCrystal::LiquidCrystal(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

Those look like linker errors, meaning that your program has compiled OK but the object code library file for the LiquidCrystal library was not found. Either locate the object code library and add it to the linker input list in your AVR Studio project, or add the LiquidCrystal.cpp file to the list of source files in your project.

dc42:
Those look like linker errors, meaning that your program has compiled OK but the object code library file for the LiquidCrystal library was not found. Either locate the object code library and add it to the linker input list in your AVR Studio project, or add the LiquidCrystal.cpp file to the list of source files in your project.

I meant to say something like that but was incapable of expressing it in an accurate way like you did.

"... you still have to tell the IDE where to find them."
I think I did say something like that but didn't express it in an accurate way as you did.

Don