Platine für DoorPi-Projekt

Begonnen von farion, 07 Januar 2017, 10:15:14

Vorheriges Thema - Nächstes Thema

farion

Ja, Soundkarte, Amp und Nanohub kannst du auch ohne Arduino testen.

Den Raspi kannst du eigentlich auf beliebige Art mit Strom versorgen.

Das Einfachste ist den Raspi per MicroUSB mit Netzteil und die Platinen über den USB-A vom Raspi zu versorgen.
Alternativ sollte es auch gehen (falls dein Raspi die 5V auf USB-A einfach durchschleift) die Platinen direkt mit dem Netzteil zu versorgen und dann von dort den Raspi über den USB-A-Port zu versorgen (deswegen gibt es 2 Micro-USB). Das funktioniert aber soweit ich weiss nicht mit allen Raspis und hängt auch von der Einbausituation ab ... die erste Lösung ist sicher die Einfachere und mit weniger Risiko.

Gruss Frieder
Fhem5.8@Raspi3|~70xHomematic|KM271|1Wire|DoorPi mit DoorPiBoard|GarageDoorSingleButton|Graphite

Joker

Zitat von: farion am 30 Juni 2017, 13:59:10
Den Raspi kannst du eigentlich auf beliebige Art mit Strom versorgen.

Das Einfachste ist den Raspi per MicroUSB mit Netzteil und die Platinen über den USB-A vom Raspi zu versorgen.
Alternativ sollte es auch gehen (falls dein Raspi die 5V auf USB-A einfach durchschleift) die Platinen direkt mit dem Netzteil zu versorgen und dann von dort den Raspi über den USB-A-Port zu versorgen (deswegen gibt es 2 Micro-USB). Das funktioniert aber soweit ich weiss nicht mit allen Raspis und hängt auch von der Einbausituation ab ... die erste Lösung ist sicher die Einfachere und mit weniger Risiko.
Ja, bei mir hat nur die erstgenannte Variante funktioniert. Das Netzteil an der Adapterplatine anzuschließen und den Raspi über USB zu versorgen ging nicht... keine Ahnung woran das letztendlich liegt..?

farion

Nicht zu empfehlen ist übrigens mehrere Netzteile zu verwenden. Ich hatte da einige lustige Effekte, als der Strom mal teilweise aus meinem Notebook und teilweise aus einem eigenen Netzteil kam.
Fhem5.8@Raspi3|~70xHomematic|KM271|1Wire|DoorPi mit DoorPiBoard|GarageDoorSingleButton|Graphite

mcbo

Also die Micro-USB-Ports von der Adapter Platine sind die Einspeisung vom Nanohub?
Und an dem Nanohub ist die Soundkarte mit nachgeschalteten Verstärker, fest verdrahtet.

Dann könnte ich zum testen, die Platine am PC anstecken und die Soundkarte müsste gefunden werden?

Und eventuell auch noch den Verstärker testen?


Gruß

Marcel

Sailor

Hallo Frieder

generelle ganz blöde Frage:
Wenn ich alles zusammen verlöte, komplett bestücke, komplett richtig verdrahte,  inklusive jungfräulichem Arduino aufgesteckt, zerschieße ich mir doch nicht den Arduino, oder?

Ich frage nur deshalb, da man die Ausgänge des Arduino in PullUp oder PullDown States programmieren kann und mir die Standard-Werte nicht bekannt sind.

Ich habe vorgehabt den Arduino - jungfaeulich wie er ist - im eingebauten Zustand auf deine Hauptplatine erstmalig zu programmieren.
( Ich hoffe das funktioniert)  :o

Gruss
    Sailor
******************************
Man wird immer besser...

mcbo

Kurze Rückmeldung.

Soundtest = erfolgreich !!!

Habe einen Lautsprecher und ein Mikrofon an der Platine angeschlossen und das ganze am Windows-PC getestet.

Der Verstärker klingt mit der Soundkarte zusammen sehr gut, kein Rauschen !!!

Da bin ich erst einmal beruhigt, dass ich das Nanohub und die Soundkarte richtig verlötet habe.  :)


Gruß

Marcel

mcbo

Kann mir mal bitte jemand mit dem Arduino Sketch auf die Sprünge helfen?

Welche Libs habt Ihr eingebunden?
Ich habe die beiden hier eingebunden:

https://github.com/itead/ITEADLIB_Arduino_Nextion/blob/master/release_notes.md
https://github.com/PaulStoffregen/OneWire

Gibt es irgendwo eine fertige ino-Datei zum Download?

Ich habe mir den Code von Prof. Dr. Peter A. Henning, zusammen kopiert.
https://wiki.fhem.de/wiki/DoorPi_und_FHEM#Arduino_2

/*----------------------------------------------------------------------------------
Haustür

Prof. Dr. Peter A. Henning, April 2016

------------------------------------------------------------------------------------*/
#include <OneWire.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
// Make sure that in NexConfig.h nexSerial is configured properly !
#include "Nextion.h"

// Door Opener Subsystem
const int DoorOpen   =  8;  // output for door opening
const int LockState  =  6;  // output to indicate lock state
byte       softlock  =  0;
byte       hardlock  =  0;

// Security PIN
const int HardLock   =  5;  // input low = high security
String PIN           = "12345";
char   pin[10];
char   pindigit      =  ' ';
byte   pinctr        =  0;
long   pinMillis     =  0;
const int WrongID    =  7;  // indicator for false 1-Wire ID or PIN

// process variables
const int loopLED    = 13; // signal loop
byte phase           = 1;  // phase of test
long currentMillis   = 0;

// dimming
const int  Brightness  = A0;   // input pin for the dimming voltage
const int  Movement    = A1;   // input for movement detection
const int  DashDim     = 3;    // output for dimming further dashlights
const int  DashlightOn = 4;    // input pin for the dashlight signal
const long dimTimeout  = 60000;
byte       isDimmed   = 0;
long       dimMillis  = 0;    // timer


// 1-Wire subsystem
OneWire   ds(12);          // 1-Wire on pin 12 (a 4.7K resistor is necessary)
const int redLED     = 11; // LED on pins 9,10,11
const int greenLED   = 10;
const int blueLED    = 9;

typedef struct {
  char* name;
  byte  ROM[8];
  int   red;
  int   green;
  int   blue;
} iButton;

const byte iBnum = 7;     // Number of defined iButtons
const iButton iButtons[] = {
  {"iRed",   {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, HIGH},
  {"iRed*",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, HIGH},
  {"iGreen", {0x01, 00x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, HIGH, LOW, HIGH},
  {"iBlue",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, HIGH, HIGH, LOW},
  {"iOrange", {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, LOW, HIGH},
  {"iPink",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, LOW},
  {"iPurple", {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, LOW}
};

// GUI
NexPage page0     = NexPage(0, 0, "page0");
NexPage page1     = NexPage(1, 0, "page1");

NexButton  p0    = NexButton(0, 1, "p0");
NexPicture p1     = NexPicture(0, 2, "p1");

NexButton num0    = NexButton(1, 11, "b0");
NexButton num1    = NexButton(1, 2, "b1");
NexButton num2    = NexButton(1, 3, "b2");
NexButton num3    = NexButton(1, 4, "b3");
NexButton num4    = NexButton(1, 5, "b4");
NexButton num5    = NexButton(1, 6, "b5");
NexButton num6    = NexButton(1, 7, "b6");
NexButton num7    = NexButton(1, 8, "b7");
NexButton num8    = NexButton(1, 9, "b8");
NexButton num9    = NexButton(1, 10, "b9");
NexButton cancel  = NexButton(1, 12, "b10");
NexProgressBar progress  = NexProgressBar(1, 13, "j0");

NexTouch *nex_Listen_List[] =
{
  &num0, &num1, &num2, &num3, &num4,
  &num5, &num6, &num7, &num8, &num9,
  &cancel, &p0, NULL
};

void p0Callback(void *ptr)
{
  dimLight(100);
  softlock = 1;
  if ( hardlock == 0) {
    showLock();
  }
}

void num0PushCallback(void *ptr)
{
  pindigit = '0';
}

void num1PushCallback(void *ptr)
{
  pindigit = '1';
}

void num2PushCallback(void *ptr)
{
  pindigit = '2';
}

void num3PushCallback(void *ptr)
{
  pindigit = '3';
}

void num4PushCallback(void *ptr)
{
  pindigit = '4';
}

void num5PushCallback(void *ptr)
{
  pindigit = '5';
}

void num6PushCallback(void *ptr)
{
  pindigit = '6';
}

void num7PushCallback(void *ptr)
{
  pindigit = '7';
}

void num8PushCallback(void *ptr)
{
  pindigit = '8';
}

void num9PushCallback(void *ptr)
{
  pindigit = '9';
}

void CancelCallback(void *ptr)
{
  pinctr = 0;
  progress.setValue(0);
}


void setup() {

  String cmd;

  // set the digital pins as output:
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(loopLED, OUTPUT);
  pinMode(DoorOpen, OUTPUT);
  pinMode(WrongID, OUTPUT);
  pinMode(LockState, OUTPUT);
  pinMode(HardLock, INPUT_PULLUP);
  pinMode(DashlightOn, INPUT_PULLUP);

  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, HIGH);
  digitalWrite(blueLED, HIGH);
  digitalWrite(loopLED, LOW);
  digitalWrite(DoorOpen, HIGH);
  digitalWrite(WrongID, HIGH);
  digitalWrite(LockState, HIGH);

  // initialize the GUI
  nexInit();

  p0.attachPush(p0Callback, &p0);
  num0.attachPush(num0PushCallback, &num0);
  num1.attachPush(num1PushCallback, &num1);
  num2.attachPush(num2PushCallback, &num2);
  num3.attachPush(num3PushCallback, &num3);
  num4.attachPush(num4PushCallback, &num4);
  num5.attachPush(num5PushCallback, &num5);
  num6.attachPush(num6PushCallback, &num6);
  num7.attachPush(num7PushCallback, &num7);
  num8.attachPush(num8PushCallback, &num8);
  num9.attachPush(num9PushCallback, &num9);
  cancel.attachPush(CancelCallback, &cancel);

  //dimming
  dimLight(100);

  //showlock
  if ( digitalRead(HardLock) == LOW) {
    showLock();
    hardlock = 1;
    softlock = 0;
  } else {
    hideLock();
    hardlock = 0;
    softlock = 0;
  }
}


void openDoor(int level) {
  digitalWrite(DoorOpen, LOW);
  delay(1000);
  digitalWrite(DoorOpen, HIGH);
}


void wrongID() {
  digitalWrite(WrongID, LOW);
  delay(1000);
  digitalWrite(WrongID, HIGH);
}


void showLock() {
  sendCommand("vis p1,1");
}
void hideLock() {
  sendCommand("vis p1,0");
}


void dimLight(int level) {
  uint16_t dimVal;
  String cmd = "dim=";
  // zero level - determine from lighting conditions
  if ( (level == 0) && (digitalRead(DashlightOn) == HIGH) ) {
    dimVal = (uint32_t) analogRead(Brightness);
    dimVal = map(dimVal, 0, 1023, 0, 100);
    isDimmed = 1;
  // nonzero level - take as it is
  } else {
    dimVal = 100;
    isDimmed = 0;
  }
  cmd += dimVal;
  //dbSerialPrint(cmd);
  sendCommand(cmd.c_str());
  dimVal = map(dimVal, 0, 100, 0, 255);
  //dbSerialPrint(" -- ");
  //dbSerialPrintln(dimVal);
  analogWrite(DashDim,dimVal);
  dimMillis = millis();
}


void loop(void) {
  byte i;
  byte j;
  boolean equiv;
  byte iBfound;
  byte present = 0;
  byte addr[8];
  char* device;

  // new for each loop
  currentMillis = millis();
  digitalWrite(loopLED, HIGH);

  // dimming
  if ( isDimmed == 1 ) {
    if ( analogRead(Movement) < 10 ) {
       dimLight(100);
    }
     if ( digitalRead(DashlightOn) == LOW) {
        //dbSerialPrintln(" DashlightOn = LOW");
        dimLight(100);
     }
  }
  if ( (currentMillis - dimMillis) > dimTimeout) {
    dimLight(0);
  }

  // locking
  if ( digitalRead(HardLock) == LOW) {
    //change display only if hardlock has changed
    if ( hardlock == 0 ) {
      showLock();
    }
    hardlock = 1;
    softlock = 0;

  } else {
    //change display only if
    if ( (hardlock == 1) && (softlock == 0)) {
      hideLock();
    }
    hardlock = 0;
  }

  //lockState display
  if ( (hardlock == 0) && (softlock == 0)) {
    digitalWrite(LockState, HIGH);
  } else {
    digitalWrite(LockState, LOW);
  }

  //1-Wire bus access only in phase 1
  if ( phase == 1) {
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, HIGH);
    digitalWrite(blueLED, HIGH);

    if ( !ds.search(addr)) {
      present = 0;
      ds.reset_search();
      digitalWrite(loopLED, LOW);
      delay(250);

    } else {
      digitalWrite(loopLED, LOW);
      // Invalid 1-Wire ID
      if (OneWire::crc8(addr, 7) != addr[7]) {
      } else {
        dimLight(100);

        // the first ROM byte indicates which chip
        switch (addr[0]) {
          case 0x01:
            device = "DS2401";
            present++;
            for (i = 0; i < iBnum; i++) {
              equiv = true;
              for (j = 0; j < 7; j++) {
                if (iButtons[i].ROM[j] != addr[j]) {
                  equiv = false;
                  break;
                }
              }
              if (equiv ) {
                iBfound = i;
                break;
              }
            }

            if ( equiv ) {
              digitalWrite(redLED, iButtons[iBfound].red);
              digitalWrite(greenLED, iButtons[iBfound].green);
              digitalWrite(blueLED, iButtons[iBfound].blue);
              // LowSec state => open door
              if ( (hardlock == 0) && (softlock == 0)) {
                openDoor(1);
                delay(4000);
                return;
                // HiSec state => go to phase 2
              } else {
                phase = 2;
                pinMillis = millis();
                page1.show();
                return;
              }
              //sabotage ? Unknown iButton
            } else {
              digitalWrite(redLED, LOW);
              digitalWrite(greenLED, LOW);
              digitalWrite(blueLED, LOW);
              wrongID();
            }
            break;
          default:
            device = "unknown";
            break;
        }
        ds.reset();
      }
    }
  }
  nexLoop(nex_Listen_List);
  if ( phase == 2 ) {
    // check for timeout
    if ( (currentMillis - pinMillis) > 30000 ) {
      progress.setValue(0);
      phase = 1;
      pinctr = 0;
      page0.show();
    }
  }

  // phase 2 and GUI input is a number
  if ( (phase == 2) && ( pindigit != ' ') ) {
    // push this number to the PIN buffer
    pin[pinctr] = pindigit;
    pindigit = ' ';
    pinctr++;
    progress.setValue(pinctr * 20);
    // PIN is complete
    if ( pinctr == 5) {
      // PIN is correct => open door
      if ( String(pin) == PIN ) {
        openDoor(2);
        // wrong PIN
      } else {
        wrongID();
      }
      // return to phase 1
      progress.setValue(0);
      phase = 1;
      pinctr = 0;
      page0.show();
    }
  }
}


Wenn ich den Sketch kompiliere, bekomme ich folgenden Fehler in Zeile 66:
"unable to find numeric literal operator 'operator"" x'"

Prof. Dr. Peter Henning

Und wir sollen jetzt zählen, welche Zeile das ist ?

LG

pah

mcbo

Sorry !!!

diese Zeile ist rot

"{"iPurple", {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, LOW}"

58 const byte iBnum = 7;     // Number of defined iButtons
59 const iButton iButtons[] = {
60   {"iRed",   {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, HIGH},
61   {"iRed*",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, HIGH},
62   {"iGreen", {0x01, 00x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, HIGH, LOW, HIGH},
63   {"iBlue",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, HIGH, HIGH, LOW},
64   {"iOrange", {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, LOW, HIGH},
65   {"iPink",  {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, LOW},
66   {"iPurple", {0x01, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--}, LOW, HIGH, LOW}
67 };


mcbo

Oh, habe den Fehler gerade selbst gefunden.

Du hast in Deinem Beispiel keine gültige ID verwendet,
und ich bin darauf reingefallen  :-[

Damit geht es testweise weiter:

"{"iPurple", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, LOW, HIGH, LOW}"

Prof. Dr. Peter Henning

Soso - ich soll der Schuldige sein ?  >:( >:(

pah

mcbo

Das ging doch nicht gegen Dich !!!

Ich dachte, dass ich die falsche Bibliothek habe oder Fehler beim zusammen kopieren gemacht habe.    :-\

Zur Info, mein klassisches DoorPi funktioniert jetzt.
Also SIP mit Türöffnung.
Habe auch sehr gute Sprachqualität im Testaufbau.

Die Kamera werde ich heute noch testen.

Allerdings macht mir das Nextion im Zusammenspiel mit dem Arduino noch Probleme.

Um die Kommunikation per serieller Schnittstelle zwischen Display und Arduino zu testen,
habe ich mir mit Nextion Editor ein paar Buttons erzeugt.
Jeder Button soll einen anderen String senden (print "Test1" ...... ).

Das funktioniert auch per serieller Konsole zum PC.

Wie kann ich Deinen Sketch dazu überreden,
die Nextion Display-Kommunikation, auf dem Arduino "Seriellen Monitor"
auszugeben.

Ich wollte dazu einen "Serial.println(Variable);" verwenden.
Nur an welche Stelle, in Deinem Code?

Gruß

Marcel

Joker

#252
Mein Testaufbau ist auch soweit fortgeschritten, dass ich das Display testen wollte- aber da scheitere ich gerade.

Der Sketch scheint nicht auf Eingaben zu reagieren. Um Fehler in meinem Code auszuschließen habe ich mal eins der Examples von der ITEAD Library auf Display und Arduino gespielt (CompButton). Darauf ist ein einzelner Button mit einer Zahl drauf, und die sollte beim draufdrücken hochgezählt werden- tut sie aber nicht bei mir  :(

Daher ein paar prinzipielle Fragen:
- die Bezeichnung RX/TX ist laut Schaltplan schon auf der Platine gedreht, d.h. an der Buchse der Platine die mit RX beschriftet ist kommt auch RX vom Display hin und TX ebenso, richtig?
- da der Micro nur eine serielle Schnittstelle hat, ist es nicht möglich das Display zu betreiben und gleichzeitig Debug-Ausgaben zu haben, oder?
- im NexConfig.h habe ich "#define DEBUG_SERIAL_ENABLE" auskommentiert, sowie "#define nexSerial Serial" gesetzt, das sollte passen?
- wenn das Display was an den Arduino schickt, dann müsste doch eigentlich die RX-LED aufleuchten oder? Tut sie bei mir nicht...

Irgendwelche Ideen was nicht passen könnte?

Der Vollständigkeit halber hier das Testprogramm:
/**
* @example CompButton.ino
*
* @par How to Use
* Show how to use API of class NexButton. 
*
* @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date    2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/

#include "Nextion.h"

NexButton b0 = NexButton(0, 1, "b0");

char buffer[100] = {0};

NexTouch *nex_listen_list[] =
{
    &b0,
    NULL
};

void b0PopCallback(void *ptr)
{
    uint16_t len;
    uint16_t number;
    NexButton *btn = (NexButton *)ptr;
    dbSerialPrintln("b0PopCallback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr);
    memset(buffer, 0, sizeof(buffer));
    btn->getText(buffer, sizeof(buffer));
   
    number = atoi(buffer);
    number += 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);
   
    btn->setText(buffer);
}

void setup(void)
{   
    nexInit();
    b0.attachPop(b0PopCallback, &b0);
    dbSerialPrintln("setup done");
}

void loop(void)
{   
    nexLoop(nex_listen_list);
}

mcbo

@Joker

da sitzen wir ja im selben Boot  ;)

Exakt so bin ich auch vorgegangen.
Unzählige Testsketche probiert.

Mit der 2. seriellen Schnittstelle sollte es sicher keine Probleme geben,
da das Nextion direkt seriell kommuniziert und die Ausgabe des Arduino, USB-Seriell.

Haben wir eventuell eine falsche Library verwendet?

Funktioniert bei dier dir Displayausgabe mit einem USB-Seriell-Wandler, am PC?


Gruß

Marcel

Joker

Es ist immer dasselbe.  :P
Man schlägt sich ein paar Stunden um die Ohren, entschließt sich schließlich im Forum zu fragen und dann kurze Zeit später findet man plötzlich die Lösung selbst:

Der micro nutzt für die Kommunikation über die RX/TX Pins "Serial1". Entsprechend muss das define in der NexConfig.h (#define nexSerial Serial1) gesetzt sein.
Debug Ausgaben über der normale Serial was über USB geht sind trotzdem möglich.