Show Posts
|
|
Pages: [1]
|
|
4
|
Forum 2005-2010 (read only) / Interfacing / Help with Newhaven i2c LCD display
|
on: October 03, 2010, 04:50:41 pm
|
|
I am running a simple sketch to display captured analog values to am i2c NHD LCD.. and am getting unexpected results.. After about 5 minutes, the program writes the analog values at unpredictable locations. On occasions the write is not even numbers. It's almost as if the LCD clear and position is lost when the next write happens. The Arduino code is straight forward enough, I wonder if there is a problems with the i2c LCD display or the NHD i2c LCD library. See sketch code here. Appreciate your thoughts
#include <Wire.h> #include <LCDi2cNHD.h> #include <stdio.h> #include <stdlib.h>
LCDi2cNHD lcd=LCDi2cNHD(4, 20, 0x50>>1, 0);
int sensor1Pin = 1; // select the input pin for the potentiometer int sensor2Pin = 3; // select the input pin for the potentiometer int sensor1Value = 0; // variable to store the value from the sensor int sensor2Value = 0; // variable to store the value from the sensor int delayValue;
void setup() { lcd.init(); lcd.clear(); lcd.setCursor(0,0); lcd.print("ADC1.angle"); lcd.setCursor(1, 0); lcd.print("ADC2.angle"); pinMode(ledPin, OUTPUT); }
void loop() { char s[10]; float angle; // read the value from the sensor: sensor1Value = analogRead(sensor1Pin); sensor2Value = analogRead(sensor2Pin); angle=360.0*float(sensor1Value)/1024.0; dtostrf(angle, 5,2,s); lcd.setCursor(0,12); lcd.print(s);
angle=360.0*float(sensor2Value)/1024.0; dtostrf(angle, 5,2,s); lcd.setCursor(1,12); lcd.print(s); delay(100); }
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Interfacing / Re: Servo
|
on: October 03, 2010, 09:01:38 pm
|
|
There could be a few things messing you up.. Most servos I have fooled with do not like to be driven to their limits (min, max). Limit numbers are unique to each servo model and brand So you have to increase Min number and decrease Max number until your servo behaves. Heavier servos likely draw down more current (especially if you have a load on the servo)
In any case, I have attached a simple servo sweep code which works fine on my nano. Hopefully it will run on your board.. do vary the digital pin you connect the servo to.
Good luck!
PS> never mind the comments.. they are a carry over from the original sweep code.
#include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() { myservo.attach(12); // attaches the servo on pin 9 to the servo object } void loop() { for(pos = 50; pos < 150; pos++) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(25); // waits 15ms for the servo to reach the position } for(pos = 150; pos>50; pos--) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(25); // waits 15ms for the servo to reach the position } }
|
|
|
|
|