FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: eddi79 am 30 Mai 2017, 06:53:55

Titel: Arduino als IO Port schaltet nicht
Beitrag von: eddi79 am 30 Mai 2017, 06:53:55
Hallo zusammen,

habe gestern versucht meinen Arduino als IO Gerät an FHEM anzubinden.
So ist mein Stand:
Verbindung über configurable firmata und Ethernet.
Arduino uno mit EthernetShield.
IP Adresse eingetragen, IP von FHEM eingetragen, Firmate aufgespielt .
--> Arduino lässt sich unter seiner IP anpingen und wird in FHEM angezeigt (z.B. Version und Firmware kann über get abgefragt werden) Kommunikation scheint also zu passen.

Nun wollte ich versuchen einen IO-Pin anzusteuern. In FHEM bekomme ich keinen Fehler und ich kann den Pin über on / off schalten. Am Arduino tut sich jedoch nichts.

Hier mein Code:


define Arduino FRM 3030 global
define Firmata_OUT FRM_OUT 7
attr Firmata_OUT IODev Arduino
attr Firmata_OUT stateFormat value


Hab ich was übersehen (versuche das zum 1. Mal) ? Wie oft wird der Port aktualisiert ? 10 Sek, 60 sek oder ein paar ms ?

Steh grad voll am Schlauch und weiß nicht woran es liegen könnte.

Danke
Markus
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: Wzut am 30 Mai 2017, 09:33:54
Du schreibst leider nicht welche Version der ConfigurableFirmata du einsetzt.
Wenn du hier im Forum etwas nach Firmata suchst wirst du etliche Beiträge finden in denen es immer wieder um die Versionen zusammen mit FHEM geht. Die neueren machen Probleme, absolut stabil läuft bei mir seit Jahren die V 2.06
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: eddi79 am 30 Mai 2017, 12:30:39
Es ist die Version 2.09 bei mir. Möchte auch OneWire noch einbinden, ansonsten wäre mir die Version egal :-)

Nachtrag:
Hab jetzt 2.06 versucht, aber irgendwie klappt es nicht. Hat das jemand am Laufen und ggf. einen Auszug aus der config :-). Weiß einfach nicht was ich falsch mache ;-(

Danke
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: Wzut am 31 Mai 2017, 09:42:10
Bitte schön : feste IP und mit W5100 Ethernet
/*
* 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>

/*
* To execute Network Firmata on Yun uncomment Bridge.h and YunClient.h.
* Do not include Ethernet.h or SPI.h in this case.
* On Yun there's no need to configure local_ip and mac in the sketch
* as this is configured on the linux-side of Yun.
*/

//#include <Bridge.h>
//#include <YunClient.h>

#if defined ethernet_h || defined UIPETHERNET_H || defined _YUN_CLIENT_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,0,55)
//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. Is ignored on Yun
#define local_ip IPAddress(192,168,0,176)
//replace with ethernet shield mac. It's mandatory every device is assigned a unique mac. Is ignored on Yun
// const byte mac[] = {0xA1,0xB2,0xC3,0xD4,0xE5,0xF6};
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x0, 0x0 };
#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
#if defined AnalogOutputFirmata_h || defined ServoFirmata_h
#include <utility/AnalogWrite.h>
#endif

#if defined AnalogInputFirmata_h || defined I2CFirmata_h || defined EncoderFirmata_h
#include <utility/FirmataReporting.h>
FirmataReporting reporting;
#endif

// dependencies for Network Firmata. Do not comment out.
#ifdef NETWORK_FIRMATA
#if defined remote_ip && defined remote_host
#error "cannot define both remote_ip and remote_host at the same time!"
#endif
#include <utility/EthernetClientStream.h>
#ifdef _YUN_CLIENT_H_
YunClient client;
#else
EthernetClient client;
#endif
#if defined remote_ip && !defined remote_host
#ifdef local_ip
  EthernetClientStream stream(client,local_ip,remote_ip,NULL,remote_port);
#else
  EthernetClientStream stream(client,IPAddress(0,0,0,0),remote_ip,NULL,remote_port);
#endif
#endif
#if !defined remote_ip && defined remote_host
#ifdef local_ip
  EthernetClientStream stream(client,local_ip,IPAddress(0,0,0,0),remote_host,remote_port);
#else
  EthernetClientStream stream(client,IPAddress(0,0,0,0),IPAddress(0,0,0,0),remote_host,remote_port);
#endif
#endif
#endif

/*==============================================================================
* FUNCTIONS
*============================================================================*/

void systemResetCallback()
{
  // initialize a defalt state

  // pins with analog capability default to analog input
  // otherwise, pins default to digital output
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_ANALOG(i)) {
#ifdef AnalogInputFirmata_h
      // turns off pullup, configures everything
      Firmata.setPinMode(i, ANALOG);
#endif
    } else if (IS_PIN_DIGITAL(i)) {
#ifdef DigitalOutputFirmata_h
      // sets the output to 0, configures portConfigInputs
      Firmata.setPinMode(i, OUTPUT);
#endif
    }
  }

#ifdef FirmataExt_h
  firmataExt.reset();
#endif
}

/*==============================================================================
* SETUP()
*============================================================================*/

void setup()
{
#ifdef NETWORK_FIRMATA
#ifdef _YUN_CLIENT_H_
  Bridge.begin();
#else
#ifdef local_ip
  Ethernet.begin((uint8_t*)mac,local_ip);  //start ethernet
#else
  Ethernet.begin((uint8_t*)mac); //start ethernet using dhcp
#endif
#endif
  delay(1000);
#endif
  Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

#if defined AnalogOutputFirmata_h || defined ServoFirmata_h
  /* analogWriteCallback is declared in AnalogWrite.h */
  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
#endif

  #ifdef FirmataExt_h
#ifdef DigitalInputFirmata_h
  firmataExt.addFeature(digitalInput);
#endif
#ifdef DigitalOutputFirmata_h
  firmataExt.addFeature(digitalOutput);
#endif
#ifdef AnalogInputFirmata_h
  firmataExt.addFeature(analogInput);
#endif
#ifdef AnalogOutputFirmata_h
  firmataExt.addFeature(analogOutput);
#endif
#ifdef ServoFirmata_h
  firmataExt.addFeature(servo);
#endif
#ifdef I2CFirmata_h
  firmataExt.addFeature(i2c);
#endif
#ifdef OneWireFirmata_h
  firmataExt.addFeature(oneWire);
#endif
#ifdef StepperFirmata_h
  firmataExt.addFeature(stepper);
#endif
#ifdef FirmataReporting_h
  firmataExt.addFeature(reporting);
#endif
#ifdef FirmataScheduler_h
  firmataExt.addFeature(scheduler);
#endif
#ifdef EncoderFirmata_h
  firmataExt.addFeature(encoder);
#endif
#endif
  /* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  // Network Firmata communicates with Ethernet-shields over SPI. Therefor all
  // SPI-pins must be set to IGNORE. Otherwise Firmata would break SPI-communication.
  // add Pin 10 and configure pin 53 as output if using a MEGA with Ethernetshield.
  // No need to ignore pin 10 on MEGA with ENC28J60, as here pin 53 should be connected to SS:
#ifdef NETWORK_FIRMATA
  // ignore SPI and pin 4 that is SS for SD-Card on Ethernet-shield
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_SPI(i)
        || 4==i
        // || 10==i //explicitly ignore pin 10 on MEGA as 53 is hardware-SS but Ethernet-shield uses pin 10 for SS
        ) {
      Firmata.setPinMode(i, IGNORE);
    }
  }
//  pinMode(PIN_TO_DIGITAL(53), OUTPUT); configure hardware-SS as output on MEGA
  pinMode(PIN_TO_DIGITAL(4), OUTPUT); // switch off SD-card bypassing Firmata
  digitalWrite(PIN_TO_DIGITAL(4), HIGH); // SS is active low;

  // start up Network Firmata:
  Firmata.begin(stream);
#else
  // start up the default Firmata using Serial interface:
  Firmata.begin(57600);
#endif
  systemResetCallback();  // reset to default config
}

/*==============================================================================
* LOOP()
*============================================================================*/
void loop()
{
#ifdef DigitalInputFirmata_h
  /* DIGITALREAD - as fast as possible, check for changes and output them to the
   * stream buffer using Firmata.write()  */
  digitalInput.report();
#endif

  /* STREAMREAD - processing incoming messagse as soon as possible, while still
   * checking digital inputs.  */
  while(Firmata.available()) {
    Firmata.processInput();
#ifdef FirmataScheduler_h
    if (!Firmata.isParsingMessage()) {
      goto runtasks;
    }
  }
  if (!Firmata.isParsingMessage()) {
runtasks: scheduler.runTasks();
#endif
  }

  /* SEND STREAM WRITE BUFFER - TO DO: make sure that the stream buffer doesn't go over
   * 60 bytes. use a timer to sending an event character every 4 ms to
   * trigger the buffer to dump. */

#ifdef FirmataReporting_h
  if (reporting.elapsed()) {
#ifdef AnalogInputFirmata_h
    /* ANALOGREAD - do all analogReads() at the configured sampling interval */
    analogInput.report();
#endif
#ifdef I2CFirmata_h
    // report i2c data for all device with read continuous mode enabled
    i2c.report();
#endif
#ifdef EncoderFirmata_h
    // report encoders positions if reporting enabled.
    encoder.report();
#endif
  }
#endif
#ifdef StepperFirmata_h
  stepper.update();
#endif
#if defined NETWORK_FIRMATA && !defined local_ip &&!defined _YUN_CLIENT_H_
  if (Ethernet.maintain())
    {
      stream.maintain(Ethernet.localIP());
    }
#endif
}

Edit : noch ein Trick wenn der Compiler mit dem Sketch nicht durchläuft :
alle Module reinnehmen und Compiler starten, der bricht dann beim Uno ab wegen Speichermagel.
Dann die nicht benötigten Module so wie oben auskommentieren und wieder Compiler anwerfen. In der Regel läuft er dann durch.
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: eddi79 am 31 Mai 2017, 20:17:48
Vielen Dank erstmal.

Hab den Sketch compiliert. Vorher meine IP eingetragen usw. Hat alles funktionier.
Der Arduino wird auch gefunden und is pinbar.
In FHEM habe ich folgende Meldung:

Internals
CONNECTS

1
DEF
3030 global
DeviceName

3030
FD

5
NAME

Ardu
NOTIFYDEV

global
NR

4
NTFY_ORDER

50-Ardu
PORT

3030
STATE

Initialized
TYPE

FRM
firmware

ConfigurableFirmata.ino
firmware_version

V_2_06
Readings
error

Unhandled sysex command

2017-05-31 20:10:29


Der Error verundert ich... und dass keine IO-Ports angezeigt werden.
Schaffe es leider auch nicht einen Port zu schalten.

Nachdem ich einen IO folgendermaßen einrichte (hoffe das ist richtig):
# definiere FRM als IO-Device über Ethernet ('global' bindet an alle IP-Addressen des Servers)
define Ardu FRM 3030 global
#attr Ardu sampling-interval 99
define Ardu_OUT FRM_OUT 11
attr Ardu_OUT IODev Ardu

kommt wenn ich ihn schalten will folgenes:
pin '11' is not configured for mode 'INPUT' or 'OUTPUT' at FHEM/lib/Device/Firmata/Platform.pm line 465.

Die Version der Configurable Firmata ist: 2.06
(wie man oben sieht) und connected ist scheinbar.

Was könnte ich denn noch falsch machen bzw. noch versuchen.

Möchte ja nur 2 oder 3 IOPorts schalten und 4 OneWire Temperatursensoren DS1820 abfragen :-(.

LG
Markus
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: KernSani am 31 Mai 2017, 23:15:56
Wenn du hier nicht weiter kommst, könntest du es auch mal im "Sonstige Systeme" Forum versuchen (Button zum verschieben ganz unten links)
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: Wzut am 01 Juni 2017, 07:04:11
Zitat von: eddi79 am 31 Mai 2017, 20:17:48
Was könnte ich denn noch falsch machen bzw. noch versuchen.

Möchte ja nur 2 oder 3 IOPorts schalten und 4 OneWire Temperatursensoren DS1820 abfragen :-(.
Deine Fehlermeldung ist vollkommen in Ordnung , Pin 11 fällt unter SPI und ist daher tabu !
Da du keine Pins siehst , diese kannst du beim Uno für I/O und One Wire benutzen :
input_pins : 2,3,5,6,7,8,9,14,15,16,17,18,19
wie man sieht fehlt dort auch der Pin 4 , der steht dir ebenfalls nicht zur Verfügung da er CS für den SD Reader beim W5100 Shield ist
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: eddi79 am 01 Juni 2017, 08:38:24
Vielen Dank,
das hatte ich übersehen.
Hab dann nochmals compiliert und geflasht. Dann hat er die Pins angezeigt und ich kann jetzt auch schalten :-) :-)
Nun muss nur noch OneWire klappen, dann wär es perfekt. Da häng ich noch etwas... aber wird auch noch werden.

Danke für die Hilfe
Markus
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: Wzut am 01 Juni 2017, 10:07:57
OneWire lief bei mir bisher immer problemlos mit einem 4,7k Pullup Widerstand vom Datenpin nach 5V
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: eddi79 am 04 Juni 2017, 07:39:48
 :)Danke. Onewire klappt. Ist das schslten uber firmate wirklich zuverlassig oder kann es vorkommen dass ein pin als geschaltet in fhem gezeigt wird das relais jedoch nicht angesteuert wurde. Ich meine meldet der arduino das erfolgreiche schalten zurück oder nicht.
LG Markus
Titel: Antw:Arduino als IO Port schaltet nicht
Beitrag von: Wzut am 04 Juni 2017, 08:53:09
Zitat von: eddi79 am 04 Juni 2017, 07:39:48
meldet der arduino das erfolgreiche schalten zurück oder nicht.
da der Status aller IO übertragen wird : ja