Forum-Navigation
Forum-Breadcrumbs - Du bist hier:ForumProdukte: Produkt Supportencoder und lcd
Du musst dich anmelden um Beiträge und Themen zu erstellen.

encoder und lcd

Hallo allerseits

ich habe einen arduino uno und möchte einen encoder aus einem Drucker zu einer Längenanzeige mit lcd benutzen. Das Auslesen vom encoder funktioniert auch mit <encoder.h>.  Der serial monitor läuft auf 4076 hoch und wieder auf 0 runter.

Wenn ich den serial montior auf dem lcd anzeigen lasse, "spinnt" die Anzeige, serial und lcd zählen nicht mehr fehlerfrei und "verschlucken" encoderstreifen.

Das scheint ein bekanntes Problem zu sein, allerdings finde ich nirgends eine "gute" Lösung.

Gruß

Andreas

/* Encoder Library - NoInterrupts Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/

// If you define ENCODER_DO_NOT_USE_INTERRUPTS *before* including
// Encoder, the library will never use interrupts. This is mainly
// useful to reduce the size of the library when you are using it
// with pins that do not support interrupts. Without interrupts,
// your program must call the read() function rapidly, or risk
// missing changes in position.
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>

// #include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Beware of Serial.print() speed. Without interrupts, if you
// transmit too much data with Serial.print() it can slow your
// reading from Encoder. Arduino 1.0 has improved transmit code.
// Using the fastest baud rate also helps. Teensy has USB packet
// buffering. But all boards can experience problems if you print
// too much and fill up buffers.

// Change these two numbers to the pins connected to your encoder.
// With ENCODER_DO_NOT_USE_INTERRUPTS, no interrupts are ever
// used, even if the pin has interrupt capability
Encoder myEnc(A2, A1);
// avoid using pins with LEDs attached

void setup() {
Serial.begin(115200);
Serial.println("Basic NoInterrupts Test:");

lcd.begin();
lcd.backlight();

 

}

long position = -999;

void loop() {
long newPos = myEnc.read();
if (newPos != position) {
position = newPos;
Serial.println(position);
}

lcd.setCursor(0, 0);
lcd.print("Step: ");
lcd.setCursor(10, 0);
lcd.print(position);

 

 

// With any substantial delay added, Encoder can only track
// very slow motion. You may uncomment this line to see
// how badly a delay affects your encoder.
//delay(50);
}