Author Topic: Arduino help  (Read 7787 times)

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Arduino help
« on: June 02, 2013, 01:01:43 PM »
Guys,
Just spent some of my har earned cash on an Arduino Mega and lcd board...

I'm trying ot get the lcd board to fire up...I've downloaded some code that's supposed to write to the Arduino and using the push buttons on the lcd shield alters the display...Trouble is I've placed the library files in the appropriate place but when I load and compile I get a load of errors, susbsequently it wont complie and upload to the Arduino...
So,
1) what am I doing wrong?
2) does anyone have any working code I can uplaod to test out the Arduino and lcd shield please?

Thanks
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #1 on: June 02, 2013, 09:21:07 PM »
John,

The libraries should go in a separate folder under the Libraries folder as in:

D:\arduino-1.0.5\libraries

I am pretty sure you can also import a library from a zip file which unzips the files and puts them in the same folder but I generally do it myself.

To use the library you need to make sure it is included. You can do this under the Sketch/Import Library menu.

All this does is add the appropriate #include statement to include the library header file(s).

Post a link to the board you have purchased. I think all you need to do is include the LiquidCyrstal Library with this statement

Code: [Select]
#include <LiquidCrystal.h>
Once a library is imported, the examples that come with it appear under the File/Examples menu. start by running that.

eg. File/Examples/LiquidCrystal/HelloWorld will give you this.

Code: [Select]
/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

You need to look at this statement

Code: [Select]
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

and make sure the pin definitions agree with your LCD display.

I would start with the LiquidCrystal examples and make sure that works before moving on. You may need to also turn the backlight on and stuff like that to begin with.
RodW
Brisbane, Australia

Offline DMIOM

  • Hero Member
  • *****
  • Posts: 676
  • Country: gb
  • Isle of Man
Re: Arduino help
« Reply #2 on: June 03, 2013, 03:14:01 AM »
John,

If it won't even compile, I'd try to simplify things; and in fact I'd suggest forget the LCD to start with.

Try and get it to compile, and then run, a program to flash an LED - that way you can prove the compile-load-run cycle.

Sample programs are available in the refererence section of the Arduino website  arduino.cc

I'd have a look at http://arduino.cc/en/Reference/DigitalWrite and try that example (you may need to change the pin number for the Mega's built-in LED).

One thing you need check which can cause compilation errors (if you haven't already done so) is to make sure the correct board type is chosen under the Tools | Board menu in the IDE

Dave

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #3 on: June 03, 2013, 03:16:46 AM »
Also check the USB port is setup correctly and the COM port number in the IDE agrees with what it actually is. There is a good tutorial on setting this all up on the Arduino web site.
RodW
Brisbane, Australia

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Arduino help
« Reply #4 on: June 03, 2013, 07:35:41 AM »
Ok, here's a bit more info...

The lcd file I was attempting to use is here: http://droboticsonline.com/ebaydownloads/LCD4Bit_mod.zip

When I attempt to compile it it wont without listing errors...Maybe some one can tell from that code what is going wrong?

I've identified my board in the IDE as a Mega2560, and is on COM4.
I've uploaded the blink test program,so I know that compiling and uploading works and my Arduino Mega works too......

The lcd shield I've got is supposed to be compatible with the Mega2560 but when plugged into the board all I get is a top line of blocks- this suggests to me that the lcd isn initalising properly, probably because the pin assignments are not set correctly...that I think I can sort...

I tend to think of myself as more of a hardware orientated person rather than a software type...
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #5 on: June 03, 2013, 08:11:40 AM »
It is good you know the environment is good and you can compile and upload a sketch.

This stuff is not plug and play. You have not told us which LCD you purchased. Is there a demo program for it? Did you get it from the same guys you bought the LCD shield from? That would be my next program to get going and note the pin assignments and the #include files before deviating to,other code.

If you are getting compile errors then the code is wrong. Also treat warnings as errors as they usually are. Look at the error messages and check the line numbers reported. Start at the first line and work through.  If you get a flood of errors maybe including variable not in scope or variable not defined, then you probably are missing some #includes or need to add a library.

Are there instructions on their web site? Do they have a forum? If so, ask there.  Also maybe ask on the Arduino forum.
RodW
Brisbane, Australia

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Arduino help
« Reply #6 on: June 03, 2013, 08:34:51 AM »
Rod,

I got the Mega 2560 from one supplier and the lcd shield from another...The sample code for the lcd is in the link in my previous post...

Looking at the lcd shield, the data pins appear to plug into the analogue pins on the Mega board rather than the digital pins...I'm wondering if the analog pins can be changed to digitals? I am thinking that this is not possible unlike pic micros...

I shall continue to play.. :)
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline Swarfing

  • Sr. Member
  • ****
  • Posts: 417
  • Country: gb
Re: Arduino help
« Reply #7 on: June 03, 2013, 03:12:34 PM »
Give this library a try as i had similar issue setting mine up yonks ago. A lot of the cheap LCD's are compatible with this, do a google on the display number LCD4884 and you will see what i mean. Hope it helps?
Once in hole stop digging.

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Arduino help
« Reply #8 on: June 03, 2013, 04:39:00 PM »
Oh...Deep Joy..........

Got it working... :D

The s/w I originally dowloaded was duff....
Went to the website of the lcd shield supplier and found a demo file..Copied that to wordpad then copied that as a sketch into the IDE..It compiled with no errors and when uploaded to the Mega worked first time....Yeeehaaa......  :clap: :clap:

I was beginning to think that pic micros were bad enough trying to learn ASM ( and BBC basic from all those years ago)...but AVR's....omg! even worse...

So, now I know my hardware is good I can go further..... :thumbup:

(All I wanted was to build a digital counter that will count wire turns for me when I rewind a rotor for a generator I'm sorting....Should have just bought a digital counter.. :Doh: but where's the fun in that?...)
« Last Edit: June 03, 2013, 05:13:40 PM by John Rudd »
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #9 on: June 03, 2013, 04:42:33 PM »
Great news even if I had to were wire a post I was half way through!
RodW
Brisbane, Australia

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Arduino help
« Reply #10 on: June 03, 2013, 05:15:00 PM »
Great news even if I had to were wire a post I was half way through!

were wire? :scratch:

Anyhow, thanks for your support and advice...

As Arnie says...'I'll be back'  :D
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #11 on: June 03, 2013, 09:33:19 PM »
Great news even if I had to were wire a post I was half way through!

were wire? :scratch:

Anyhow, thanks for your support and advice...

As Arnie says...'I'll be back'  :D

oops dyslexic fingers - I reworded my post full of useless advice  :coffee:
RodW
Brisbane, Australia

Offline Swarfing

  • Sr. Member
  • ****
  • Posts: 417
  • Country: gb
Re: Arduino help
« Reply #12 on: June 04, 2013, 02:06:34 PM »
John you still not said which lcd sheild you have?
Once in hole stop digging.

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Arduino help
« Reply #13 on: June 04, 2013, 03:11:53 PM »
John you still not said which lcd sheild you have?

Apologies...This one:

http://www.ebay.co.uk/itm/16x2-LCD-Screen-Keypad-Shield-1602-Blue-Arduino-lcd-Shield-UNO-MEGA-2560-UK-Fast-/290922513330?pt=UK_Sound_Vision_Other&hash=item43bc5543b2#ht_380wt_722

All working well...

Now working on compiling code to make a counter for rewinding my genny rotor :D
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline RodW

  • Full Member
  • ***
  • Posts: 120
  • Country: au
    • Vehicle Modifications Network
Re: Arduino help
« Reply #14 on: June 05, 2013, 02:03:02 AM »

Now working on compiling code to make a counter for rewinding my genny rotor :D

John,

Maybe read up on interrupts so that your main processing loop is interrupted by an ISR (interrupt Service Routine) to increment each pulse of the sensor rather than continuously poll for some action. This will require use of a specific port. Keep a count in a global variable in the ISR and let the loop() print the display.

So the ISR probably only has one line of code:

Code: [Select]
global_counter++;

Then the loop can print the count to the LCD at its leisure. If you print continuously,  the display I have flickers so I would set a time delay in milliseconds and only print it when the timer expires by using millis(), maybe every 50 to 200 milliseconds decided after a bit of experimenting.

However maybe an even better way would be to only print to the display if the global counter has changed.

Note this is not a complete example and may not compile without a bit of work on your part.

Code: [Select]

unsigned long global_counter = 0;
unsigned long last_reading = 0;

void counter()
{
    global_counter++;


setup()
{
  // remember to set up LCD;
  attachInterrupt(0, counter, RISING);
}

loop(){
  if(global_counter != last_reading){
    lcd.Print(global_counter);
    last_reading = global_counter;
  }
}
RodW
Brisbane, Australia