Arrrr .. duino :)

Hooray - my USB adaptor arrived this morning and within 1 hour of rigging up an Arduino compatible development board all sorts of cool things are happening! I decided to be a real cheapskate and build my Arduino myself rather than buy one. So it's all breadboarded and slightly rough looking, but on the plus side it works perfectly and I have another 9 AtMEGA8s sat around waiting for exciting things to happen to them.

Here's the obligatory YouTube video:

Showing the following:

  1. Reading an analogue value from a potentiometer
  2. Display that value on line 1 of LCD (in 4 bit nibble mode)
  3. Display the same value using a bar graph type output on line 2 of LCD
  4. Use the value to also set position of a servo.

All in Arduino's lovely C type syntax:

#include <lcd4bit.h>
#include <servo.h>

LCD4Bit lcd = LCD4Bit(2);
Servo servo1;

int potPin = 0;
int servoPin = 12;
int val = 0;

void setup() {
  lcd.init();
  servo1.setMaximumPulse(2200);
  servo1.attach(servoPin);
}

void loop() {
  val = analogRead(potPin);
  char buf[12];
  itoa(val, buf, 10);

  // Print 1st line
  lcd.cursorTo(1, 0);
  lcd.printIn("Value: ");
  lcd.printIn(buf);
  lcd.printIn("   ");

  // Print 2nd line
  lcd.cursorTo(2, 0);
  int steps = 255/16;

  for (int i=0; i<16; i++) {
    if ((val/4) > (steps*i)) {
      lcd.print(0xFF);
    } else {
      lcd.printIn(" ");
    }
  }

  // Keep positioning the servo while waiting to update the LCD
  for (int x=0; x<50; x+=2) {
    val = analogRead(potPin);
    servo1.write(val/6);
    Servo::refresh();
    delay(2);
  }
}

So easy! I am finished with trying to do PIC development on my Mac on a tight budget.

Stu (not verified) on January 21st 2008

For instructions on installing libraries, I would refer you to the Arduino site (http://www.arduino.cc/en/Main/Libraries) where I'm sure they do a better job of explaining it than I could. Similarly, the servo library is on the arduino site in the Playground (http://www.arduino.cc/playground/ComponentLib/Servo). In fact, if you're new to the Arduino then I recommend that you take some time peruse the main site including the Playground - it's a fantastic resource!

Oliver H (not verified) on January 20th 2008

Where do I put the "lcd4bit.h" file also where is the "servo.h" file Thanks Oliver

Stu (not verified) on January 20th 2008

Oliver, did you install the LCD library? http://www.arduino.cc/playground/Code/LCD4BitLibrary

Oliver H (not verified) on January 20th 2008

When I try to compile the code I get the following message: 21: error: lcd4bit.h: No such file or directory In function 'void setup()': In function 'void loop()': Does anyone have a reason for this. Thnks Oliver P.S. I am very new to the Arduino.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <code> <cite> <strike> <caption>
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.