Go Down

Topic: Atmel Studio + Arduino and LiquidCrystal (Read 3932 times) previous topic - next topic

bonatius

Hi all,

I'm a beginner with Arduino and programming.

I have a problem. I want to use a LCD dispay (http://www.hobbytronics.co.uk/arduino-lcd-keypad-shield).
I wrote a program in Arduino enviroment:

Code: [Select]

/*
    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: http://www.youtube.com/watch?v=F74khQnh9pM&feature=relmfu&noredirect=1 and http://www.youtube.com/watch?v=qEcWR5EUNdk&feature=relmfu

Here is my code:

Code: [Select]

#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.

floresta

Quote
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

liudr

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

Remove it and you should be fine.

bonatius

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?

floresta

#4
Oct 09, 2012, 10:03 pm Last Edit: Oct 09, 2012, 10:07 pm by floresta Reason: 1
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

liudr

OK, just realized you used double quotation instead of brackets

#include <LiquidCrystal.h>

bonatius

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.

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)' 

floresta

Quote
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

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

liudr


@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.

dc42


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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

liudr


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.

floresta

"... 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

Go Up