├── .gitignore ├── CLITool ├── .cproject ├── .project ├── .settings │ ├── language.settings.xml │ └── org.eclipse.cdt.managedbuilder.core.prefs ├── Debug │ ├── CLITool │ ├── makefile │ ├── objects.mk │ ├── sources.mk │ └── src │ │ ├── DisplayNixie.d │ │ ├── DisplayNixie.o │ │ └── subdir.mk └── src │ └── DisplayNixie.cpp ├── DisplayNixie ├── README.md ├── bin │ └── .gitignore ├── nixie.service └── src │ ├── DisplayNixie.cpp │ └── makefile ├── Firmware for NCS314 v3.x └── DisplayNixie3x │ ├── .cproject │ ├── .project │ ├── .settings │ ├── language.settings.xml │ └── org.eclipse.cdt.managedbuilder.core.prefs │ ├── Debug │ ├── DisplayNixie3x │ ├── makefile │ ├── objects.mk │ ├── sources.mk │ └── src │ │ ├── DisplayNixie3x.d │ │ ├── DisplayNixie3x.o │ │ └── subdir.mk │ └── src │ └── DisplayNixie3x.cpp ├── Firmware for NCS318 └── DisplayNixie │ ├── .cproject │ ├── .project │ ├── .settings │ ├── language.settings.xml │ └── org.eclipse.cdt.managedbuilder.core.prefs │ ├── Debug │ ├── DisplayNixie │ ├── makefile │ ├── objects.mk │ ├── sources.mk │ └── src │ │ ├── DisplayNixie.d │ │ ├── DisplayNixie.o │ │ └── subdir.mk │ └── src │ └── DisplayNixie.cpp ├── Firmware ├── .cproject ├── .project ├── .settings │ ├── language.settings.xml │ └── org.eclipse.cdt.managedbuilder.core.prefs ├── Debug │ ├── DisplayNixie │ ├── makefile │ ├── objects.mk │ ├── sources.mk │ └── src │ │ ├── DisplayNixie.d │ │ ├── DisplayNixie.o │ │ └── subdir.mk └── src │ └── DisplayNixie.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /CLITool/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /CLITool/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CLITool 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /CLITool/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CLITool/.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/delimiter=\: 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/delimiter=\: 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/delimiter=\: 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/operation=remove 8 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 9 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/delimiter=\: 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/operation=remove 12 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 13 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 14 | -------------------------------------------------------------------------------- /CLITool/Debug/CLITool: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/CLITool/Debug/CLITool -------------------------------------------------------------------------------- /CLITool/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include src/subdir.mk 12 | -include subdir.mk 13 | -include objects.mk 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | ifneq ($(strip $(CC_DEPS)),) 17 | -include $(CC_DEPS) 18 | endif 19 | ifneq ($(strip $(C++_DEPS)),) 20 | -include $(C++_DEPS) 21 | endif 22 | ifneq ($(strip $(C_UPPER_DEPS)),) 23 | -include $(C_UPPER_DEPS) 24 | endif 25 | ifneq ($(strip $(CXX_DEPS)),) 26 | -include $(CXX_DEPS) 27 | endif 28 | ifneq ($(strip $(C_DEPS)),) 29 | -include $(C_DEPS) 30 | endif 31 | ifneq ($(strip $(CPP_DEPS)),) 32 | -include $(CPP_DEPS) 33 | endif 34 | endif 35 | 36 | -include ../makefile.defs 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | 40 | # All Target 41 | all: CLITool 42 | 43 | # Tool invocations 44 | CLITool: $(OBJS) $(USER_OBJS) 45 | @echo 'Building target: $@' 46 | @echo 'Invoking: Cross G++ Linker' 47 | g++ -o "CLITool" $(OBJS) $(USER_OBJS) $(LIBS) 48 | @echo 'Finished building target: $@' 49 | @echo ' ' 50 | 51 | # Other Targets 52 | clean: 53 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) CLITool 54 | -@echo ' ' 55 | 56 | .PHONY: all clean dependents 57 | .SECONDARY: 58 | 59 | -include ../makefile.targets 60 | -------------------------------------------------------------------------------- /CLITool/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := -lwiringPi 8 | 9 | -------------------------------------------------------------------------------- /CLITool/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | C_UPPER_SRCS := 6 | CXX_SRCS := 7 | C++_SRCS := 8 | OBJ_SRCS := 9 | CC_SRCS := 10 | ASM_SRCS := 11 | C_SRCS := 12 | CPP_SRCS := 13 | O_SRCS := 14 | S_UPPER_SRCS := 15 | CC_DEPS := 16 | C++_DEPS := 17 | EXECUTABLES := 18 | OBJS := 19 | C_UPPER_DEPS := 20 | CXX_DEPS := 21 | C_DEPS := 22 | CPP_DEPS := 23 | 24 | # Every subdirectory with source files must be described here 25 | SUBDIRS := \ 26 | src \ 27 | 28 | -------------------------------------------------------------------------------- /CLITool/Debug/src/DisplayNixie.d: -------------------------------------------------------------------------------- 1 | src/DisplayNixie.d: ../src/DisplayNixie.cpp 2 | -------------------------------------------------------------------------------- /CLITool/Debug/src/DisplayNixie.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/CLITool/Debug/src/DisplayNixie.o -------------------------------------------------------------------------------- /CLITool/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | CPP_SRCS += \ 7 | ../src/DisplayNixie.cpp 8 | 9 | OBJS += \ 10 | ./src/DisplayNixie.o 11 | 12 | CPP_DEPS += \ 13 | ./src/DisplayNixie.d 14 | 15 | 16 | # Each subdirectory must supply rules for building sources it contributes 17 | src/%.o: ../src/%.cpp 18 | @echo 'Building file: $<' 19 | @echo 'Invoking: Cross G++ Compiler' 20 | g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 21 | @echo 'Finished building: $<' 22 | @echo ' ' 23 | 24 | 25 | -------------------------------------------------------------------------------- /CLITool/src/DisplayNixie.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : DisplayNixie.cpp 3 | // Author : GRA&AFCH 4 | // Version : v1.3 5 | // Copyright : Free 6 | // Description : Display digits on shields 7 | //============================================================================ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define _VERSION 1.3 18 | #define I2CAdress 0x68 19 | #define I2CFlush 0 20 | #define SECOND_REGISTER 0x0 21 | #define MINUTE_REGISTER 0x1 22 | #define HOUR_REGISTER 0x2 23 | 24 | using namespace std; 25 | int LEpin=3; 26 | int I2CFileDesc; 27 | uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 28 | 29 | int decToBcd(int val) { 30 | return ((val / 10 * 16) + (val % 10)); 31 | } 32 | 33 | void writeRTCDate(tm date) { 34 | wiringPiI2CWrite(I2CFileDesc, I2CFlush); 35 | wiringPiI2CWriteReg8(I2CFileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 36 | wiringPiI2CWriteReg8(I2CFileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 37 | wiringPiI2CWriteReg8(I2CFileDesc,SECOND_REGISTER,decToBcd(date.tm_sec)); 38 | wiringPiI2CWrite(I2CFileDesc, I2CFlush); 39 | } 40 | 41 | int main(int argc, char* argv[]) { 42 | printf("Display Nixie CLI Tool v%1.1f \n\r", _VERSION); 43 | printf("%s", argv[1]); 44 | 45 | if (argc < 2) 46 | { 47 | printf("Enter digits to display... or commands: \n now - show current time, \n " 48 | //"clock - loop the program and update time every second, \n " 49 | "[digits] - and six or nine digits, \n " 50 | "settime x - set time, where x time in format [hh:mm:ss], \n " 51 | "setsystime - set current time from OS, \n " 52 | //"ledson - turn on RGB LEDs,\n " 53 | //"ledsoff - turn off RGB LEDs, \n " 54 | //"setledscolor x - set color of LEDs where x is color in [RRR:GGG:BBB] format, \n " 55 | //"setledsbright x - [0...255], \n " 56 | "? - show this help."); 57 | return 0; 58 | } 59 | wiringPiSetup (); 60 | 61 | if (wiringPiSPISetupMode (0, 2000000, 2)) printf("SPI ok\n\r"); 62 | else {printf("SPI NOT ok\n\r"); return 0;} 63 | 64 | I2CFileDesc = wiringPiI2CSetup(I2CAdress); 65 | 66 | char _stringToDisplay[10]; 67 | int tubes_qty=6; 68 | 69 | if (!strcmp(argv[1],"now")) 70 | { 71 | time_t seconds=time(NULL); 72 | tm* timeinfo=localtime(&seconds); 73 | char* format="%H%M%S"; 74 | strftime(_stringToDisplay, 8, format, timeinfo); 75 | } 76 | 77 | else if (!strcmp(argv[1],"settime")) 78 | { 79 | _stringToDisplay[0]=argv[2][0]; 80 | _stringToDisplay[1]=argv[2][1]; 81 | _stringToDisplay[2]=argv[2][3]; 82 | _stringToDisplay[3]=argv[2][4]; 83 | _stringToDisplay[4]=argv[2][6]; 84 | _stringToDisplay[5]=argv[2][7]; 85 | tm time; 86 | time.tm_hour=10*((int)_stringToDisplay[0]-48)+(int)_stringToDisplay[1]-48; 87 | time.tm_min=10*((int)_stringToDisplay[2]-48)+(int)_stringToDisplay[3]-48; 88 | time.tm_sec=10*((int)_stringToDisplay[4]-48)+(int)_stringToDisplay[5]-48; 89 | writeRTCDate(time); 90 | } 91 | 92 | else if (!strcmp(argv[1],"setsystime")) 93 | { 94 | time_t seconds=time(NULL); 95 | tm* time=localtime(&seconds); 96 | writeRTCDate(*time); 97 | char* format="%H%M%S"; 98 | strftime(_stringToDisplay, 8, format, time); 99 | } 100 | 101 | else 102 | { 103 | tubes_qty=strlen(argv[1]); 104 | if ((tubes_qty != 6) && (tubes_qty != 9)) 105 | { 106 | puts("Wrong length: must be 6 or 9 digits. \n"); 107 | return 0; 108 | } 109 | for (int i=0; i>24; 131 | bufferIndex++; 132 | buff[bufferIndex]=Var32>>16; 133 | bufferIndex++; 134 | buff[bufferIndex]=Var32>>8; 135 | bufferIndex++; 136 | buff[bufferIndex]=Var32; 137 | bufferIndex++; 138 | } 139 | 140 | digitalWrite(LEpin, LOW); 141 | wiringPiSPIDataRW(0, buff, 4*tubes_qty/3); 142 | digitalWrite(LEpin, HIGH); 143 | puts("Exit..."); 144 | return 0; 145 | } 146 | 147 | -------------------------------------------------------------------------------- /DisplayNixie/README.md: -------------------------------------------------------------------------------- 1 | # NixieClockRaspberryPi 2 | 3 | ## With mods by Leon Shaner 4 | 5 | Simple Nixie Tubes Clock Based on RaspberryPi, adapter and NCS314 shield for Arduino (by GRA and AFCH) 6 | A simple program that show the current system time at the Nixie tubes. 7 | 8 | NOTE: Works with NCS314 v2.x or NCS312; has not been tested with newer models (as of 19 February 2021). 9 | 10 | ### Major features of the Shaner mods: 11 | 12 | 1. Use the system RTC by default (e.g. rely on NTP for more accurate time). 13 | 2. Option to display 12-hour or 24-hour for the hour digits. 14 | 3. Repurpose MODE button to toggle fireworks on/off. 15 | 4. Repurpose UP/DOWN buttons to increase/decrease the fireworks cycle speed. 16 | 5. Command-line parsing to choose preferred options without recompile. 17 | 6. Re-wrote makefile for proper handling of binary rebuild any time the sources are modified. 18 | 19 | ### Wiringpi library 20 | 21 | Before doing the build instructions below follow these steps to install the wiringpi library as it is no longer included in repos as of Bookworm 22 | 23 | 1. Download the most recent precompiled armhf binary from https://github.com/WiringPi/WiringPi/releases: 24 | `curl -L -o wiringpi_3.2_arm64.deb https://github.com/WiringPi/WiringPi/releases/download/3.2/wiringpi_3.2_arm64.deb` 25 | 2. Run: `sudo apt install ./wiringpi_3.2_arm64.deb` 26 | 27 | ### Required hardware: 28 | 29 | 1. Raspberry Pi any models with 40-pin GPIO connector (Except A and B models). 30 | 2. Arduino to Raspberry Pi adapter (by GRA & AFCH): https://gra-afch.com/catalog/shield-nixie-clock-for-arduino/raspberry-pi-shield-nixie-tubes-clock-ncs314-for-in-14-nixie-tubes-options-tubes-gps-remote-arduino-columns-copy/ 31 | 3. Arduino Nixie Clock Shield NCS314 (v1.2, v2.x): https://gra-afch.com/catalog/shield-nixie-clock-for-arduino/nixie-tubes-clock-arduino-shield-ncs314-for-xussr-in-14-nixie-tubes/ 32 | 33 | ### How to build: 34 | 35 | 1. Download and unzip. 36 | 2. Enable SPI module in the "Raspberry Pi Configuration": https://photos.app.goo.gl/vH7DtG9nwMzJHwvP2 37 | 2.1) or CLI way "sudo raspi-config": https://photos.app.goo.gl/wfoPd8CNLSlJ0bF83 38 | 39 | 3. cd into .../DisplayNixie/src 40 | 4. Run 'make' 41 | 5. Binary will be placed at .../DisplayNixie/bin/DisplayNixie, a la: 42 | /nixie/NixieClockRaspberryPi-shaner/DisplayNixie/bin/DisplayNixie 43 | 44 | ### Сommand line options (shaner mods): 45 | 46 | - USAGE: DisplayNixie -- Use system clock in 12-hour mode. 47 | - DisplayNixie nosysclock -- use Nixie clock (e.g. not NTP assisted). 48 | - DisplayNixie 24hour -- use 24-hour mode. 49 | - DisplayNixie fireworks -- enable fireworks. 50 | 51 | NOTE: Any combination/order of above arguments is allowed. 52 | 53 | ### Run-time options (shaner mods): 54 | 55 | - MODE Button: Toggle fireworks on/off 56 | - UP Button: Speed up fireworks color-rotation 57 | - DOWN Button: Slow down fireworks color-rotation 58 | 59 | ### Autorun the program at startup: 60 | 61 | 1. Edit the provided nixie.service template to reflect the full path down to your binary: 62 | 63 | NOTE: Fix the path on the following line in nixie.service to match your binary location. 64 | 65 | ExecStart=/nixie/NixieClockRaspberryPi-shaner/DisplayNixie/bin/DisplayNixie 66 | 67 | 2. Copy your customized nixie.service into the /etc/systemd/system directory: 68 | 69 | - $ sudo cp nixie.service /etc/systemd/system 70 | 71 | 3. Reload the systemd state and start the nixie service: 72 | 73 | - $ sudo systemctl daemon-reload 74 | - $ sudo systemctl enable nixie 75 | - $ sudo systemctl start nixie 76 | 77 | NOTE: The systemd will auto-start DisplayNixie whenever the system is booted. 78 | 79 | 4. To stop and/or restart the nixie binary at any time: 80 | 81 | - $ sudo systemctl stop nixie 82 | - $ sudo systemctl restart nixie 83 | -------------------------------------------------------------------------------- /DisplayNixie/bin/.gitignore: -------------------------------------------------------------------------------- 1 | #just a git hack to pre-create the bin directory 2 | -------------------------------------------------------------------------------- /DisplayNixie/nixie.service: -------------------------------------------------------------------------------- 1 | 2 | [Unit] 3 | Description=nixie clock 4 | After=network.target 5 | 6 | [Service] 7 | ExecStart=/nixie/NixieClockRaspberryPi-shaner/DisplayNixie/bin/DisplayNixie 8 | WorkingDirectory=/tmp 9 | StandardOutput=inherit 10 | StandardError=inherit 11 | Restart=always 12 | User=pi 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /DisplayNixie/src/DisplayNixie.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : DisplayNixie.cpp 3 | // Author : GRA&AFCH @ Leon Shaner 4 | // Version : v2.3.1 5 | // Copyright : Free 6 | // Description : Display time on shields NCS314 v2.x or NCS312 7 | //============================================================================ 8 | 9 | #define _VERSION "2.3.1 SHANER" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | #define R5222_PIN 22 23 | bool HV5222; 24 | #define LEpin 3 25 | #define UP_BUTTON_PIN 1 26 | #define DOWN_BUTTON_PIN 4 27 | #define MODE_BUTTON_PIN 5 28 | #define BUZZER_PIN 0 29 | #define I2CAdress 0x68 30 | #define I2CFlush 0 31 | 32 | #define DEBOUNCE_DELAY 150 33 | #define TOTAL_DELAY 17 34 | 35 | #define SECOND_REGISTER 0x0 36 | #define MINUTE_REGISTER 0x1 37 | #define HOUR_REGISTER 0x2 38 | #define WEEK_REGISTER 0x3 39 | #define DAY_REGISTER 0x4 40 | #define MONTH_REGISTER 0x5 41 | #define YEAR_REGISTER 0x6 42 | 43 | #define RED_LIGHT_PIN 28 44 | #define GREEN_LIGHT_PIN 27 45 | #define BLUE_LIGHT_PIN 29 46 | #define MAX_POWER 100 47 | #define INIT_CYCLE_FREQ 5 48 | #define INIT_CYCLE_BUMP 5 49 | 50 | #define UPPER_DOTS_MASK 0x80000000 51 | #define LOWER_DOTS_MASK 0x40000000 52 | 53 | #define LEFT_REPR_START 5 54 | #define LEFT_BUFFER_START 0 55 | #define RIGHT_REPR_START 2 56 | #define RIGHT_BUFFER_START 4 57 | 58 | uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 59 | 60 | int fileDesc; 61 | int redLight = 100; 62 | int greenLight = 0; 63 | int blueLight = 0; 64 | int lightCycle = 0; 65 | bool dotState = 0; 66 | int rotator = 0; 67 | int cycleFreq = INIT_CYCLE_FREQ; 68 | 69 | // Set initial fireworks mode true=on; false=off 70 | bool doFireworks = false; 71 | 72 | // Set default clock mode 73 | // NOTE: true means rely on system to keep time (e.g. NTP assisted for accuracy). 74 | bool useSystemRTC = true; 75 | 76 | // Set the hour mode 77 | // Set use12hour = true for hours 0-12 and 1-11 (e.g. a.m./p.m. implied) 78 | // Set use12hour = false for hours 0-23 79 | bool use12hour = true; 80 | 81 | int bcdToDec(int val) { 82 | return ((val / 16 * 10) + (val % 16)); 83 | } 84 | 85 | int decToBcd(int val) { 86 | return ((val / 10 * 16) + (val % 10)); 87 | } 88 | 89 | tm addHourToDate(tm date) { 90 | date.tm_hour += 1; 91 | mktime(&date); 92 | return date; 93 | } 94 | 95 | tm addMinuteToDate(tm date) { 96 | date.tm_min += 1; 97 | mktime(&date); 98 | return date; 99 | } 100 | 101 | tm getRTCDate() { 102 | wiringPiI2CWrite(fileDesc, I2CFlush); 103 | tm date; 104 | date.tm_sec = bcdToDec(wiringPiI2CReadReg8(fileDesc,SECOND_REGISTER)); 105 | date.tm_min = bcdToDec(wiringPiI2CReadReg8(fileDesc,MINUTE_REGISTER)); 106 | if (use12hour) 107 | { 108 | date.tm_hour = bcdToDec(wiringPiI2CReadReg8(fileDesc,HOUR_REGISTER)); 109 | if (date.tm_hour > 12) 110 | date.tm_hour -= 12; 111 | } 112 | else 113 | date.tm_hour = bcdToDec(wiringPiI2CReadReg8(fileDesc,HOUR_REGISTER)); 114 | date.tm_wday = bcdToDec(wiringPiI2CReadReg8(fileDesc,WEEK_REGISTER)); 115 | date.tm_mday = bcdToDec(wiringPiI2CReadReg8(fileDesc,DAY_REGISTER)); 116 | date.tm_mon = bcdToDec(wiringPiI2CReadReg8(fileDesc,MONTH_REGISTER)); 117 | date.tm_year = bcdToDec(wiringPiI2CReadReg8(fileDesc,YEAR_REGISTER)); 118 | date.tm_isdst = 0; 119 | return date; 120 | } 121 | 122 | void updateRTCHour(tm date) { 123 | wiringPiI2CWrite(fileDesc, I2CFlush); 124 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 125 | wiringPiI2CWrite(fileDesc, I2CFlush); 126 | } 127 | 128 | void updateRTCMinute(tm date) { 129 | wiringPiI2CWrite(fileDesc, I2CFlush); 130 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 131 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 132 | wiringPiI2CWrite(fileDesc, I2CFlush); 133 | } 134 | void resetRTCSecond() { 135 | wiringPiI2CWrite(fileDesc, I2CFlush); 136 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER, 0); 137 | wiringPiI2CWrite(fileDesc, I2CFlush); 138 | } 139 | 140 | void writeRTCDate(tm date) { 141 | wiringPiI2CWrite(fileDesc, I2CFlush); 142 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER,decToBcd(date.tm_sec)); 143 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 144 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 145 | wiringPiI2CWriteReg8(fileDesc,WEEK_REGISTER,decToBcd(date.tm_wday)); 146 | wiringPiI2CWriteReg8(fileDesc,DAY_REGISTER,decToBcd(date.tm_mday)); 147 | wiringPiI2CWriteReg8(fileDesc,MONTH_REGISTER,decToBcd(date.tm_mon)); 148 | wiringPiI2CWriteReg8(fileDesc,YEAR_REGISTER,decToBcd(date.tm_year)); 149 | wiringPiI2CWrite(fileDesc, I2CFlush); 150 | } 151 | 152 | void initPin(int pin) { 153 | pinMode(pin, INPUT); 154 | pullUpDnControl(pin, PUD_UP); 155 | 156 | } 157 | 158 | void resetFireWorks() { 159 | redLight = 0; 160 | greenLight = 0; 161 | blueLight = 0; 162 | softPwmWrite(RED_LIGHT_PIN, redLight); 163 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 164 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 165 | } 166 | 167 | void initFireWorks() { 168 | redLight = 5; 169 | greenLight = 0; 170 | blueLight = 0; 171 | softPwmWrite(RED_LIGHT_PIN, redLight); 172 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 173 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 174 | } 175 | 176 | void funcMode(void) { 177 | static unsigned long modeTime = 0; 178 | if ((millis() - modeTime) > DEBOUNCE_DELAY) { 179 | puts("MODE button was pressed."); 180 | // Mode Switch toggles Fireworks on/off 181 | doFireworks = !doFireworks; 182 | if (!doFireworks) 183 | resetFireWorks(); 184 | else 185 | initFireWorks(); 186 | modeTime = millis(); 187 | } 188 | } 189 | 190 | void funcUp(void) { 191 | static unsigned long buttonTime = 0; 192 | if ((millis() - buttonTime) > DEBOUNCE_DELAY) { 193 | // UP button speeds up Fireworks 194 | cycleFreq = ((cycleFreq + INIT_CYCLE_BUMP) / INIT_CYCLE_BUMP ) * INIT_CYCLE_BUMP; 195 | if (cycleFreq >= MAX_POWER / 2 ) 196 | { 197 | cycleFreq = MAX_POWER / 2; 198 | printf("Up button was pressed. Already at fastest speed, %d; ignoring.\n", cycleFreq); 199 | } 200 | else 201 | printf("UP button was pressed. Frequency=%d\n", cycleFreq); 202 | buttonTime = millis(); 203 | } 204 | } 205 | 206 | void funcDown(void) { 207 | static unsigned long buttonTime = 0; 208 | if ((millis() - buttonTime) > DEBOUNCE_DELAY) { 209 | // Down button slows down Fireworks 210 | cycleFreq = ((cycleFreq - INIT_CYCLE_BUMP) / INIT_CYCLE_BUMP ) * INIT_CYCLE_BUMP; 211 | if (cycleFreq <= 1 ) 212 | { 213 | cycleFreq = 1; 214 | printf("Down button was pressed. Already at slowest speed, %d; ignoring.\n", cycleFreq); 215 | } 216 | else 217 | printf("Down button was pressed. Frequency=%d\n", cycleFreq); 218 | } 219 | buttonTime = millis(); 220 | } 221 | 222 | 223 | uint32_t get32Rep(char * _stringToDisplay, int start) { 224 | uint32_t var32 = 0; 225 | 226 | var32= (SymbolArray[_stringToDisplay[start]-0x30])<<20; 227 | var32|=(SymbolArray[_stringToDisplay[start - 1]-0x30])<<10; 228 | var32|=(SymbolArray[_stringToDisplay[start - 2]-0x30]); 229 | return var32; 230 | } 231 | 232 | void fillBuffer(uint32_t var32, unsigned char * buffer, int start) { 233 | buffer[start] = var32>>24; 234 | buffer[start + 1] = var32>>16; 235 | buffer[start + 2] = var32>>8; 236 | buffer[start + 3] = var32; 237 | } 238 | 239 | void dotBlink() 240 | { 241 | static unsigned int lastTimeBlink=millis(); 242 | 243 | if ((millis() - lastTimeBlink) >= 1000) 244 | { 245 | lastTimeBlink=millis(); 246 | dotState = !dotState; 247 | } 248 | } 249 | 250 | void rotateFireWorks() { 251 | int fireworks[] = {0,0,1, 252 | -1,0,0, 253 | 0,1,0, 254 | 0,0,-1, 255 | 1,0,0, 256 | 0,-1,0 257 | }; 258 | redLight += fireworks[rotator * 3]; 259 | greenLight += fireworks[rotator * 3 + 1]; 260 | blueLight += fireworks[rotator * 3 + 2]; 261 | softPwmWrite(RED_LIGHT_PIN, redLight); 262 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 263 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 264 | lightCycle = lightCycle + cycleFreq; 265 | if (lightCycle >= MAX_POWER) { 266 | rotator = rotator + 1; 267 | lightCycle = 0; 268 | } 269 | if (rotator > 5) 270 | rotator = 0; 271 | } 272 | 273 | 274 | uint32_t addBlinkTo32Rep(uint32_t var) { 275 | if (dotState) 276 | { 277 | var &=~LOWER_DOTS_MASK; 278 | var &=~UPPER_DOTS_MASK; 279 | } 280 | else 281 | { 282 | var |=LOWER_DOTS_MASK; 283 | var |=UPPER_DOTS_MASK; 284 | } 285 | return var; 286 | } 287 | 288 | // Interrupt handler to turn off Nixie upon SIGINT(2), SIGQUIT(3), SIGTERM(15), but not SIGKILL(9) 289 | void signal_handler (int sig_received) 290 | { 291 | printf("Received Signal %d; Exiting.\n", sig_received); 292 | digitalWrite(RED_LIGHT_PIN, LOW); 293 | digitalWrite(GREEN_LIGHT_PIN, LOW); 294 | digitalWrite(BLUE_LIGHT_PIN, LOW); 295 | digitalWrite(LEpin, LOW); 296 | exit(sig_received); 297 | } 298 | 299 | //uint64_t* reverseBit(uint64_t num); 300 | uint64_t reverseBit(uint64_t num); 301 | 302 | int main(int argc, char* argv[]) { 303 | 304 | // Setup signal handlers 305 | signal(SIGINT, signal_handler); 306 | signal(SIGQUIT, signal_handler); 307 | signal(SIGTERM, signal_handler); 308 | 309 | printf("Nixie Clock v%s \n\r", _VERSION); 310 | 311 | wiringPiSetup(); 312 | 313 | //softToneCreate (BUZZER_PIN); 314 | //softToneWrite(BUZZER_PIN, 1000); 315 | 316 | softPwmCreate(GREEN_LIGHT_PIN, 0, MAX_POWER); 317 | softPwmCreate(BLUE_LIGHT_PIN, 0, MAX_POWER); 318 | 319 | 320 | // Crude command-line argument handling 321 | if (argc >= 2) 322 | { 323 | int curr_arg = 1; 324 | while (curr_arg < argc) 325 | { 326 | if (!strcmp(argv[curr_arg],"nosysclock")) 327 | useSystemRTC = false; 328 | else if (!strcmp(argv[curr_arg],"24hour")) 329 | use12hour = false; 330 | else if (!strcmp(argv[curr_arg],"fireworks")) 331 | doFireworks = true; 332 | else 333 | { 334 | printf("ERROR: %s Unknown argument, \"%s\" on command line.\n\n", argv[0], argv[1]); 335 | printf("USAGE: %s -- Use system clock in 12-hour mode.\n", argv[0]); 336 | printf(" %s nosysclock -- use Nixie clock (e.g. not NTP assisted).\n", argv[0]); 337 | printf(" %s 24hour -- use 24-hour mode.\n", argv[0]); 338 | printf(" %s fireworks -- enable fireworks.\n", argv[0]); 339 | puts("\nNOTE: Any combination/order of above arguments is allowed.\n"); 340 | exit(10); 341 | } 342 | curr_arg += 1; 343 | } 344 | } 345 | 346 | 347 | // Tell the user the RTC mode 348 | if (useSystemRTC) 349 | puts("Using system RTC (eg. NTP assisted accuracy)."); 350 | else 351 | puts("Using Nixie embedded RTC (e.g. not NTP assisted)."); 352 | 353 | // Tell the user the hour mode 354 | if (use12hour) 355 | puts("Using 12-hour display (implied a.m./p.m.)."); 356 | else 357 | puts("Using 24-hour display."); 358 | 359 | // Tell the user the fireworks mode 360 | if (doFireworks) 361 | puts("Fireworks ENABLED at start."); 362 | else 363 | puts("Fireworks DISABLED at start."); 364 | 365 | // Further setup... 366 | initPin(UP_BUTTON_PIN); 367 | initPin(DOWN_BUTTON_PIN); 368 | initPin(MODE_BUTTON_PIN); 369 | 370 | // Initial setup for multi-color LED's based on default doFirewworks boolean 371 | if (doFireworks) 372 | softPwmCreate(RED_LIGHT_PIN, 100, MAX_POWER); 373 | else 374 | { 375 | softPwmCreate(RED_LIGHT_PIN, 0, MAX_POWER); 376 | resetFireWorks(); 377 | } 378 | 379 | // Mode Switch toggles Fireworks on/off 380 | wiringPiISR(MODE_BUTTON_PIN,INT_EDGE_RISING,&funcMode); 381 | 382 | // Open the Nixie device 383 | fileDesc = wiringPiI2CSetup(I2CAdress); 384 | 385 | // Further date setup 386 | tm date = getRTCDate(); 387 | time_t seconds = time(NULL); 388 | tm* timeinfo = localtime (&seconds); 389 | 390 | // Tell the user the SPI status 391 | if (wiringPiSPISetupMode (0, 2000000, 2)) { 392 | puts("SPI ok"); 393 | } 394 | else { 395 | puts("SPI NOT ok"); 396 | return 0; 397 | } 398 | 399 | pinMode(R5222_PIN, INPUT); 400 | pullUpDnControl(R5222_PIN, PUD_UP); 401 | HV5222=!digitalRead(R5222_PIN); 402 | if (HV5222) puts("R52222 resistor detected. HV5222 algorithm is used."); 403 | uint64_t reverseBuffValue; 404 | 405 | // Loop forever displaying the time 406 | long buttonDelay = millis(); 407 | 408 | do { 409 | char _stringToDisplay[8]; 410 | 411 | 412 | // NOTE: RTC relies on system to keep time (e.g. NTP assisted for accuracy). 413 | if (useSystemRTC) 414 | { 415 | seconds = time(NULL); 416 | timeinfo = localtime (&seconds); 417 | date.tm_mday = timeinfo->tm_mday; 418 | date.tm_wday = timeinfo->tm_wday; 419 | date.tm_mon = timeinfo->tm_mon + 1; 420 | date.tm_year = timeinfo->tm_year - 100; 421 | writeRTCDate(*timeinfo); 422 | } 423 | 424 | // NOTE: RTC relies on Nixie to keep time (e.g. no NTP). 425 | date = getRTCDate(); 426 | 427 | char* format = (char*) "%H%M%S"; 428 | strftime(_stringToDisplay, 8, format, &date); 429 | 430 | 431 | pinMode(LEpin, OUTPUT); 432 | dotBlink(); 433 | 434 | unsigned char buff[8]; 435 | 436 | uint32_t var32 = get32Rep(_stringToDisplay, LEFT_REPR_START); 437 | var32 = addBlinkTo32Rep(var32); 438 | fillBuffer(var32, buff , LEFT_BUFFER_START); 439 | 440 | var32 = get32Rep(_stringToDisplay, RIGHT_REPR_START); 441 | var32 = addBlinkTo32Rep(var32); 442 | fillBuffer(var32, buff , RIGHT_BUFFER_START); 443 | 444 | 445 | 446 | if (doFireworks) 447 | { 448 | // Handle Fireworks speed UP / Down 449 | if (digitalRead(UP_BUTTON_PIN) == 0 && (millis() - buttonDelay) > DEBOUNCE_DELAY) { 450 | funcUp(); 451 | initFireWorks(); 452 | buttonDelay = millis(); 453 | } 454 | if (digitalRead(DOWN_BUTTON_PIN) == 0 && (millis() - buttonDelay) > DEBOUNCE_DELAY) { 455 | funcDown(); 456 | initFireWorks(); 457 | buttonDelay = millis(); 458 | } 459 | rotateFireWorks(); 460 | } 461 | 462 | digitalWrite(LEpin, LOW); 463 | 464 | if (HV5222) 465 | { 466 | reverseBuffValue=reverseBit(*(uint64_t*)buff); 467 | buff[4]=reverseBuffValue; 468 | buff[5]=reverseBuffValue>>8; 469 | buff[6]=reverseBuffValue>>16; 470 | buff[7]=reverseBuffValue>>24; 471 | buff[0]=reverseBuffValue>>32; 472 | buff[1]=reverseBuffValue>>40; 473 | buff[2]=reverseBuffValue>>48; 474 | buff[3]=reverseBuffValue>>56; 475 | } 476 | 477 | wiringPiSPIDataRW(0, buff, 8); 478 | digitalWrite(LEpin, HIGH); 479 | delay (TOTAL_DELAY); 480 | } 481 | while (true); 482 | return 0; 483 | } 484 | 485 | //uint64_t* reverseBit(uint64_t num) 486 | uint64_t reverseBit(uint64_t num) 487 | { 488 | uint64_t reverse_num=0; 489 | int i; 490 | for (i=0; i<64; i++) 491 | { 492 | if ((num & ((uint64_t)1< 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 80 | 81 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DisplayNixie3x 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/delimiter=\: 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/delimiter=\: 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/delimiter=\: 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/operation=remove 8 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 9 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/delimiter=\: 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/operation=remove 12 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 13 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 14 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/DisplayNixie3x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware for NCS314 v3.x/DisplayNixie3x/Debug/DisplayNixie3x -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include src/subdir.mk 12 | -include subdir.mk 13 | -include objects.mk 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | ifneq ($(strip $(CC_DEPS)),) 17 | -include $(CC_DEPS) 18 | endif 19 | ifneq ($(strip $(C++_DEPS)),) 20 | -include $(C++_DEPS) 21 | endif 22 | ifneq ($(strip $(C_UPPER_DEPS)),) 23 | -include $(C_UPPER_DEPS) 24 | endif 25 | ifneq ($(strip $(CXX_DEPS)),) 26 | -include $(CXX_DEPS) 27 | endif 28 | ifneq ($(strip $(C_DEPS)),) 29 | -include $(C_DEPS) 30 | endif 31 | ifneq ($(strip $(CPP_DEPS)),) 32 | -include $(CPP_DEPS) 33 | endif 34 | endif 35 | 36 | -include ../makefile.defs 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | 40 | # All Target 41 | all: DisplayNixie3x 42 | 43 | # Tool invocations 44 | DisplayNixie3x: $(OBJS) $(USER_OBJS) 45 | @echo 'Building target: $@' 46 | @echo 'Invoking: Cross G++ Linker' 47 | g++ -o "DisplayNixie3x" $(OBJS) $(USER_OBJS) $(LIBS) 48 | @echo 'Finished building target: $@' 49 | @echo ' ' 50 | 51 | # Other Targets 52 | clean: 53 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) DisplayNixie3x 54 | -@echo ' ' 55 | 56 | .PHONY: all clean dependents 57 | .SECONDARY: 58 | 59 | -include ../makefile.targets 60 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := -lwiringPi 8 | 9 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | C_UPPER_SRCS := 6 | CXX_SRCS := 7 | C++_SRCS := 8 | OBJ_SRCS := 9 | CC_SRCS := 10 | ASM_SRCS := 11 | C_SRCS := 12 | CPP_SRCS := 13 | O_SRCS := 14 | S_UPPER_SRCS := 15 | CC_DEPS := 16 | C++_DEPS := 17 | EXECUTABLES := 18 | OBJS := 19 | C_UPPER_DEPS := 20 | CXX_DEPS := 21 | C_DEPS := 22 | CPP_DEPS := 23 | 24 | # Every subdirectory with source files must be described here 25 | SUBDIRS := \ 26 | src \ 27 | 28 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/src/DisplayNixie3x.d: -------------------------------------------------------------------------------- 1 | src/DisplayNixie3x.d: ../src/DisplayNixie3x.cpp 2 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/src/DisplayNixie3x.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware for NCS314 v3.x/DisplayNixie3x/Debug/src/DisplayNixie3x.o -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | CPP_SRCS += \ 7 | ../src/DisplayNixie3x.cpp 8 | 9 | OBJS += \ 10 | ./src/DisplayNixie3x.o 11 | 12 | CPP_DEPS += \ 13 | ./src/DisplayNixie3x.d 14 | 15 | 16 | # Each subdirectory must supply rules for building sources it contributes 17 | src/%.o: ../src/%.cpp 18 | @echo 'Building file: $<' 19 | @echo 'Invoking: Cross G++ Compiler' 20 | g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 21 | @echo 'Finished building: $<' 22 | @echo ' ' 23 | 24 | 25 | -------------------------------------------------------------------------------- /Firmware for NCS314 v3.x/DisplayNixie3x/src/DisplayNixie3x.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : DisplayNixie.cpp 3 | // Author : GRA&AFCH 4 | // Version : v1.0 5 | // Copyright : Free 6 | // Description : Display time on shields NCS314 v3.x 7 | // Date : 27.04.2020 8 | //============================================================================ 9 | 10 | #define _VERSION "1.0 for NCS314 HW Version 3.x" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 23 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 24 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 25 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 26 | 27 | using namespace std; 28 | #define LEpin 3 29 | #define SHDNpin 2 30 | #define UP_BUTTON_PIN 1 31 | #define DOWN_BUTTON_PIN 4 32 | #define MODE_BUTTON_PIN 5 33 | #define BUZZER_PIN 0 34 | #define I2CAdress 0x68 35 | #define I2CFlush 0 36 | 37 | #define DEBOUNCE_DELAY 150 38 | #define TOTAL_DELAY 17 39 | 40 | #define SECOND_REGISTER 0x0 41 | #define MINUTE_REGISTER 0x1 42 | #define HOUR_REGISTER 0x2 43 | #define WEEK_REGISTER 0x3 44 | #define DAY_REGISTER 0x4 45 | #define MONTH_REGISTER 0x5 46 | #define YEAR_REGISTER 0x6 47 | 48 | #define RED_LIGHT_PIN 28 49 | #define GREEN_LIGHT_PIN 27 50 | #define BLUE_LIGHT_PIN 29 51 | #define MAX_POWER 100 52 | 53 | #define UPPER_DOTS_MASK 0x80000000 54 | #define LOWER_DOTS_MASK 0x40000000 55 | 56 | #define LEFT_REPR_START 5 57 | #define LEFT_BUFFER_START 0 58 | #define RIGHT_REPR_START 2 59 | #define RIGHT_BUFFER_START 4 60 | 61 | uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 62 | 63 | int fileDesc; 64 | int redLight = 100; 65 | int greenLight = 0; 66 | int blueLight = 0; 67 | int lightCycle = 0; 68 | bool dotState = 0; 69 | int rotator = 0; 70 | 71 | int bcdToDec(int val) { 72 | return ((val / 16 * 10) + (val % 16)); 73 | } 74 | 75 | int decToBcd(int val) { 76 | return ((val / 10 * 16) + (val % 10)); 77 | } 78 | 79 | tm addHourToDate(tm date) { 80 | date.tm_hour += 1; 81 | mktime(&date); 82 | return date; 83 | } 84 | 85 | tm addMinuteToDate(tm date) { 86 | date.tm_min += 1; 87 | mktime(&date); 88 | return date; 89 | } 90 | 91 | tm getRTCDate() { 92 | wiringPiI2CWrite(fileDesc, I2CFlush); 93 | tm date; 94 | date.tm_sec = bcdToDec(wiringPiI2CReadReg8(fileDesc,SECOND_REGISTER)); 95 | date.tm_min = bcdToDec(wiringPiI2CReadReg8(fileDesc,MINUTE_REGISTER)); 96 | date.tm_hour = bcdToDec(wiringPiI2CReadReg8(fileDesc,HOUR_REGISTER)); 97 | date.tm_wday = bcdToDec(wiringPiI2CReadReg8(fileDesc,WEEK_REGISTER)); 98 | date.tm_mday = bcdToDec(wiringPiI2CReadReg8(fileDesc,DAY_REGISTER)); 99 | date.tm_mon = bcdToDec(wiringPiI2CReadReg8(fileDesc,MONTH_REGISTER)); 100 | date.tm_year = bcdToDec(wiringPiI2CReadReg8(fileDesc,YEAR_REGISTER)); 101 | date.tm_isdst = 0; 102 | return date; 103 | } 104 | 105 | void updateRTCHour(tm date) { 106 | wiringPiI2CWrite(fileDesc, I2CFlush); 107 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 108 | wiringPiI2CWrite(fileDesc, I2CFlush); 109 | } 110 | 111 | void updateRTCMinute(tm date) { 112 | wiringPiI2CWrite(fileDesc, I2CFlush); 113 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 114 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 115 | wiringPiI2CWrite(fileDesc, I2CFlush); 116 | } 117 | void resetRTCSecond() { 118 | wiringPiI2CWrite(fileDesc, I2CFlush); 119 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER, 0); 120 | wiringPiI2CWrite(fileDesc, I2CFlush); 121 | } 122 | 123 | void writeRTCDate(tm date) { 124 | wiringPiI2CWrite(fileDesc, I2CFlush); 125 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER,decToBcd(date.tm_sec)); 126 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 127 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 128 | wiringPiI2CWriteReg8(fileDesc,WEEK_REGISTER,decToBcd(date.tm_wday)); 129 | wiringPiI2CWriteReg8(fileDesc,DAY_REGISTER,decToBcd(date.tm_mday)); 130 | wiringPiI2CWriteReg8(fileDesc,MONTH_REGISTER,decToBcd(date.tm_mon)); 131 | wiringPiI2CWriteReg8(fileDesc,YEAR_REGISTER,decToBcd(date.tm_year)); 132 | wiringPiI2CWrite(fileDesc, I2CFlush); 133 | } 134 | 135 | void initPin(int pin) { 136 | pinMode(pin, INPUT); 137 | pullUpDnControl(pin, PUD_UP); 138 | 139 | } 140 | 141 | void funcMode(void) { 142 | static unsigned long modeTime = 0; 143 | if ((millis() - modeTime) > DEBOUNCE_DELAY) { 144 | puts("MODE button was pressed."); 145 | resetRTCSecond(); 146 | modeTime = millis(); 147 | } 148 | } 149 | 150 | void dotBlink() 151 | { 152 | static unsigned int lastTimeBlink=millis(); 153 | 154 | if ((millis() - lastTimeBlink) > 1000) 155 | { 156 | lastTimeBlink=millis(); 157 | dotState = !dotState; 158 | } 159 | } 160 | 161 | /*void rotateFireWorks() { 162 | int fireworks[] = {0,0,1, 163 | -1,0,0, 164 | 0,1,0, 165 | 0,0,-1, 166 | 1,0,0, 167 | 0,-1,0 168 | }; 169 | redLight += fireworks[rotator * 3]; 170 | greenLight += fireworks[rotator * 3 + 1]; 171 | blueLight += fireworks[rotator * 3 + 2]; 172 | softPwmWrite(RED_LIGHT_PIN, redLight); 173 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 174 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 175 | lightCycle = lightCycle + 1; 176 | if (lightCycle == MAX_POWER) { 177 | rotator = rotator + 1; 178 | lightCycle = 0; 179 | } 180 | if (rotator > 5) 181 | rotator = 0; 182 | }*/ 183 | 184 | uint32_t get32Rep(char * _stringToDisplay, int start) { 185 | uint32_t var32 = 0; 186 | 187 | var32= (SymbolArray[_stringToDisplay[start]-0x30])<<20; 188 | var32|=(SymbolArray[_stringToDisplay[start - 1]-0x30])<<10; 189 | var32|=(SymbolArray[_stringToDisplay[start - 2]-0x30]); 190 | return var32; 191 | } 192 | 193 | void fillBuffer(uint32_t var32, unsigned char * buffer, int start) { 194 | 195 | buffer[start] = var32>>24; 196 | buffer[start + 1] = var32>>16; 197 | buffer[start + 2] = var32>>8; 198 | buffer[start + 3] = var32; 199 | } 200 | 201 | 202 | uint32_t addBlinkTo32Rep(uint32_t var) { 203 | if (dotState) 204 | { 205 | var &=~LOWER_DOTS_MASK; 206 | var &=~UPPER_DOTS_MASK; 207 | } 208 | else 209 | { 210 | var |=LOWER_DOTS_MASK; 211 | var |=UPPER_DOTS_MASK; 212 | } 213 | return var; 214 | } 215 | 216 | char _stringToDisplay[8]; 217 | void doIndication(); 218 | 219 | int main(int argc, char* argv[]) { 220 | printf("Nixie Clock v%s \n\r", _VERSION); 221 | wiringPiSetup(); 222 | //softToneCreate (BUZZER_PIN); 223 | //softToneWrite(BUZZER_PIN, 1000); 224 | softPwmCreate(RED_LIGHT_PIN, 100, MAX_POWER); 225 | softPwmCreate(GREEN_LIGHT_PIN, 0, MAX_POWER); 226 | softPwmCreate(BLUE_LIGHT_PIN, 0, MAX_POWER); 227 | initPin(UP_BUTTON_PIN); 228 | initPin(DOWN_BUTTON_PIN); 229 | initPin(MODE_BUTTON_PIN); 230 | wiringPiISR(MODE_BUTTON_PIN,INT_EDGE_RISING,&funcMode); 231 | fileDesc = wiringPiI2CSetup(I2CAdress); 232 | 233 | tm date = getRTCDate(); 234 | time_t seconds = time(NULL); 235 | tm* timeinfo = localtime (&seconds); 236 | date.tm_mday = timeinfo->tm_mday; 237 | date.tm_wday = timeinfo->tm_wday; 238 | date.tm_mon = timeinfo->tm_mon + 1; 239 | date.tm_year = timeinfo->tm_year - 100; 240 | writeRTCDate(date); 241 | 242 | if (wiringPiSPISetupMode (0, 2000000, 3)) { 243 | puts("SPI ok"); 244 | } 245 | else { 246 | puts("SPI NOT ok"); 247 | return 0; 248 | } 249 | 250 | pinMode(SHDNpin, OUTPUT); 251 | digitalWrite(SHDNpin, HIGH); //HIGH = ON 252 | 253 | long hourDelay = millis(); 254 | long minuteDelay = hourDelay; 255 | do { 256 | //char _stringToDisplay[8]; 257 | date = getRTCDate(); 258 | char* format ="%H%M%S"; 259 | strftime(_stringToDisplay, 8, format, &date); 260 | 261 | 262 | pinMode(LEpin, OUTPUT); 263 | dotBlink(); 264 | 265 | doIndication(); 266 | 267 | if (digitalRead(UP_BUTTON_PIN) == 0 && (millis() - hourDelay) > DEBOUNCE_DELAY) { 268 | updateRTCHour(addHourToDate(date)); 269 | hourDelay = millis(); 270 | } 271 | if (digitalRead(DOWN_BUTTON_PIN) == 0 && (millis() - minuteDelay) > DEBOUNCE_DELAY) { 272 | updateRTCMinute(addMinuteToDate(date)); 273 | minuteDelay = millis(); 274 | } 275 | 276 | // rotateFireWorks(); 277 | 278 | delay (TOTAL_DELAY); 279 | } 280 | while (true); 281 | return 0; 282 | } 283 | 284 | 285 | #define UpperDotsMask 0x80000000 286 | #define LowerDotsMask 0x40000000 287 | 288 | void doIndication() 289 | { 290 | 291 | unsigned long Var32=0; 292 | unsigned long New32_L=0; 293 | unsigned long New32_H=0; 294 | unsigned char buff[8]; 295 | 296 | long digits=atoi(_stringToDisplay); 297 | 298 | /********************************************************** 299 | * Data format incomin [H1][H2][M1][M2][S1][S2] 300 | *********************************************************/ 301 | 302 | //-------- REG 1 ----------------------------------------------- 303 | Var32=0; 304 | 305 | Var32|=(unsigned long)(SymbolArray[digits%10])<<20; // s2 306 | digits=digits/10; 307 | 308 | Var32|=(unsigned long)(SymbolArray[digits%10])<<10; //s1 309 | digits=digits/10; 310 | 311 | Var32|=(unsigned long)(SymbolArray[digits%10]); //m2 312 | digits=digits/10; 313 | 314 | if (dotState) Var32|=LowerDotsMask; 315 | else Var32&=~LowerDotsMask; 316 | 317 | if (dotState) Var32|=UpperDotsMask; 318 | else Var32&=~UpperDotsMask; 319 | 320 | for (int i=1; i<=32; i++) 321 | { 322 | i=i+32; 323 | int newindex=16*(3-(ceil((float)i/4)*4-i))+ceil((float)i/4); 324 | i=i-32; 325 | if (newindex<=32) bitWrite(New32_L, newindex-1, bitRead(Var32, i-1)); 326 | else bitWrite(New32_H, newindex-32-1, bitRead(Var32, i-1)); 327 | } 328 | //------------------------------------------------------------------------- 329 | 330 | //-------- REG 0 ----------------------------------------------- 331 | Var32=0; 332 | 333 | Var32|=(unsigned long)(SymbolArray[digits%10])<<20; // m1 334 | digits=digits/10; 335 | 336 | Var32|= (unsigned long)(SymbolArray[digits%10])<<10; //h2 337 | digits=digits/10; 338 | 339 | Var32|= (unsigned long)SymbolArray[digits%10]; //h1 340 | digits=digits/10; 341 | 342 | if (dotState) Var32|=LowerDotsMask; 343 | else Var32&=~LowerDotsMask; 344 | 345 | if (dotState) Var32|=UpperDotsMask; 346 | else Var32&=~UpperDotsMask; 347 | 348 | for (int i=1; i<=32; i++) 349 | { 350 | int newindex=16*(3-(ceil((float)i/4)*4-i))+ceil((float)i/4); 351 | if (newindex<=32) bitWrite(New32_L, newindex-1, bitRead(Var32, i-1)); 352 | else bitWrite(New32_H, newindex-32-1, bitRead(Var32, i-1)); 353 | } 354 | 355 | buff[0] = New32_H>>24; 356 | buff[1] = New32_H>>16; 357 | buff[2] = New32_H>>8; 358 | buff[3] = New32_H; 359 | 360 | buff[4] = New32_L>>24; 361 | buff[5] = New32_L>>16; 362 | buff[6] = New32_L>>8; 363 | buff[7] = New32_L; 364 | 365 | wiringPiSPIDataRW(0, buff, 8); 366 | 367 | digitalWrite(LEpin, HIGH); // <<-- H -> L 368 | 369 | digitalWrite(LEpin, LOW); //<<-- H -> L 370 | 371 | //------------------------------------------------------------------------- 372 | } 373 | 374 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 80 | 81 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DisplayNixie 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/delimiter=\: 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/delimiter=\: 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/delimiter=\: 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/operation=remove 8 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 9 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/delimiter=\: 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/operation=remove 12 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 13 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 14 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/DisplayNixie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware for NCS318/DisplayNixie/Debug/DisplayNixie -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include src/subdir.mk 12 | -include subdir.mk 13 | -include objects.mk 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | ifneq ($(strip $(CC_DEPS)),) 17 | -include $(CC_DEPS) 18 | endif 19 | ifneq ($(strip $(C++_DEPS)),) 20 | -include $(C++_DEPS) 21 | endif 22 | ifneq ($(strip $(C_UPPER_DEPS)),) 23 | -include $(C_UPPER_DEPS) 24 | endif 25 | ifneq ($(strip $(CXX_DEPS)),) 26 | -include $(CXX_DEPS) 27 | endif 28 | ifneq ($(strip $(C_DEPS)),) 29 | -include $(C_DEPS) 30 | endif 31 | ifneq ($(strip $(CPP_DEPS)),) 32 | -include $(CPP_DEPS) 33 | endif 34 | endif 35 | 36 | -include ../makefile.defs 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | 40 | # All Target 41 | all: DisplayNixie 42 | 43 | # Tool invocations 44 | DisplayNixie: $(OBJS) $(USER_OBJS) 45 | @echo 'Building target: $@' 46 | @echo 'Invoking: Cross G++ Linker' 47 | g++ -o "DisplayNixie" $(OBJS) $(USER_OBJS) $(LIBS) 48 | @echo 'Finished building target: $@' 49 | @echo ' ' 50 | 51 | # Other Targets 52 | clean: 53 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) DisplayNixie 54 | -@echo ' ' 55 | 56 | .PHONY: all clean dependents 57 | .SECONDARY: 58 | 59 | -include ../makefile.targets 60 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := -lwiringPi 8 | 9 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | C_UPPER_SRCS := 6 | CXX_SRCS := 7 | C++_SRCS := 8 | OBJ_SRCS := 9 | CC_SRCS := 10 | ASM_SRCS := 11 | C_SRCS := 12 | CPP_SRCS := 13 | O_SRCS := 14 | S_UPPER_SRCS := 15 | CC_DEPS := 16 | C++_DEPS := 17 | EXECUTABLES := 18 | OBJS := 19 | C_UPPER_DEPS := 20 | CXX_DEPS := 21 | C_DEPS := 22 | CPP_DEPS := 23 | 24 | # Every subdirectory with source files must be described here 25 | SUBDIRS := \ 26 | src \ 27 | 28 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/src/DisplayNixie.d: -------------------------------------------------------------------------------- 1 | src/DisplayNixie.d: ../src/DisplayNixie.cpp 2 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/src/DisplayNixie.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware for NCS318/DisplayNixie/Debug/src/DisplayNixie.o -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | CPP_SRCS += \ 7 | ../src/DisplayNixie.cpp 8 | 9 | OBJS += \ 10 | ./src/DisplayNixie.o 11 | 12 | CPP_DEPS += \ 13 | ./src/DisplayNixie.d 14 | 15 | 16 | # Each subdirectory must supply rules for building sources it contributes 17 | src/%.o: ../src/%.cpp 18 | @echo 'Building file: $<' 19 | @echo 'Invoking: Cross G++ Compiler' 20 | g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 21 | @echo 'Finished building: $<' 22 | @echo ' ' 23 | 24 | 25 | -------------------------------------------------------------------------------- /Firmware for NCS318/DisplayNixie/src/DisplayNixie.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : DisplayNixie.cpp 3 | // Author : GRA&AFCH 4 | // Version : v1.3 5 | // Copyright : Free 6 | // Description : Display time on shields NCS318 v1.1 7 | //============================================================================ 8 | 9 | #define _VERSION "1.3" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | #define LEpin 3 22 | #define UP_BUTTON_PIN 1 23 | #define DOWN_BUTTON_PIN 4 24 | #define MODE_BUTTON_PIN 5 25 | #define BUZZER_PIN 0 26 | #define I2CAdress 0x68 27 | #define I2CFlush 0 28 | 29 | #define DEBOUNCE_DELAY 150 30 | #define TOTAL_DELAY 17 31 | 32 | #define SECOND_REGISTER 0x0 33 | #define MINUTE_REGISTER 0x1 34 | #define HOUR_REGISTER 0x2 35 | #define WEEK_REGISTER 0x3 36 | #define DAY_REGISTER 0x4 37 | #define MONTH_REGISTER 0x5 38 | #define YEAR_REGISTER 0x6 39 | 40 | //#define RED_LIGHT_PIN 28 41 | //#define GREEN_LIGHT_PIN 27 42 | //#define BLUE_LIGHT_PIN 29 43 | #define MAX_POWER 100 44 | 45 | #define UPPER_DOTS_MASK 0x80000000 46 | #define LOWER_DOTS_MASK 0x40000000 47 | 48 | #define LEFT_REPR_START 5 49 | #define LEFT_BUFFER_START 0 50 | #define RIGHT_REPR_START 2 51 | #define RIGHT_BUFFER_START 4 52 | 53 | uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 54 | 55 | int fileDesc; 56 | int redLight = 100; 57 | int greenLight = 0; 58 | int blueLight = 0; 59 | int lightCycle = 0; 60 | bool dotState = 0; 61 | int rotator = 0; 62 | 63 | int bcdToDec(int val) { 64 | return ((val / 16 * 10) + (val % 16)); 65 | } 66 | 67 | int decToBcd(int val) { 68 | return ((val / 10 * 16) + (val % 10)); 69 | } 70 | 71 | tm addHourToDate(tm date) { 72 | date.tm_hour += 1; 73 | mktime(&date); 74 | return date; 75 | } 76 | 77 | tm addMinuteToDate(tm date) { 78 | date.tm_min += 1; 79 | mktime(&date); 80 | return date; 81 | } 82 | 83 | tm getRTCDate() { 84 | wiringPiI2CWrite(fileDesc, I2CFlush); 85 | tm date; 86 | date.tm_sec = bcdToDec(wiringPiI2CReadReg8(fileDesc,SECOND_REGISTER)); 87 | date.tm_min = bcdToDec(wiringPiI2CReadReg8(fileDesc,MINUTE_REGISTER)); 88 | date.tm_hour = bcdToDec(wiringPiI2CReadReg8(fileDesc,HOUR_REGISTER)); 89 | date.tm_wday = bcdToDec(wiringPiI2CReadReg8(fileDesc,WEEK_REGISTER)); 90 | date.tm_mday = bcdToDec(wiringPiI2CReadReg8(fileDesc,DAY_REGISTER)); 91 | date.tm_mon = bcdToDec(wiringPiI2CReadReg8(fileDesc,MONTH_REGISTER)); 92 | date.tm_year = bcdToDec(wiringPiI2CReadReg8(fileDesc,YEAR_REGISTER)); 93 | date.tm_isdst = 0; 94 | return date; 95 | } 96 | 97 | void updateRTCHour(tm date) { 98 | wiringPiI2CWrite(fileDesc, I2CFlush); 99 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 100 | wiringPiI2CWrite(fileDesc, I2CFlush); 101 | } 102 | 103 | void updateRTCMinute(tm date) { 104 | wiringPiI2CWrite(fileDesc, I2CFlush); 105 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 106 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 107 | wiringPiI2CWrite(fileDesc, I2CFlush); 108 | } 109 | void resetRTCSecond() { 110 | wiringPiI2CWrite(fileDesc, I2CFlush); 111 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER, 0); 112 | wiringPiI2CWrite(fileDesc, I2CFlush); 113 | } 114 | 115 | void writeRTCDate(tm date) { 116 | wiringPiI2CWrite(fileDesc, I2CFlush); 117 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER,decToBcd(date.tm_sec)); 118 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 119 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 120 | wiringPiI2CWriteReg8(fileDesc,WEEK_REGISTER,decToBcd(date.tm_wday)); 121 | wiringPiI2CWriteReg8(fileDesc,DAY_REGISTER,decToBcd(date.tm_mday)); 122 | wiringPiI2CWriteReg8(fileDesc,MONTH_REGISTER,decToBcd(date.tm_mon)); 123 | wiringPiI2CWriteReg8(fileDesc,YEAR_REGISTER,decToBcd(date.tm_year)); 124 | wiringPiI2CWrite(fileDesc, I2CFlush); 125 | } 126 | 127 | void initPin(int pin) { 128 | pinMode(pin, INPUT); 129 | pullUpDnControl(pin, PUD_UP); 130 | 131 | } 132 | 133 | void funcMode(void) { 134 | static unsigned long modeTime = 0; 135 | if ((millis() - modeTime) > DEBOUNCE_DELAY) { 136 | puts("MODE button was pressed."); 137 | resetRTCSecond(); 138 | modeTime = millis(); 139 | } 140 | } 141 | 142 | 143 | 144 | uint32_t get32Rep(char * _stringToDisplay, int start) { 145 | uint32_t var32 = 0; 146 | 147 | var32= (SymbolArray[_stringToDisplay[start]-0x30])<<20; 148 | var32|=(SymbolArray[_stringToDisplay[start - 1]-0x30])<<10; 149 | var32|=(SymbolArray[_stringToDisplay[start - 2]-0x30]); 150 | return var32; 151 | } 152 | 153 | void fillBuffer(uint32_t var32, unsigned char * buffer, int start) { 154 | buffer[start] = var32>>24; 155 | buffer[start + 1] = var32>>16; 156 | buffer[start + 2] = var32>>8; 157 | buffer[start + 3] = var32; 158 | } 159 | 160 | void dotBlink() 161 | { 162 | static unsigned int lastTimeBlink=millis(); 163 | 164 | if ((millis() - lastTimeBlink) > 1000) 165 | { 166 | lastTimeBlink=millis(); 167 | dotState = !dotState; 168 | } 169 | } 170 | /* 171 | void rotateFireWorks() { 172 | int fireworks[] = {0,0,1, 173 | -1,0,0, 174 | 0,1,0, 175 | 0,0,-1, 176 | 1,0,0, 177 | 0,-1,0 178 | }; 179 | redLight += fireworks[rotator * 3]; 180 | greenLight += fireworks[rotator * 3 + 1]; 181 | blueLight += fireworks[rotator * 3 + 2]; 182 | softPwmWrite(RED_LIGHT_PIN, redLight); 183 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 184 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 185 | lightCycle = lightCycle + 1; 186 | if (lightCycle == MAX_POWER) { 187 | rotator = rotator + 1; 188 | lightCycle = 0; 189 | } 190 | if (rotator > 5) 191 | rotator = 0; 192 | }*/ 193 | 194 | uint32_t addBlinkTo32Rep(uint32_t var) { 195 | if (dotState) 196 | { 197 | var &=~LOWER_DOTS_MASK; 198 | var &=~UPPER_DOTS_MASK; 199 | } 200 | else 201 | { 202 | var |=LOWER_DOTS_MASK; 203 | var |=UPPER_DOTS_MASK; 204 | } 205 | return var; 206 | } 207 | 208 | 209 | int main(int argc, char* argv[]) { 210 | printf("Nixie Clock v%s \n\r", _VERSION); 211 | wiringPiSetup(); 212 | //softToneCreate (BUZZER_PIN); 213 | //softToneWrite(BUZZER_PIN, 1000); 214 | 215 | /*softPwmCreate(RED_LIGHT_PIN, 100, MAX_POWER); 216 | softPwmCreate(GREEN_LIGHT_PIN, 0, MAX_POWER); 217 | softPwmCreate(BLUE_LIGHT_PIN, 0, MAX_POWER); 218 | */ 219 | initPin(UP_BUTTON_PIN); 220 | initPin(DOWN_BUTTON_PIN); 221 | initPin(MODE_BUTTON_PIN); 222 | //wiringPiISR(MODE_BUTTON_PIN,INT_EDGE_RISING,&funcMode); 223 | fileDesc = wiringPiI2CSetup(I2CAdress); 224 | 225 | tm date = getRTCDate(); 226 | time_t seconds = time(NULL); 227 | tm* timeinfo = localtime (&seconds); 228 | date.tm_mday = timeinfo->tm_mday; 229 | date.tm_wday = timeinfo->tm_wday; 230 | date.tm_mon = timeinfo->tm_mon + 1; 231 | date.tm_year = timeinfo->tm_year - 100; 232 | writeRTCDate(date); 233 | 234 | if (wiringPiSPISetupMode (0, 2000000, 2)) { 235 | puts("SPI ok"); 236 | } 237 | else { 238 | puts("SPI NOT ok"); 239 | return 0; 240 | } 241 | 242 | long hourDelay = millis(); 243 | long minuteDelay = hourDelay; 244 | long modeDelay=hourDelay; 245 | do { 246 | char _stringToDisplay[8]; 247 | date = getRTCDate(); 248 | char* format ="%H%M%S"; 249 | strftime(_stringToDisplay, 8, format, &date); 250 | 251 | 252 | pinMode(LEpin, OUTPUT); 253 | dotBlink(); 254 | 255 | unsigned char buff[8]; 256 | 257 | uint32_t var32 = get32Rep(_stringToDisplay, LEFT_REPR_START); 258 | var32 = addBlinkTo32Rep(var32); 259 | fillBuffer(var32, buff , LEFT_BUFFER_START); 260 | 261 | var32 = get32Rep(_stringToDisplay, RIGHT_REPR_START); 262 | var32 = addBlinkTo32Rep(var32); 263 | fillBuffer(var32, buff , RIGHT_BUFFER_START); 264 | 265 | if (digitalRead(UP_BUTTON_PIN) == 0 && (millis() - hourDelay) > DEBOUNCE_DELAY) { 266 | updateRTCHour(addHourToDate(date)); 267 | hourDelay = millis(); 268 | } 269 | if (digitalRead(DOWN_BUTTON_PIN) == 0 && (millis() - minuteDelay) > DEBOUNCE_DELAY) { 270 | updateRTCMinute(addMinuteToDate(date)); 271 | minuteDelay = millis(); 272 | } 273 | 274 | if (digitalRead(MODE_BUTTON_PIN) == 0 && (millis() - modeDelay) > DEBOUNCE_DELAY) { 275 | resetRTCSecond(); 276 | modeDelay = millis(); 277 | } 278 | 279 | //rotateFireWorks(); 280 | digitalWrite(LEpin, LOW); 281 | wiringPiSPIDataRW(0, buff, 8); 282 | digitalWrite(LEpin, HIGH); 283 | delay (TOTAL_DELAY); 284 | } 285 | while (true); 286 | return 0; 287 | } 288 | -------------------------------------------------------------------------------- /Firmware/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 80 | 81 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /Firmware/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DisplayNixie 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /Firmware/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Firmware/.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/delimiter=\: 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/delimiter=\: 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/CPLUS_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/delimiter=\: 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/C_INCLUDE_PATH/operation=remove 8 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 9 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/delimiter=\: 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/LIBRARY_PATH/operation=remove 12 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/append=true 13 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.493283321/appendContributed=true 14 | -------------------------------------------------------------------------------- /Firmware/Debug/DisplayNixie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware/Debug/DisplayNixie -------------------------------------------------------------------------------- /Firmware/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include src/subdir.mk 12 | -include subdir.mk 13 | -include objects.mk 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | ifneq ($(strip $(CC_DEPS)),) 17 | -include $(CC_DEPS) 18 | endif 19 | ifneq ($(strip $(C++_DEPS)),) 20 | -include $(C++_DEPS) 21 | endif 22 | ifneq ($(strip $(C_UPPER_DEPS)),) 23 | -include $(C_UPPER_DEPS) 24 | endif 25 | ifneq ($(strip $(CXX_DEPS)),) 26 | -include $(CXX_DEPS) 27 | endif 28 | ifneq ($(strip $(C_DEPS)),) 29 | -include $(C_DEPS) 30 | endif 31 | ifneq ($(strip $(CPP_DEPS)),) 32 | -include $(CPP_DEPS) 33 | endif 34 | endif 35 | 36 | -include ../makefile.defs 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | 40 | # All Target 41 | all: DisplayNixie 42 | 43 | # Tool invocations 44 | DisplayNixie: $(OBJS) $(USER_OBJS) 45 | @echo 'Building target: $@' 46 | @echo 'Invoking: Cross G++ Linker' 47 | g++ -o "DisplayNixie" $(OBJS) $(USER_OBJS) $(LIBS) 48 | @echo 'Finished building target: $@' 49 | @echo ' ' 50 | 51 | # Other Targets 52 | clean: 53 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) DisplayNixie 54 | -@echo ' ' 55 | 56 | .PHONY: all clean dependents 57 | .SECONDARY: 58 | 59 | -include ../makefile.targets 60 | -------------------------------------------------------------------------------- /Firmware/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := -lwiringPi 8 | 9 | -------------------------------------------------------------------------------- /Firmware/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | C_UPPER_SRCS := 6 | CXX_SRCS := 7 | C++_SRCS := 8 | OBJ_SRCS := 9 | CC_SRCS := 10 | ASM_SRCS := 11 | C_SRCS := 12 | CPP_SRCS := 13 | O_SRCS := 14 | S_UPPER_SRCS := 15 | CC_DEPS := 16 | C++_DEPS := 17 | EXECUTABLES := 18 | OBJS := 19 | C_UPPER_DEPS := 20 | CXX_DEPS := 21 | C_DEPS := 22 | CPP_DEPS := 23 | 24 | # Every subdirectory with source files must be described here 25 | SUBDIRS := \ 26 | src \ 27 | 28 | -------------------------------------------------------------------------------- /Firmware/Debug/src/DisplayNixie.d: -------------------------------------------------------------------------------- 1 | src/DisplayNixie.d: ../src/DisplayNixie.cpp 2 | -------------------------------------------------------------------------------- /Firmware/Debug/src/DisplayNixie.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UberEclectic/NixieClockRaspberryPi/2644322b181f55001c0d0ec4c51a809251bcb44b/Firmware/Debug/src/DisplayNixie.o -------------------------------------------------------------------------------- /Firmware/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | CPP_SRCS += \ 7 | ../src/DisplayNixie.cpp 8 | 9 | OBJS += \ 10 | ./src/DisplayNixie.o 11 | 12 | CPP_DEPS += \ 13 | ./src/DisplayNixie.d 14 | 15 | 16 | # Each subdirectory must supply rules for building sources it contributes 17 | src/%.o: ../src/%.cpp 18 | @echo 'Building file: $<' 19 | @echo 'Invoking: Cross G++ Compiler' 20 | g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 21 | @echo 'Finished building: $<' 22 | @echo ' ' 23 | 24 | 25 | -------------------------------------------------------------------------------- /Firmware/src/DisplayNixie.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : DisplayNixie.cpp 3 | // Author : GRA&AFCH 4 | // Version : v2.3 5 | // Copyright : Free 6 | // Description : Display time on shields NCS314 v2.x or NCS312 7 | //============================================================================ 8 | 9 | #define _VERSION "2.3" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | #define R5222_PIN 22 22 | bool HV5222; 23 | #define LEpin 3 24 | #define UP_BUTTON_PIN 1 25 | #define DOWN_BUTTON_PIN 4 26 | #define MODE_BUTTON_PIN 5 27 | #define BUZZER_PIN 0 28 | #define I2CAdress 0x68 29 | #define I2CFlush 0 30 | 31 | #define DEBOUNCE_DELAY 150 32 | #define TOTAL_DELAY 17 33 | 34 | #define SECOND_REGISTER 0x0 35 | #define MINUTE_REGISTER 0x1 36 | #define HOUR_REGISTER 0x2 37 | #define WEEK_REGISTER 0x3 38 | #define DAY_REGISTER 0x4 39 | #define MONTH_REGISTER 0x5 40 | #define YEAR_REGISTER 0x6 41 | 42 | #define RED_LIGHT_PIN 28 43 | #define GREEN_LIGHT_PIN 27 44 | #define BLUE_LIGHT_PIN 29 45 | #define MAX_POWER 100 46 | 47 | #define UPPER_DOTS_MASK 0x80000000 48 | #define LOWER_DOTS_MASK 0x40000000 49 | 50 | #define LEFT_REPR_START 5 51 | #define LEFT_BUFFER_START 0 52 | #define RIGHT_REPR_START 2 53 | #define RIGHT_BUFFER_START 4 54 | 55 | uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 56 | 57 | int fileDesc; 58 | int redLight = 100; 59 | int greenLight = 0; 60 | int blueLight = 0; 61 | int lightCycle = 0; 62 | bool dotState = 0; 63 | int rotator = 0; 64 | 65 | int bcdToDec(int val) { 66 | return ((val / 16 * 10) + (val % 16)); 67 | } 68 | 69 | int decToBcd(int val) { 70 | return ((val / 10 * 16) + (val % 10)); 71 | } 72 | 73 | tm addHourToDate(tm date) { 74 | date.tm_hour += 1; 75 | mktime(&date); 76 | return date; 77 | } 78 | 79 | tm addMinuteToDate(tm date) { 80 | date.tm_min += 1; 81 | mktime(&date); 82 | return date; 83 | } 84 | 85 | tm getRTCDate() { 86 | wiringPiI2CWrite(fileDesc, I2CFlush); 87 | tm date; 88 | date.tm_sec = bcdToDec(wiringPiI2CReadReg8(fileDesc,SECOND_REGISTER)); 89 | date.tm_min = bcdToDec(wiringPiI2CReadReg8(fileDesc,MINUTE_REGISTER)); 90 | date.tm_hour = bcdToDec(wiringPiI2CReadReg8(fileDesc,HOUR_REGISTER)); 91 | date.tm_wday = bcdToDec(wiringPiI2CReadReg8(fileDesc,WEEK_REGISTER)); 92 | date.tm_mday = bcdToDec(wiringPiI2CReadReg8(fileDesc,DAY_REGISTER)); 93 | date.tm_mon = bcdToDec(wiringPiI2CReadReg8(fileDesc,MONTH_REGISTER)); 94 | date.tm_year = bcdToDec(wiringPiI2CReadReg8(fileDesc,YEAR_REGISTER)); 95 | date.tm_isdst = 0; 96 | return date; 97 | } 98 | 99 | void updateRTCHour(tm date) { 100 | wiringPiI2CWrite(fileDesc, I2CFlush); 101 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 102 | wiringPiI2CWrite(fileDesc, I2CFlush); 103 | } 104 | 105 | void updateRTCMinute(tm date) { 106 | wiringPiI2CWrite(fileDesc, I2CFlush); 107 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 108 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 109 | wiringPiI2CWrite(fileDesc, I2CFlush); 110 | } 111 | void resetRTCSecond() { 112 | wiringPiI2CWrite(fileDesc, I2CFlush); 113 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER, 0); 114 | wiringPiI2CWrite(fileDesc, I2CFlush); 115 | } 116 | 117 | void writeRTCDate(tm date) { 118 | wiringPiI2CWrite(fileDesc, I2CFlush); 119 | wiringPiI2CWriteReg8(fileDesc,SECOND_REGISTER,decToBcd(date.tm_sec)); 120 | wiringPiI2CWriteReg8(fileDesc,MINUTE_REGISTER,decToBcd(date.tm_min)); 121 | wiringPiI2CWriteReg8(fileDesc,HOUR_REGISTER,decToBcd(date.tm_hour)); 122 | wiringPiI2CWriteReg8(fileDesc,WEEK_REGISTER,decToBcd(date.tm_wday)); 123 | wiringPiI2CWriteReg8(fileDesc,DAY_REGISTER,decToBcd(date.tm_mday)); 124 | wiringPiI2CWriteReg8(fileDesc,MONTH_REGISTER,decToBcd(date.tm_mon)); 125 | wiringPiI2CWriteReg8(fileDesc,YEAR_REGISTER,decToBcd(date.tm_year)); 126 | wiringPiI2CWrite(fileDesc, I2CFlush); 127 | } 128 | 129 | void initPin(int pin) { 130 | pinMode(pin, INPUT); 131 | pullUpDnControl(pin, PUD_UP); 132 | 133 | } 134 | 135 | void funcMode(void) { 136 | static unsigned long modeTime = 0; 137 | if ((millis() - modeTime) > DEBOUNCE_DELAY) { 138 | puts("MODE button was pressed."); 139 | resetRTCSecond(); 140 | modeTime = millis(); 141 | } 142 | } 143 | 144 | 145 | 146 | uint32_t get32Rep(char * _stringToDisplay, int start) { 147 | uint32_t var32 = 0; 148 | 149 | var32= (SymbolArray[_stringToDisplay[start]-0x30])<<20; 150 | var32|=(SymbolArray[_stringToDisplay[start - 1]-0x30])<<10; 151 | var32|=(SymbolArray[_stringToDisplay[start - 2]-0x30]); 152 | return var32; 153 | } 154 | 155 | void fillBuffer(uint32_t var32, unsigned char * buffer, int start) { 156 | buffer[start] = var32>>24; 157 | buffer[start + 1] = var32>>16; 158 | buffer[start + 2] = var32>>8; 159 | buffer[start + 3] = var32; 160 | } 161 | 162 | void dotBlink() 163 | { 164 | static unsigned int lastTimeBlink=millis(); 165 | 166 | if ((millis() - lastTimeBlink) > 1000) 167 | { 168 | lastTimeBlink=millis(); 169 | dotState = !dotState; 170 | } 171 | } 172 | 173 | void rotateFireWorks() { 174 | int fireworks[] = {0,0,1, 175 | -1,0,0, 176 | 0,1,0, 177 | 0,0,-1, 178 | 1,0,0, 179 | 0,-1,0 180 | }; 181 | redLight += fireworks[rotator * 3]; 182 | greenLight += fireworks[rotator * 3 + 1]; 183 | blueLight += fireworks[rotator * 3 + 2]; 184 | softPwmWrite(RED_LIGHT_PIN, redLight); 185 | softPwmWrite(GREEN_LIGHT_PIN, greenLight); 186 | softPwmWrite(BLUE_LIGHT_PIN, blueLight); 187 | lightCycle = lightCycle + 1; 188 | if (lightCycle == MAX_POWER) { 189 | rotator = rotator + 1; 190 | lightCycle = 0; 191 | } 192 | if (rotator > 5) 193 | rotator = 0; 194 | } 195 | 196 | uint32_t addBlinkTo32Rep(uint32_t var) { 197 | if (dotState) 198 | { 199 | var &=~LOWER_DOTS_MASK; 200 | var &=~UPPER_DOTS_MASK; 201 | } 202 | else 203 | { 204 | var |=LOWER_DOTS_MASK; 205 | var |=UPPER_DOTS_MASK; 206 | } 207 | return var; 208 | } 209 | 210 | //uint64_t* reverseBit(uint64_t num); 211 | uint64_t reverseBit(uint64_t num); 212 | 213 | int main(int argc, char* argv[]) { 214 | printf("Nixie Clock v%s \n\r", _VERSION); 215 | wiringPiSetup(); 216 | //softToneCreate (BUZZER_PIN); 217 | //softToneWrite(BUZZER_PIN, 1000); 218 | softPwmCreate(RED_LIGHT_PIN, 100, MAX_POWER); 219 | softPwmCreate(GREEN_LIGHT_PIN, 0, MAX_POWER); 220 | softPwmCreate(BLUE_LIGHT_PIN, 0, MAX_POWER); 221 | initPin(UP_BUTTON_PIN); 222 | initPin(DOWN_BUTTON_PIN); 223 | initPin(MODE_BUTTON_PIN); 224 | //wiringPiISR(MODE_BUTTON_PIN,INT_EDGE_RISING,&funcMode); 225 | fileDesc = wiringPiI2CSetup(I2CAdress); 226 | 227 | tm date = getRTCDate(); 228 | time_t seconds = time(NULL); 229 | tm* timeinfo = localtime (&seconds); 230 | date.tm_mday = timeinfo->tm_mday; 231 | date.tm_wday = timeinfo->tm_wday; 232 | date.tm_mon = timeinfo->tm_mon + 1; 233 | date.tm_year = timeinfo->tm_year - 100; 234 | writeRTCDate(date); 235 | 236 | if (wiringPiSPISetupMode (0, 2000000, 2)) { 237 | puts("SPI ok"); 238 | } 239 | else { 240 | puts("SPI NOT ok"); 241 | return 0; 242 | } 243 | 244 | pinMode(R5222_PIN, INPUT); 245 | pullUpDnControl(R5222_PIN, PUD_UP); 246 | HV5222=!digitalRead(R5222_PIN); 247 | if (HV5222) puts("R52222 resistor detected. HV5222 algorithm is used."); 248 | uint64_t reverseBuffValue; 249 | 250 | long hourDelay = millis(); 251 | long minuteDelay = hourDelay; 252 | long modeDelay = hourDelay; 253 | do { 254 | char _stringToDisplay[8]; 255 | date = getRTCDate(); 256 | char* format ="%H%M%S"; 257 | strftime(_stringToDisplay, 8, format, &date); 258 | 259 | 260 | pinMode(LEpin, OUTPUT); 261 | dotBlink(); 262 | 263 | unsigned char buff[8]; 264 | 265 | uint32_t var32 = get32Rep(_stringToDisplay, LEFT_REPR_START); 266 | var32 = addBlinkTo32Rep(var32); 267 | 268 | fillBuffer(var32, buff , LEFT_BUFFER_START); 269 | 270 | var32 = get32Rep(_stringToDisplay, RIGHT_REPR_START); 271 | var32 = addBlinkTo32Rep(var32); 272 | 273 | fillBuffer(var32, buff , RIGHT_BUFFER_START); 274 | 275 | if (digitalRead(UP_BUTTON_PIN) == 0 && (millis() - hourDelay) > DEBOUNCE_DELAY) { 276 | updateRTCHour(addHourToDate(date)); 277 | hourDelay = millis(); 278 | } 279 | if (digitalRead(DOWN_BUTTON_PIN) == 0 && (millis() - minuteDelay) > DEBOUNCE_DELAY) { 280 | updateRTCMinute(addMinuteToDate(date)); 281 | minuteDelay = millis(); 282 | } 283 | if (digitalRead(MODE_BUTTON_PIN) == 0 && (millis() - modeDelay) > DEBOUNCE_DELAY) { 284 | resetRTCSecond(); 285 | modeDelay = millis(); 286 | } 287 | 288 | rotateFireWorks(); 289 | digitalWrite(LEpin, LOW); 290 | 291 | if (HV5222) 292 | { 293 | reverseBuffValue=reverseBit(*(uint64_t*)buff); 294 | buff[4]=reverseBuffValue; 295 | buff[5]=reverseBuffValue>>8; 296 | buff[6]=reverseBuffValue>>16; 297 | buff[7]=reverseBuffValue>>24; 298 | buff[0]=reverseBuffValue>>32; 299 | buff[1]=reverseBuffValue>>40; 300 | buff[2]=reverseBuffValue>>48; 301 | buff[3]=reverseBuffValue>>56; 302 | } 303 | 304 | wiringPiSPIDataRW(0, buff, 8); 305 | digitalWrite(LEpin, HIGH); 306 | delay (TOTAL_DELAY); 307 | } 308 | while (true); 309 | return 0; 310 | } 311 | 312 | //uint64_t* reverseBit(uint64_t num) 313 | uint64_t reverseBit(uint64_t num) 314 | { 315 | uint64_t reverse_num=0; 316 | int i; 317 | for (i=0; i<64; i++) 318 | { 319 | if ((num & ((uint64_t)1<"Import", "Genral"->"Existing Project into Workspce". 36 | p.s. The project uses the "wiringPi" library: http://wiringpi.com/download-and-install/ 37 | 38 | Autorun the program at startup: 39 | Edit /home/pi/.bashrc file - add string like this: 40 | sudo "/home/pi/Documents/Eclipse Projects/DisplayNixie/Debug/DisplayNixie" clock 41 | --------------------------------------------------------------------------------