Final Project for 4180 Nixie Tube IoT Clock
Dependencies: 4DGL-uLCD-SE NixieTube MBed_Adafruit-GPS-Library NetServices wave_player mbed spxml
Final Project for ECE 4180
Diff: main.cpp
- Revision:
- 3:d62bb9ee0aa0
- Parent:
- 2:714d63ea1eef
- Child:
- 4:9651e706b36f
--- a/main.cpp Wed Dec 14 03:55:23 2016 +0000 +++ b/main.cpp Wed Dec 14 08:22:40 2016 +0000 @@ -3,7 +3,6 @@ // https://developer.mbed.org/users/mlee350/notebook/adafruit-ultimate-gps-breakout-board/ // https://developer.mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ // https://developer.mbed.org/handbook/LocalFileSystem - // Includes Files #include "mbed.h" #include <string> @@ -17,185 +16,68 @@ #include "HTTPClient.h" #include <string> #include "NTPClient.h" - -/////////////////////// -#define TUBE_1_LED 0x00800 -#define TUBE_2_LED 0x01000 -#define TUBE_3_LED 0x02000 -#define TUBE_4_LED 0x04000 -#define TUBE_5_LED 0x08000 -#define TUBE_6_LED 0x10000 - -#define TUBE_1_CATH 0x20000 -#define TUBE_2_CATH 0x40000 -#define TUBE_3_CATH 0x80000 -#define TUBE_4_CATH 0x100000 -#define TUBE_5_CATH 0x200000 -#define TUBE_6_CATH 0x400000 - -void nixie_shiftout(); -int nixie_id_convert(int digit); -void send_nixie_shiftreg(int cathode_id, int led_bitfield, int tube_bitfield); - - -DigitalOut myled1(LED1); -DigitalOut myled2(LED2); - - -DigitalOut sdi(p24); -DigitalOut scl(p23); -DigitalOut rcl(p22); -PwmOut cen(p21); - -Ticker shifter; - -int curr_tube = 1; - -volatile int digit1 = 1; -volatile int digit2 = 2; -volatile int digit3 = 3; -volatile int digit4 = 4; - - -uint32_t delay1 = 0.0005; -uint32_t delay2 = 0.0045; - -float brightness = 0; - +#include "NixieTube.h" +Serial pc(USBTX, USBRX); +NixieTube Ntube(p24,p23,p22,p21); ///////////////////////// -Serial pc(USBTX, USBRX); EthernetNetIf eth; HTTPClient http; HTTPResult result; - -NTPClient ntp; - - -LocalFileSystem local("local"); // Create the local filesystem under the name "local" -AnalogOut DACout(p18); // DAC for producing sound -wave_player waver(&DACout); // wavplayer object -Serial * gps_Serial; // GPS Interface -uLCD_4DGL uLCD(p13,p14,p15); // serial tx, serial rx, reset pin; +//////////////////////// +NTPClient ntp; // Used for Clock +//////////////////////////////// +LocalFileSystem local("local"); // Create the local filesystem under the name "local" +AnalogOut DACout(p18); // DAC for producing sound +wave_player waver(&DACout); // wavplayer object +Serial * gps_Serial; // GPS Interface +uLCD_4DGL uLCD(p13,p14,p15); // serial tx, serial rx, reset pin; //LCD Files Needs to be local to the ulcd screen - -// Need To Make a few changes here -// Weather fucntion to grab local weather data -// Alarm // -// Clock need to take time and output it to the nixe tubes hr mins -// Initilizing? -// GPS Setup -// Confirm Link On ULCD Screen -// Confirm WIFI setup On ULCD Screen -// Confirm Bluetoth link? display bluetooth decal when connected? Or just Letter B in Blue just as good // Declarations -bool completed = false; // Used for HTTP Request -bool pressPlay = false;//default on pause (song select mode) +bool completed = false; // Used for HTTP Request +bool pressPlay = false; // Default on pause (song select mode) int volume = 0; - -int weather(); +volatile float lattitude = 33.7490; +volatile float longitude = -84.3880; bool gps_setup(); -void display_screen_debug(),request_callback(),parseWeather(),system_setup(),display_weather(),sound_alarm(); - -int main() { - //sound_alarm(1); - //display_weather(0); - pc.baud(9600); - pc.printf("\r\nintializing hardware,...v14\r\n"); - eth.init(); //Use DHCP -sendGETRequest: - EthernetErr ethErr = eth.setup(60000); - int retry = 0; - if (ethErr) { - pc.printf("Error in setup trying again %d",retry); - retry++; - goto sendGETRequest; - } - pc.printf("net ok testing weather\r\n"); - weather(); - - cen.period_us(10000); - cen.write(1.0); - shifter.attach(&nixie_shiftout, 0.001); - - time_t ctTime; - ctTime = time(NULL); +void display_screen_debug(),request_callback(),parseWeather(),system_setup(),display_weather(int),sound_alarm(int),ethernet_setup(); - Host server(IpAddr(), 123, "0.us.pool.ntp.org"); - ntp.setTime(server); - - char hString[3]; - char mString[3]; - int offset = 5; - while(1) { - ctTime = time(NULL) - 3600 * offset; - strftime(hString, 3, "%I", localtime(&ctTime)); - strftime(mString, 3, "%M", localtime(&ctTime)); - - //pc.printf("hour: %s \n min: %s\n", hString, mString); - - int hour = std::atoi(hString); - int min = std::atoi(mString); - - int digit1 = hour / 10; - int digit2 = hour % 10; - - int digit3 = min / 10; - int digit4 = min % 10; - - pc. printf("\n %d, %d, %d, %d", digit1, digit2, digit3, digit4); - wait(5); - //ctTime = time(NULL); - //pc.printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); - } - - return 0; - - - - //eth.disconnect(); - } // Used for obtaining weather Information -void request_callback(HTTPResult r) -{ +void request_callback(HTTPResult r){ result = r; completed = true; } -void parseWeather(SP_XmlElementNode *node, string loc) -{ +void display_weather(int code){ + uLCD.flush_media(); + uLCD.cls(); + uLCD.media_init(); + uLCD.set_sector_address(0x0000,(code*65)); + uLCD.display_control(3); + uLCD.display_image(0,0); + } + +void parseWeather(SP_XmlElementNode *node, string loc){ //extracts current weather XML data fields for LCD SP_XmlHandle handle(node); SP_XmlElementNode * condition = handle.getChild( "item" ).getChild("yweather:condition").toElement(); //display Weather conditions - pc.printf("%d:\r\n", (int)condition->getAttrValue("code")); // Print the name of the city - pc.printf("%s:\r\n", loc); + pc.printf("%s:", loc); //Print the weather conditions - pc.printf("%s\r\n",condition->getAttrValue("text")); + pc.printf("%s",condition->getAttrValue("text")); //Print the termperature (in degrees Celcius) - pc.printf("%sF\r\n",condition->getAttrValue("temp")); + pc.printf("%sF",condition->getAttrValue("temp")); + display_weather(atoi(condition->getAttrValue("code"))); } -// Query Term for Weather -// select+*+from+weather.forecast+where+woeid+in+(SELECT+woeid+FROM+geo.places+WHERE+text%3D%22(33.7490%2C-84.3880)%22) -// Query Website https://developer.yahoo.com/yql/console/#h=select+*+from+weather.forecast+where+woeid+in+(SELECT+woeid+FROM+geo.places+WHERE+text%3D%22(33.7490%2C-84.3880)%22) -//asuming that outputformat of lattitude and logitude is - for west + for east and does not use chars for directionals as that would be dumb -//"https://query.yahooapis.com/v1/public/yql?q=select+*+from+weather.forecast+where+woeid+in+(SELECT+woeid+FROM+geo.places+WHERE+text%3D%22(33.7490%2C-84.3880)%22)", &stream, request_callback); -// "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20%28SELECT%20woeid%20FROM%20geo.places%20WHERE%20text%3D%22(33.7490%2C-84.3880)%22)"(lat log) &stream, request_callback) -// Variable Version -// "https://query.yahooapis.com/v1/public/yql?q=select+*+from+weather.forecast+where+woeid+in+(SELECT+woeid+FROM+geo.places+WHERE+text%3D%22(lat%2Clong)%22)", &stream, request_callback); -// "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20%28SELECT%20woeid%20FROM%20geo.places%20WHERE%20text%3D%22(%.6f%2C%.6f)%22)"(lat log) &stream, request_callback) - -int weather() -{ +int weather(){ +retryweather: completed = false; SP_XmlDomParser parser; HTTPStream stream; char buffer3 [200]; - float lattitude = 33.7490; - float longitude = -84.3880; wait(1); pc.printf("%.6f:",lattitude); pc.printf("%.6f:",longitude); @@ -230,6 +112,7 @@ pc.printf("Weather complete"); } else { pc. printf("Weather Error %d", result); + goto retryweather; return -1; } @@ -247,27 +130,6 @@ } return 0; } - - - -/// Functions will follow here -void display_screen_debug() { - } - -void system_setup () { - - } - -void display_weather(int code){ - uLCD.flush_media(); - uLCD.cls(); - uLCD.media_init(); - //uLCD.printf("\n\nAn SD card is needed for image and video data"); - uLCD.set_sector_address(0x0000,(code*65)); - uLCD.display_image(0,0); - uLCD.cls(); - } - // Need to update so that if it failes to get a GPS fix after say 10 tries it defaults lat and longitude values and time is found thought another method. bool gps_setup(){ Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? @@ -281,6 +143,8 @@ myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); myGPS.sendCommand(PGCMD_ANTENNA); refresh_Timer.start(); //starts the clock on the timer + uLCD.text_width(1); //4X size text + uLCD.text_height(1); uLCD.printf("Starting Up\n"); while(gps_off){ uLCD.cls(); @@ -307,6 +171,8 @@ uLCD.printf("Altitude: %5.2f\n", myGPS.altitude); uLCD.printf("Satellites: %d\n", myGPS.satellites); gps_off = false; + lattitude = myGPS.latitude; + longitude = myGPS.longitude; } } } @@ -319,57 +185,64 @@ waver.play(wave_file,&pressPlay, &volume); //play(FILE *wavefile,bool *pressPlay, int *volume); pressPlay = false; fclose(wave_file); - } +} + -void nixie_shiftout() { - - - switch (curr_tube) { - case 1: - send_nixie_shiftreg(nixie_id_convert(digit1), 0, TUBE_1_CATH); - break; - case 2: - send_nixie_shiftreg(nixie_id_convert(digit2), 0, TUBE_2_CATH); - break; - case 3: - send_nixie_shiftreg(nixie_id_convert(digit3), 0, TUBE_3_CATH); - break; - case 4: - send_nixie_shiftreg(nixie_id_convert(digit4), 0, TUBE_4_CATH); - break; - default: - curr_tube = 1; - } - curr_tube++; - if (curr_tube == 5) { - curr_tube = 1; +int main() { + //sound_alarm(1); + pc.baud(9600); + pc.printf("\r\nintializing hardware,...v15\r\n"); + eth.init(); //Use DHCP +sendGETRequest: + EthernetErr ethErr = eth.setup(60000); + int retry = 0; + if (ethErr) { + pc.printf("Error in setup trying again %d",retry); + retry++; + goto sendGETRequest; } -} - -int nixie_id_convert(int digit) { - if (digit == 0 || digit == -1) { - return digit + 1; - } - if (digit < 10) { - return 11 - digit; - } - if (digit == 10) { - return 11; - } - return 0; -} - -void send_nixie_shiftreg(int cathode_id, int led_bitfield, int tube_bitfield) { - - int buffer = 0; - buffer = 1 << (cathode_id-1) | led_bitfield | tube_bitfield; - - for (int i=23; i >= 0; i--) { - sdi = buffer & (1 << i); - scl = 1; - scl = 0; - } - rcl = 1; - rcl = 0; - -} + pc.printf("net ok testing weather\r\n"); + weather(); + weather(); + time_t ctTime; + ctTime = time(NULL); + Host server(IpAddr(), 123, "0.us.pool.ntp.org"); + ntp.setTime(server); + char hString[3]; + char mString[3]; + int offset = 5; + int old_min2 = 0; + int reset = 0; + while(1) { + ctTime = time(NULL) - 3600 * offset; + strftime(hString, 3, "%I", localtime(&ctTime)); + strftime(mString, 3, "%M", localtime(&ctTime)); + + //pc.printf("hour: %s \n min: %s\n", hString, mString); + + int hour = std::atoi(hString); + int min = std::atoi(mString); + + int hour1 = hour / 10; + int hour2 = hour % 10; + + int min1 = min / 10; + int min2 = min % 10; + + if (min2!=old_min2) { + old_min2=min2; + pc. printf("\n %d, %d, %d, %d\r\n", hour1, hour2, min1, min2); + Ntube.update_all_nixie_tube(hour1, hour2, min1, min2); + reset++; + + } + if (reset>14){ + reset = 0; + weather(); + weather(); + } + wait(5); + //ctTime = time(NULL); + //pc.printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); + } +} \ No newline at end of file