[gelöst] FRM_ROTENC liefert keine Daten mehr

Begonnen von wkarl, 04 November 2014, 13:19:44

Vorheriges Thema - Nächstes Thema

wkarl

Hallo Norbert,

der Arduino UNO liefert mir sauber fünf Temperaturen (OneWire) und zwei Schaltzustände. Vor etlichen Wochen habe ich einen Keyes Rotationsgeber eingebunden. Anfänglich wurden auch Daten geliefert, dann nicht mehr. Um sicher zu gehen, dass es nicht der Rotationsgeber ist habe ich Ersatz bestellt (daher die lange Zeit). Aber auch der Ersatz verändert die Situation nicht positiv.
Folgenden sketch habe ich zum Testen des Rotationsgebers geladen:
/* interrupt routine for Rotary Encoders


   The average rotary encoder has three pins, seen from front: A C B
   Clockwise rotation A(on)->B(on)->A(off)->B(off)
   CounterCW rotation B(on)->A(on)->B(off)->A(off)

   and may be a push switch with another two pins, pulled low at pin 8 in this case
 

*/

// usually the rotary encoders three pins have the ground pin in the middle
enum PinAssignments {
  encoderPinA = 2,   // right (labeled DT on our decoder, yellow wire)
  encoderPinB = 3,   // left (labeled CLK on our decoder, green wire)
  clearButton = 4    // switch (labeled SW on our decoder, orange wire)
// connect the +5v and gnd appropriately
};

volatile unsigned int encoderPos = 0;  // a counter for the dial
unsigned int lastReportedPos = 1;   // change management
static boolean rotating=false;      // debounce management

// interrupt service routine vars
boolean A_set = false;             
boolean B_set = false;


void setup() {

  pinMode(encoderPinA, INPUT); // new method of enabling pullups
  pinMode(encoderPinB, INPUT);
  pinMode(clearButton, INPUT);
// turn on pullup resistors (old method)
  //digitalWrite(encoderPinA, HIGH);
// digitalWrite(encoderPinB, HIGH);
// digitalWrite(clearButton, HIGH);

// encoder pin on interrupt 0 (pin 2)
  attachInterrupt(0, doEncoderA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
  attachInterrupt(1, doEncoderB, CHANGE);

  Serial.begin(9600);  // output
}

// main loop, work is done by interrupt service routines, this one only prints stuff
void loop() {
  rotating = true;  // reset the debouncer

  if (lastReportedPos != encoderPos) {
    Serial.print("Index:");
    Serial.println(encoderPos, DEC);
    lastReportedPos = encoderPos;
  }
  if (digitalRead(clearButton) == LOW )  {
    encoderPos = 0;
  }
}

// Interrupt on A changing state
void doEncoderA(){
  // debounce
  if ( rotating ) delay (1);  // wait a little until the bouncing is done

  // Test transition, did things really change?
  if( digitalRead(encoderPinA) != A_set ) {  // debounce once more
    A_set = !A_set;

    // adjust counter + if A leads B
    if ( A_set && !B_set )
      encoderPos += 1;

    rotating = false;  // no more debouncing until loop() hits again
  }
}

// Interrupt on B changing state, same as A above
void doEncoderB(){
  if ( rotating ) delay (1);
  if( digitalRead(encoderPinB) != B_set ) {
    B_set = !B_set;
    //  adjust counter - 1 if B leads A
    if( B_set && !A_set )
      encoderPos -= 1;

    rotating = false;
  }
}

Dies liefert sauber die Rotationswerte.
Wenn ich die CONFIGURABLE_FIRMATA lade fällt mir noch was auf. Wenn ich mit get Temperaturwerte abfrage finde ich im log FRM Einträge. Bei get ... position nicht.

Kannst Du mir sagen wie ich hier weiter debuggen kann? Danke schon mal.

ciao walter
FHEM 5.7 & TabletUI 2.2 auf Fedora22 Server auf NUC5i5RYK
CUL 868 > FAST EnergyCam
HMLAN > HomeMatic TCs & VDs, Bewegungsmelder, Schalter, Taster, Steckdosen

ntruchsess

ohne Deine Konfiguration zu kennen, könnte ich da nur raten.

das Rotary-encoder-feature pushed die Daten immer dann, wenn der Encoder bewegt wird. Ein pull (wie bei 1-Wire) ist nicht vorgesehen. Würde auch wenig Sinn machen, weil der Encoder ja keine Absolutposition misst, sondern systematisch nur die Veränderung seiner Position erfasst.
while (!asleep()) {sheep++};

wkarl

Hallo Norbert,

hier meine Definition
#################################################
###### StellMischer
###### Fussbodenheizung
#################################################
define StellMischer_FH FRM_ROTENC 2 3
attr StellMischer_FH IODev FIRMATA
attr StellMischer_FH group Heizung
attr StellMischer_FH icon sani_floor_heating@black
attr StellMischer_FH room H-KG-Heizung
attr StellMischer_FH stateFormat position
attr StellMischer_FH verbose 5

ciao walter
FHEM 5.7 & TabletUI 2.2 auf Fedora22 Server auf NUC5i5RYK
CUL 868 > FAST EnergyCam
HMLAN > HomeMatic TCs & VDs, Bewegungsmelder, Schalter, Taster, Steckdosen

ntruchsess

#3
und der ConfigurableFirmata-sketch ist wie konfiguriert? Nur 1 Encoder, oder mehrere?
while (!asleep()) {sheep++};

wkarl

Hallo Norbert,

und hier die Config vom sketch:
/*
* Firmata is a generic protocol for communicating with microcontrollers
* from software on a host computer. It is intended to work with
* any host computer software package.
*
* To download a host software package, please click on the following link
* to open the download page in your default browser.
*
* http://firmata.org/wiki/Download
*/

/*
  Copyright (C) 2006-2008 Hans-Christoph Steiner.  All rights reserved.
  Copyright (C) 2010-2011 Paul Stoffregen.  All rights reserved.
  Copyright (C) 2009 Shigeru Kobayashi.  All rights reserved.
  Copyright (C) 2009-2013 Jeff Hoefs.  All rights reserved.
  Copyright (C) 2013 Norbert Truchsess. All rights reserved.
  Copyright (C) 2014 Nicolas Panel. All rights reserved.
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  See file LICENSE.txt for further informations on licensing terms.

  formatted using the GNU C formatting and indenting
*/


#include <Firmata.h>

/*
* by default Firmata uses the Serial-port (over USB) of Arduino.
* ConfigurableFirmata may also comunicate over ethernet using tcp/ip.
* To configure this 'Network Firmata' to use the original WIZ5100-based
* ethernet-shield or Arduino Ethernet uncomment the includes of 'SPI.h' and 'Ethernet.h':
*/

#include <SPI.h>
#include <Ethernet.h>

/*
* To configure 'Network Firmata' to use an ENC28J60 based board include
* 'UIPEthernet.h' (no SPI.h required). The UIPEthernet-library can be downloaded
* from: https://github.com/ntruchsess/arduino_uip
*/

//#include <UIPEthernet.h>

#if defined ethernet_h || defined UIPETHERNET_H
/*==============================================================================
* Network configuration for Network Firmata
*============================================================================*/
#define NETWORK_FIRMATA
//replace with ip of server you want to connect to, comment out if using 'remote_host'
#define remote_ip IPAddress(192,168,178,197)
//replace with hostname of server you want to connect to, comment out if using 'remote_ip'
//#define remote_host "server.local"
//replace with the port that your server is listening on
#define remote_port 3030
//replace with arduinos ip-address. Comment out if Ethernet-startup should use dhcp
//#define local_ip IPAddress(192,168,0,6)
//replace with ethernet shield mac. It's mandatory every device is assigned a unique mac
const byte mac[] = {0x90,0xA2,0xDA,0x0F,0x1C,0x81};
#endif

// To configure, save this file to your working directory so you can edit it
// then comment out the include and declaration for any features that you do
// not need below.

// Also note that the current compile size for an Arduino Uno with all of the
// following features enabled is about 22.4k. If you are using an older Arduino
// or other microcontroller with less memory you will not be able to include
// all of the following feature classes.

#include <utility/DigitalInputFirmata.h>
DigitalInputFirmata digitalInput;

#include <utility/DigitalOutputFirmata.h>
DigitalOutputFirmata digitalOutput;

//#include <utility/AnalogInputFirmata.h>
//AnalogInputFirmata analogInput;

//#include <utility/AnalogOutputFirmata.h>
//AnalogOutputFirmata analogOutput;

#include <Servo.h> //wouldn't load from ServoFirmata.h in Arduino1.0.3
//#include <utility/ServoFirmata.h>
//ServoFirmata servo;

#include <Wire.h> //wouldn't load from I2CFirmata.h in Arduino1.0.3
//#include <utility/I2CFirmata.h>
//I2CFirmata i2c;

#include <utility/OneWireFirmata.h>
OneWireFirmata oneWire;

//#include <utility/StepperFirmata.h>
//StepperFirmata stepper;

#include <utility/FirmataExt.h>
FirmataExt firmataExt;

#include <utility/FirmataScheduler.h>
FirmataScheduler scheduler;

#include <utility/EncoderFirmata.h>
EncoderFirmata encoder;


// dependencies. Do not comment out the following lines

ciao walter
FHEM 5.7 & TabletUI 2.2 auf Fedora22 Server auf NUC5i5RYK
CUL 868 > FAST EnergyCam
HMLAN > HomeMatic TCs & VDs, Bewegungsmelder, Schalter, Taster, Steckdosen

wkarl

Hallo Norbert,

nach langem Suchen habe ich nun erkannt, dass ich die falsche Version geladen hatte. D.h. die Version vom wiki (2.05). Ich weiß nicht wie oft ich das Forum durchgekämmt habe, aber erst heute habe ich die Information gefunden es gibt eine dev-Version 2.06. Dies genutzt und schon funktionierts :-o

Nun stell ich fest ROTENC zählt negativ die Rotation. Ich dachte das Tauschen der Pins von '2 3' auf '3 2' behebt dies, aber dem ist nicht der Fall.

Übersehe ich etwas (scheine Übung darin zu haben) oder muss ich mit (-1) multiplizieren?

Danke und ciao
walter
FHEM 5.7 & TabletUI 2.2 auf Fedora22 Server auf NUC5i5RYK
CUL 868 > FAST EnergyCam
HMLAN > HomeMatic TCs & VDs, Bewegungsmelder, Schalter, Taster, Steckdosen