NixeTubesShieldNCS314 icon indicating copy to clipboard operation
NixeTubesShieldNCS314 copied to clipboard

Is it possible to turn the bulbs off in software?

Open SapientHetero opened this issue 4 years ago • 12 comments

I'd like to integrate a PIR sensor with a NCS314 V2.2 in order to extend bulb life by turning them off when nobody is in the room to see them. Is there any way to do this in software?

SapientHetero avatar Oct 07 '20 14:10 SapientHetero

Hello.

We have a Hardware pinout and logic on the Board for the PIR sensor. However we did not implemented its usage in the Software (Firmware). One of our buyers have implemented several similar functions in our Firmware as a mods. Please use link below to his blog and ask him for code and other info: https://www.buildxyz.xyz/nixieclock-build-guide/

This blog should be useful to you. Write back if there will be any other questions.

Regards.

ср, 7 окт. 2020 г. в 17:30, Sapient Hetero [email protected]:

I'd like to integrate a PIR sensor with a NCS314 V2.2 in order to extend bulb life by turning them off when nobody is in the room to see them. Is there any way to do this in software?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/afch/NixeTubesShieldNCS314/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAROBMWBROT6THP3XPCUIJTSJR3PLANCNFSM4SHPIA3A .

-- Alexey [GRA & AFCH]

afch avatar Oct 08 '20 08:10 afch

https://github.com/afch/NixeTubesShieldNCS314/blob/master/Firmware/Source%20code/Hardware%20Version%202.0%20(HW2.0)/NixieClockShield_NCS314/doIndication314_HW2.x.ino#L79-L82

https://github.com/afch/NixeTubesShieldNCS314/blob/master/Firmware/Source%20code/Hardware%20Version%202.0%20(HW2.0)/NixieClockShield_NCS314/doIndication314_HW2.x.ino#L103-L106

You can turn off the bulbs by writing 0's into these.

h3xcat avatar Oct 09 '20 02:10 h3xcat

https://github.com/afch/NixeTubesShieldNCS314/blob/adb9bca8aa63063cb1de16f8eab42e1fc1e984dd/Firmware/Source%20code/Hardware%20Version%202.0%20(HW2.0)/NixieClockShield_NCS314/doIndication314_HW2.x.ino#L108

Write this variable LOW and they shut off.

Delorean14 avatar Jan 21 '21 08:01 Delorean14

Can you shed more light (information) on the logic / pinout for a PIR sensor on the NCS314 board (I have v3.4) that you refer to. I note from the board schematic that pin D8 is not used by the shield and potentially could be used to connect a PIR sensor. I was thinking of using this to set BL (SHDN) on pin D5 “LOW” when the sensor did not detect any motion for a period, which would turn off the high voltage to all of the tubes, but there is probably a more elegant way of accomplishing this. The link you suggested to another customer didn’t really help me with this as much as I had hoped.

regorwislon avatar Feb 21 '23 07:02 regorwislon

I ended up switching from the PIR sensor to an ultrasonic sensor: https://www.amazon.com/HiLetgo-HC-SR04-Ultrasonic-Distance-MEGA2560/dp/B00E87VXH0/ref=sr_1_9?crid=3RQ8SC81A2C1C&keywords=proximity+sensor&qid=1676989931&sprefix=proximity+sensor%2Caps%2C110&sr=8-9 because the PIR sensor kept detecting the airflow from air conditioning vents in the ceiling and no filter algorithm I tried could reject it well enough while still sensing human presence. These aren’t perfect either but they’re better than the PIR sensors.

// Proximity Sensor – note that it also needs power and ground
#define TRIGGER_PIN  23   // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     25   // Arduino pin tied to echo pin on the ultrasonic sensor.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

Here's the code I use with the sensor

// ***** Handle Peeking - detect/extend/end peek mode

  // Starting peek mode in response to ultrasonic sensor
  // If object is detected within configured distance while bulbs are off (sleeping), turn bulbs on in dimmed mode (set elsewhere) for the configured period of time.
  // If daytime, leave them on as long as object is detected
  if (sleeping) {

    if (Settings.alarmBulbsOnDuration && alarmRinging) {               // if configured to do so...
      if (!peekStart)                                                  //  and not already peeking...
        peekStart = millis();                                          //  enter Peek mode on alarm...
      peekDuration = Settings.alarmBulbsOnDuration;                    //  for the configured period of time.
      sleeping = false;                                                //  turn sleeping off when alarm sounds so bulbs turn on
      dimming = false;                                                 //  turn off dimming so PWM doesn't distort alarm music
      RGBLedsOn = Settings.RGBLedsOn;                                  //  and restore RGB LEDs to previous setting
      //DEBUG_PRINTLN(F("Entering peek mode due to alarm"));
    }

    // while waiting for peeking to end, just disable sleeping
    if (peekStart > 0 && (millis() - peekStart < (uint32_t)peekDuration * 1000UL)) { // leave bulbs on if in peek mode...
      sleeping = false;
    }

    // check for sonar ping indicating peeking should start or be extended
    if (millis() - lastSonarPingTime > SONAR_READ_INTERVAL &&                // only do pings at specified interval...
        !ESPTransactionInProgress) {                                         //  and NOT when a transaction is in progress or Serial3 data will be lost
      lastSonarPingTime = millis();                                          // don't ping too often or processor becomes sluggish
      uint16_t maxDistance = (uint16_t)Settings.dayPeekDistance;             // if not dimming, activate sonar at max distance
      if (dimming)                                                           // at night, activate only when sensor is triggered at configured distance
        maxDistance = Settings.peekDistance;
      if (alarmRinging)
        maxDistance = Settings.peekDistance;                        // if alarm is ringing, turn it off if hand is waved in front of sensor
      maxDistance = maxDistance*2 + maxDistance/2;                           // convert maxDistance to cm from inches, roughly
      uint32_t distance = sonar.ping_in(maxDistance);                        // do a ping
      if (distance > 0 && distance <= maxDistance) {                         // if distance is zero, there was no detection, otherwise...
        if (alarmRinging) {                                                  //  if alarm is ringing...
          alarmRinging = false;                                              //   turn it off...
          song = parseSong(noSong);                                          //   and stop playing song
        } else if (!peekStart)
          peekDuration = Settings.peekDuration;                              // determines how long peek will last
        peekStart = millis();                                                // indicates peek cycle in progress and tells us when to end it if it's night time
        sleeping = false;                                                    // turn off sleeping so time is displayed
      }
    }
  }

  // ending peek mode
  if (peekStart > 0) {
    if (millis() - peekStart > (uint32_t)peekDuration * 1000UL) {            // turn peek mode off after configured time elapses
      DEBUG_PRINTLN(F("Leaving peek mode"));
      peekStart = 0;
    }
  }

SapientHetero avatar Feb 21 '23 14:02 SapientHetero

Thank you. I'll try and get my head around that. I still haven't figured out the best way to actually turn the tubes off / on.

regorwislon avatar Feb 22 '23 03:02 regorwislon

I'm thinking of using LEpin as suggested above, and only allowing it to go HIGH if recent motion has been detected. Is that too simple?

regorwislon avatar Feb 22 '23 03:02 regorwislon

It was too simple! Setting LEpin LOW only stops the tubes from changing from what they are already displaying. However my original idea of using BL (the Blanking pin) by setting pinSHDN LOW does turn them off, and restoring pinSHDN to HIGH turns them back on again. 🙂

regorwislon avatar Feb 22 '23 04:02 regorwislon

Glad you got it working.

You can also dim the bulbs by using pulse width modulation on LEpin.

// these values determine how dim the bulbs are when dimming is enabled. Lower pulse width + lower delay = dimmer bulbs

uint8_t dimPulseWidth[4] = {15, 30, 45, 65};

uint32_t dimDelay[4] = {500, 1000, 1500, 2000}; // in microseconds; this matters more than pulsewidth

Then insteading of setting LEpin high to display the time, set it to your desired pulse width

if (dimming) {

delayMicroseconds(dimDelay[Settings.dimmingSetting-1]);

analogWrite(LEpin, dimPulseWidth[Settings.dimmingSetting-1]);

}

From: regorwislon @.> Sent: Tuesday, February 21, 2023 11:23 PM To: afch/NixeTubesShieldNCS314 @.> Cc: Sapient Hetero @.>; Author @.> Subject: Re: [afch/NixeTubesShieldNCS314] Is it possible to turn the bulbs off in software? (#17)

It was too simple! Setting LEpin LOW only stops the tubes from changing from what they are already displaying. However my original idea of using BL (the Blanking pin) by setting pinSHDN LOW does turn them off, and restoring pinSHDN to HIGH turns them back on again. 🙂

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

SapientHetero avatar Feb 22 '23 04:02 SapientHetero

Many thanks for your help and for sharing your knowledge and work. much appreciated.

On 22/02/2023, at 5:41 PM, Sapient Hetero @.***> wrote:

 Glad you got it working.

You can also dim the bulbs by using pulse width modulation on LEpin.

// these values determine how dim the bulbs are when dimming is enabled. Lower pulse width + lower delay = dimmer bulbs

uint8_t dimPulseWidth[4] = {15, 30, 45, 65};

uint32_t dimDelay[4] = {500, 1000, 1500, 2000}; // in microseconds; this matters more than pulsewidth

Then insteading of setting LEpin high to display the time, set it to your desired pulse width

if (dimming) {

delayMicroseconds(dimDelay[Settings.dimmingSetting-1]);

analogWrite(LEpin, dimPulseWidth[Settings.dimmingSetting-1]);

}

From: regorwislon @.> Sent: Tuesday, February 21, 2023 11:23 PM To: afch/NixeTubesShieldNCS314 @.> Cc: Sapient Hetero @.>; Author @.> Subject: Re: [afch/NixeTubesShieldNCS314] Is it possible to turn the bulbs off in software? (#17)

It was too simple! Setting LEpin LOW only stops the tubes from changing from what they are already displaying. However my original idea of using BL (the Blanking pin) by setting pinSHDN LOW does turn them off, and restoring pinSHDN to HIGH turns them back on again. 🙂

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***> — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

regorwislon avatar Feb 22 '23 05:02 regorwislon

By the way, I am using a combination Mega/ESP8266 board to control my Nixie Clock [https://www.amazon.com/gp/product/B07THDDFSJ/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1. Instead of using the non-user-friendly buttons on the back of the clock to change settings, I run a webserver on the ESP8266 and control it via WiFi.

SapientHetero avatar Feb 23 '23 20:02 SapientHetero

Nice idea. I have played around with the ESP32Cam board which also runs a webserver to monitor the camera so I might explore this combined board when I have a bit of time. Still have to build a case for my clock.

regorwislon avatar Feb 23 '23 22:02 regorwislon