Pages: [1]   Go Down
Author Topic: Atmel Studio + Arduino and LiquidCrystal  (Read 3212 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
    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: and

Here is my code:

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.17 KB - downloaded 20 times.)
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Remove it and you should be fine.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 09, 2012, 03:07:00 pm by floresta » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, just realized you used double quotation instead of brackets

#include <LiquidCrystal.h>
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: