Хелпикс

Главная

Контакты

Случайная статья





The code: Display the servo angle into a LCD



 

Практическая работа

 

Ардуино + Сервопривод + Дисплей

 

Попытка 1

 

 

The circuit works as same as an in the servo knob, only addition is an LCD interface to read out the position of the servo.

 

 

#include < Servo. h>

#include < LiquidCrystal. h>

 

Servo servo1;  

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potin;    

 

void setup ()

{

servo1. attach(9);

lcd. begin(16, 2);

lcd. print(" position=" );

}

 

void loop ()

{

potin = analogRead(A0);            

potin = map(potin, 0, 1023, 0, 180);     

servo1. write(potin);                  

delay(15);   

lcd. setCursor(9, 0);

lcd. print(potin);

lcd. print(" degree" );

}

 

https: //mechatrofice. blogspot. com/2015/06/servo-knob-position-control-with-LCD-display-interface-arduino. html

 

Попытка 2

 

http: //bentommy. blogspot. com. ee/2013/09/arduino-project-analog-pot-lcd-display. html

https: //www. youtube. com/watch? v=d48e1m4vXYQ

 

 

Arduino Project that reads a potentiometer (analog). Showing this on an LCD. The signal is between 0 and 1023. This translated into servo positions that are between 0 and 175 This also appears on the LCD's. Then the signal is send to an RC servo.

- Arduino UNO
- LCD Display HJ1602A
- potmeter
- Resistor to LCD 2. 2 KOhm

 


The code is not tested - if it not work let me know!


Arduinocode:

 


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

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott < http: //people. interaction-ivrea. it/m. rinott>

This example code is in the public domain.

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

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

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin


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

void setup() {
myservo. attach(9); // attaches the servo on pin 9 to the servo object
// set up the LCD's number of columns and rows:
lcd. begin(16, 2);
// Print a message to the LCD.
lcd. print(" Booting" );
delay(2000);
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):

// print the number of seconds since reset:

val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)

lcd. setCursor(0, 1); // set Cursor at place 1 (0) at line 2(1)
lcd. print(val); // Print value from potmeter to LCD
lcd. setCursor(3, 1); // set Cursor at place 4 (3) at line 2(1)
lcd. print(" Inn (0-1023)" ); // Print tekst on LCD

val = map(val, 0, 1023, 0, 175); // scale it to use it with the servo (value between 0 and 175)

lcd. setCursor(0, 0); // set Cursor at place 1 (0) at line 1(0)
lcd. print(val); // Print value from the servo to the LCD
lcd. setCursor(3, 1); // set Cursor at place 3 (2) at line 1(0)
lcd. print(" Servo (0-175)" ); // Print tekst on LCD


myservo. write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there

}

Попытка 3

 


Please don't ask if there are problems in the hardware, for the wirings are working (I've tested the other wires that are used in the working segments, the Arduino itself is working ( I've tested changing the pins) The 7 Segment display is working as I've tried changing one of the working output wires into the seems-to-be " not working" topmost segment. The breadboard is working, I've tried changing the position of the 7 segment display, and other 6 segments are working, leaving the segA or the topmost segment not working.

The code includes a servo motor and a 7 segment display. The setup works in a way that when the push button is HIGH in " IN", the 7 segment display decrements from 9 to one, one by one everytime the push button is hit. when the push button is HIGH in " OUT" the 7 segment display increments from one to 9, one by one everytime the push button is hit. I've got no problem with the mechanism, but I've got problems with the display of the digit, the topmost segment of the 7 segment display does not light up with any value. PLEASE HELPPP!!!!!
This is the code I've modified from Arduining. com

 


#include < Servo. h>
Servo myservo; // create servo object to control a servo

#define ServoM 12 //Connected to the servo motor.
#define Bright 11 //servo library disable PWM on pins 9 and 10.
#define Exit 9 //Pin connected to the EXIT button.
#define In 8 //Pin connected to the IN button.

#define BarLow 90 //Low position of the barrier.
#define BarUp 160 //Up position of the barrier.
#define CAPACITY 9 //Capacity of the parking lot.
#define INTEN 80 //Display intensity %

//Pins conections to segments (cathodes).
#define segA 0
#define segB 1
#define segC 2
#define segD 3
#define segE 4
#define segF 5
#define segG 6

//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
// pgfedcba < --- segments
B11000000, // number 0
B11111001, // number 1
B10100100, // number 2
B10110000, // number 3
B10011001, // number 4
B10010010, // number 5
B10000010, // number 6
B11111000, // number 7
B10000000, // number 8
B10010000 // number 9
};

void setup(){
myservo. attach(ServoM); // attaches the servo.

pinMode(Exit, INPUT); // set " EXIT" button pin to input
pinMode(In, INPUT); // set " IN" button pin to input
digitalWrite(Exit, HIGH); // Connect Pull-Up resistor.
digitalWrite(In, HIGH); // Connect Pull-Up resistor.
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(Bright, OUTPUT);
analogWrite(Bright, 255*INTEN/100);
myservo. write(BarLow); //Barrier in the low position
// delay(1000);
}

int Available= 9; // Number of places available.

//================================================================
void loop(){
Display(Available);
if(digitalRead(In)==0)
{
if(Available! = 0){
Available--;
myservo. write(BarUp);
delay(3000);
myservo. write(BarLow);
}
}
if(digitalRead(Exit)==0)
{
if(Available! = CAPACITY){
Available++;
myservo. write(BarUp);
delay(3000);
myservo. write(BarLow);
}
}
}

/*-------------------------------------------------------------------
Put the segments according to the number.
--------------------------------------------------------------------*/
void Display(int number){
byte segs = ~segments[number]; //" ~" is used for common anode.

digitalWrite(segA, bitRead(segs, 0) );
digitalWrite(segB, bitRead(segs, 1) );
digitalWrite(segC, bitRead(segs, 2) );
digitalWrite(segD, bitRead(segs, 3) );
digitalWrite(segE, bitRead(segs, 4) );
digitalWrite(segF, bitRead(segs, 5) );
digitalWrite(segG, bitRead(segs, 6) );
}

 

 

http: //forum. arduino. cc/index. php? topic=257800. 0

 

попытка 4

 

The code: Display the servo angle into a LCD

This example is already in biicode. You can create your project and open the block or copy the code into a . cpp file:

$ bii init my_arduino_project$ cd my_arduino_project$ bii open examples/servolcd

Check the code inside your block’s folder:



  

© helpiks.su При использовании или копировании материалов прямая ссылка на сайт обязательна.