jp112sdl / Beispiel_AskSinPP

88 stars 36 forks source link

HM-Sen-LI-O (mit BH1750) #35

Closed aquadrat2217 closed 4 years ago

aquadrat2217 commented 4 years ago

Hi,

vielen Dank für die gute Anleitung und Firmware, aber ich komme nicht weiter. Installation und anlernen an die CCU hat alles wunderbar funktioniert, aber es werden nur 0 lux angezeigt. Ich verwende den BH1750 und der addr Pin liegt auf GND. Starte ich so den Arduino sieht es folgendermaßen aus :

AskSin++ V4.1.1 (Nov 14 2019 19:59:41)
Address Space: 32 - 77
CC init1
CC Version: 17
 - ready
iVcc: 4693
TX Delay = 8
Measure... 

bei "Measure" geht es nicht weiter.

Lege ich den addr auf VCC kommt folgendes:

AskSin++ V4.1.1 (Nov 14 2019 19:59:41)
[BH1750] ERROR: received NACK on transmit of address
Address Space: 32 - 77
CC init1
CC Version: 17
 - ready
iVcc: 4693
TX Delay = 8
Measure... 0 lux
<- 0F 01 84 53 34FD01 000000 00 C1 00 00 00 00  - 1344
<- 0E 02 86 10 34FD01 000000 06 01 00 00 00  - 1443
TX Delay = 8

Er zeigt an, dass die Adresse falsch ist, aber das Programm läuft weiter.

Ich habe auch schon den Beispielsketch von BH1750.h eingespielt und dies funktioniert ohne Probleme.

Hat jemand eine Idee wo das Problem liegt?

VG Andreas

jp112sdl commented 4 years ago

Hi, ich kann dir da leider nicht weiterhelfen, da ich keinen BH1750 mehr zum Testen habe.

aquadrat2217 commented 4 years ago

Hi, das gleiche Problem habe ich auch mit dem Tsl2561. Es wird nur 0 lux angezeigt.

jp112sdl commented 4 years ago

Hast du auch alle Stellen im Code auf den jeweiligen Sensor angepasst? Hab doch noch nen BH1750 in der letzten Ecke gefunden und es funktioniert mit diesem auf Anhieb.

aquadrat2217 commented 4 years ago

Hi,

das ist komisch, welche Arduino IDE und AVR Board Version verwendest du? Ich habe IDE 1.8.10 und AVR 1.8.1

VG Andreas

jp112sdl commented 4 years ago

Nehme ich auch.

Daher eher die Vermutung, du hast nicht alle Stellen im Code erwischt, die umzustellen sind.

aquadrat2217 commented 4 years ago

Ich habe 5 Zeilen geändert und mit der Suchfunktion gearbeitet. Es gibt keine Zeile mehr mit BH1750. Wenn die richtige Sensoradresse eingestellt ist, bleibt das Programm bei Maesure... stehen.

jp112sdl commented 4 years ago

Dann weiß ich auch nicht weiter. Hier ist der Sketch mit dem es bei mir auf Anhieb geht:

//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>
#include <Register.h>
#include <sensors/Bh1750.h>
//#include <sensors/Tsl2561.h>
//#include <sensors/Max44009.h>

#include <MultiChannelDevice.h>

// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8

// number of available peers per channel
#define PEERS_PER_CHANNEL 6

//seconds between sending messages
byte _txMindelay = 0x08;

// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
  {0x34, 0xfd, 0x01},     // Device ID
  "JPLIO00001",           // Device Serial
  {0x00, 0xfd},           // Device Model
  0x01,                   // Firmware Version
  0x53, // Device Type
  {0x01, 0x00}            // Info Bytes
};

/**
   Configure the used hardware
*/
typedef AvrSPI<10, 11, 12, 13> SPIType;
typedef Radio<SPIType, 2> RadioType;
typedef StatusLed<LED_PIN> LedType;
typedef AskSin<LedType, BatterySensor, RadioType> BaseHal;
class Hal : public BaseHal {
  public:
    void init (const HMID& id) {
      BaseHal::init(id);
      // measure battery every 1h
      battery.init(seconds2ticks(60UL * 60), sysclock);
      battery.low(22);
      battery.critical(19);
    }

    bool runready () {
      return sysclock.runready() || BaseHal::runready();
    }
} hal;

DEFREGISTER(LiReg0, MASTERID_REGS, DREG_CYCLICINFOMSGDIS, DREG_LOCALRESETDISABLE, DREG_INTKEY)
class LiList0 : public RegList0<LiReg0> {
  public:
    LiList0 (uint16_t addr) : RegList0<LiReg0>(addr) {}
    void defaults () {
      clear();
      //cyclicInfoMsgDis(0);
      // intKeyVisible(false);
      // localResetDisable(false);
    }
};

DEFREGISTER(LiReg1, CREG_AES_ACTIVE, CREG_TX_MINDELAY, CREG_TX_THRESHOLD_PERCENT)
class LiList1 : public RegList1<LiReg1> {
  public:
    LiList1 (uint16_t addr) : RegList1<LiReg1>(addr) {}
    void defaults () {
      clear();
      aesActive(false);
      txMindelay(8);
      //txThresholdPercent(0);
    }
};

class LuxEventMsg : public Message {
  public:
    void init(uint8_t msgcnt, uint32_t lux) {
      Message::init(0xf, msgcnt, 0x53, RPTEN | BCAST, 0x00, 0xc1);
      pload[0] = (lux >> 24)  & 0xff;
      pload[1] = (lux >> 16) & 0xff;
      pload[2] = (lux >> 8) & 0xff;
      pload[3] = (lux) & 0xff;
    }
};

class LuxChannel : public Channel<Hal, LiList1, EmptyList, List4, PEERS_PER_CHANNEL, LiList0>, public Alarm {

    LuxEventMsg   lmsg;
    uint32_t      lux;
    uint16_t      millis;

    Bh1750<>     bh1750;
    //Tsl2561<>                   tsl2561; // Brücke zwischen L und GND
    //Tsl2561<TSL2561_ADDR_HIGH>  tsl2561; // Brücke zwischen H und GND
    //Tsl2561<TSL2561_ADDR_FLOAT> tsl2561; // keine Brücke gesetzt
    //MAX44009<>                  max44009;

    uint8_t last_flags = 0xff;

  public:
    LuxChannel () : Channel(), Alarm(5), lux(0), millis(0) {}
    virtual ~LuxChannel () {}

    // here we do the measurement
    void measure () {
      DPRINT("Measure... ");
      bh1750.measure();
      lux = bh1750.brightness();
      //tsl2561.measure();
      //lux = tsl2561.brightness();
      //max44009.measure();
      //lux = max44009.brightness();
      DDEC(lux);
      DPRINTLN(" lux");
    }

    uint8_t flags () const {
      uint8_t flags = this->device().battery().low() ? 0x80 : 0x00;
      return flags;
    }

    virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
      uint8_t msgcnt = device().nextcount();
      // reactivate for next measure
      tick = delay();
      clock.add(*this);

      measure();

      if (last_flags != flags()) {
        this->changed(true);
        last_flags = flags();
      }

      lmsg.init(msgcnt, lux * 100);
      device().sendPeerEvent(lmsg, *this);
    }

    uint32_t delay () {
      _txMindelay = this->getList1().txMindelay();
      DPRINT("TX Delay = ");
      DDECLN(_txMindelay);
      return seconds2ticks(_txMindelay);
    }

    void setup(Device<Hal, LiList0>* dev, uint8_t number, uint16_t addr) {
      Channel::setup(dev, number, addr);
      sysclock.add(*this);
      bh1750.init();
      //tsl2561.init();
      //max44009.init();
    }

    uint8_t status () const {
      return 0;
    }
};

typedef MultiChannelDevice<Hal, LuxChannel, 1, LiList0> LuxType;

LuxType sdev(devinfo, 0x20);
ConfigButton<LuxType> cfgBtn(sdev);

void setup () {
  DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
  buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
  sdev.initDone();
}

void loop() {
  bool worked = hal.runready();
  bool poll = sdev.pollRadio();
  if ( worked == false && poll == false ) {
    if ( hal.battery.critical() ) {
      hal.activity.sleepForever(hal);
    }
    hal.activity.savePower<Sleep<>>(hal);
  }
}
jp112sdl commented 4 years ago

P.S.: Der ADDR-Pin am BH1750 ist bei mir not connected.

aquadrat2217 commented 4 years ago

Der Sketch funktioniert auch nicht. Das gleiche Fehlerbild. Dann kann es ja nur an der Hardware liegen. Oder kannst du mir dein Hex-File schicken? Damit könnte ich es nochmal probieren. Evtl. Passt eine Library nicht.

jp112sdl commented 4 years ago

Probier mal. HM-Sen-LI-O.with_bootloader.hex

aquadrat2217 commented 4 years ago

Immer noch das gleiche Problem. So sieht die Ausgabe aus:

`AskSin++ V4.1.1 (Nov 18 2019 15:37:54) Address Space: 32 - 77 CC init1 CC Version: 17

Baudrate ist auf 115200. Ist das richtig?

jp112sdl commented 4 years ago

Nein. 57600 muss es sein. Wenn die Ausgabe bei 115200 kommt, hast du einen Pro Mini mit 16MHz. Da stimmt das ganze Timing nicht mehr

aquadrat2217 commented 4 years ago

ach, da liegt das Problem. Ich habe es auf einen Arduino nano geflasht. Dann muss ich mir einen Pro mini mit 8 MHz besorgen. Oder kann man es für einen Nano umbauen?

jp112sdl commented 4 years ago

Oder kann man es für einen Nano umbauen?

Keine Ahnung, nie damit beschäftigt. Die AskSin++ Projekte sind alle für den 8MHz Pro Mini gebaut, allein schon wegen der 3.3V Pegel. Abgesehen von den 16MHz deines Nano hat der ja auch 5V Pegel an den Pins.

Xento commented 4 years ago

Es sollte reichen, wenn man in der IDE den Nano auswählt als Board. Dann sollte die richtige Frequenz eingestellt sein usw. Was man dann noch bedenken muss, ist der 5V Pegel.

Am Mo., 18. Nov. 2019 um 18:55 Uhr schrieb Jérôme <notifications@github.com

:

Oder kann man es für einen Nano umbauen?

Keine Ahnung, nie damit beschäftigt. Die AskSin++ Projekte sind alle für den 8MHz Pro Mini gebaut, allein schon wegen der 3.3V Pegel. Abgesehen von den 16MHz deines Nano hat der ja auch 5V Pegel an den Pins.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jp112sdl/Beispiel_AskSinPP/issues/35?email_source=notifications&email_token=AAJ5HROP4DKEY2FFHDYYJSTQULJHPA5CNFSM4JOKXXX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEELKO3A#issuecomment-555132780, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ5HRJJNAB7NA22ANOJC33QULJHPANCNFSM4JOKXXXQ .

aquadrat2217 commented 4 years ago

Hallo,

also es lag am Arduino, mit dem pro mini mit 8 MHz funktioniert es ohne Probleme. Danke für die Unterstützung.

VG Andreas