Jump to content

phaseform

Members
  • Content Count

    17
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by phaseform

  1. Credit to pixelk for this code: (I changed the NTP server, removed some possible infinite loops and put it in an Energia sketch) /* ESP8266 connected to Serial1 */ void setup() { // initialize both serial ports: Serial.begin(9600); Serial1.begin(9600); Serial.println("..."); } void loop() { delay(3000); Serial.println(); Serial.println("Getting time.."); int Epoch = GetTime(); Serial.print("Epoch is: "); Serial.println(Epoch); delay(5000); } const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets unsigned long GetTime() { String cmd = "AT+CIPSTART=\"UDP\",\"130.102.128.23\",123"; // NTP server Serial1.println(cmd); delay(2000); if(Serial1.find("Error")){ Serial.print("RECEIVED: Error"); return 0; } int counta = 0; memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) packetBuffer[0] = 0b11100011; // LI, Version, Mode packetBuffer[1] = 0; // Stratum, or type of clock packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision Serial1.print("AT+CIPSEND="); Serial1.println(NTP_PACKET_SIZE); if(Serial1.find(">")) { for (byte i = 0; i < NTP_PACKET_SIZE; i++) { Serial1.write(packetBuffer[i]); delay(5); } }else{ Serial1.println("AT+CIPCLOSE"); return 0; } //Serial1.find("+IPD,48:"); int acksize = NTP_PACKET_SIZE + 1 + 2 + 8; // ESP8266 adds a space, a CRLF and starts with "+IPD,48:" Serial.println("ESP2866 ACK : "); for (byte i = 0; i < acksize; i++) { while (Serial1.available() == 0) // you may have to wait for some bytes { counta += 1; Serial.print("."); delay(100); if (counta == 15){ return 0; } } byte ch = Serial1.read(); if (ch < 0x10) Serial.print('0'); Serial.print(ch,HEX); Serial.print(' '); if ( (((i+1) % 15) == 0) ) { Serial.println(); } } Serial.println(); Serial.println(); memset(packetBuffer, 0, NTP_PACKET_SIZE); Serial.println("Server answer : "); int i = 0; while (Serial1.available() > 0) { byte ch = Serial1.read(); if (i <= NTP_PACKET_SIZE) { packetBuffer[i] = ch; } if (ch < 0x10) Serial.print('0'); Serial.print(ch,HEX); Serial.print(' '); if ( (((i+1) % 15) == 0) ) { Serial.println(); } delay(5); i++; if ( ( i < NTP_PACKET_SIZE ) && ( Serial1.available() == 0 ) ) { while (Serial1.available() == 0) // you may have to wait for some bytes { counta += 1; Serial.print("!"); delay(100); if (counta == 15){ return 0; } } } } Serial.println(); Serial.println(); Serial.print(i+1); Serial.println(" bytes received"); // will be more than 48 Serial.print(packetBuffer[40],HEX); Serial.print(" "); Serial.print(packetBuffer[41],HEX); Serial.print(" "); Serial.print(packetBuffer[42],HEX); Serial.print(" "); Serial.print(packetBuffer[43],HEX); Serial.print(" = "); unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): unsigned long secsSince1900 = highWord << 16 | lowWord; Serial.print(secsSince1900,DEC); // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: const unsigned long seventyYears = 2208988800UL; // subtract seventy years: unsigned long epoch = secsSince1900 - seventyYears; unsigned long DST = 60*60*2; // adjust to your GMT+DST unsigned long timestamp = epoch + DST; Serial.println(); Serial.print("Epoch : "); Serial.println(epoch,DEC); return epoch; }
  2. I've been trying to get this library to work with my Stellaris, which has proved a bit of a challenge for a beginner like myself.. I edited Mfrc522.cpp where I changed Mfrc522::Mfrc522(int chipSelectPin, int NRSTPD) { pinMode(chipSelectPin, OUTPUT); _chipSelectPin = chipSelectPin; pinMode(NRSTPD, OUTPUT); digitalWrite(NRSTPD, HIGH); _NRSTPD = NRSTPD; } to Mfrc522::Mfrc522(int chipSelectPin, int NRSTPD) { _chipSelectPin = chipSelectPin; _NRSTPD = NRSTPD; } and moved pinMode(chipSelectPin, OUTPUT); pinMode(NRSTPD, OUTPUT); digitalWrite(NRSTPD, HIGH); to setup (void) of the sketch. NERDGASM! only took about 10 hrs, but I have a card read! fk yeah! For my setup I've set int chipSelectPin = 2; //SDA on reader - connected to pin2 aka CS(2) int NRSTPD = 17; // aka PF_0 I've found out that Mfrc522 Mfrc522(chipSelectPin,NRSTDP); doesnt match Mfrc522.cpp, where the variable NRSTPD is used, so I changed NRSTDP to NRSTPD in the sketch. here is my working code: /* Example file for communicating with the NFRC522. The program prints the card data. Created by Eelco Rouw - Originally adapted by Grant Gibson. Modified by phaseform for use with the Stellaris */ // pin mapping for SPI(2) on the Stellaris (also tiva??) using Rei Vilo's pinmap // SDA - CS(2) -> PB_5 = pin 2 as an integer // SCK - SCK(2) -> PB_4 // Mosi - MOSI(2) -> PB_7 // Miso - MISO(2) -> PB_6 // IRQ - Not connected // GND - GND // RST - reset -> PF_0 // VCC - +3.3V = pin 1 #include <Mfrc522.h> #include <SPI.h> int chipSelectPin = 2; //SDA on reader - connected to pin2 aka CS(2) int NRSTPD = 17; //aka PF_0 Mfrc522 Mfrc522(chipSelectPin, NRSTPD); //changed NRSTDP to NRSTPD unsigned char serNum[5]; void setup() { Serial.begin(9600); // using serial port 1 (USB) SPI.setModule(2); // using SPI module 2... pinMode(chipSelectPin, OUTPUT); //moved this here from Mfrc522.cpp digitalWrite(chipSelectPin, LOW); pinMode(NRSTPD, OUTPUT); //moved this here from Mfrc522.cpp digitalWrite(NRSTPD, HIGH); //moved this here from Mfrc522.cpp pinMode(BLUE_LED, OUTPUT); pinMode(RED_LED, OUTPUT); Mfrc522.Init(); } void loop() { unsigned char i,tmp; unsigned char status; unsigned char str[MAX_LEN]; unsigned char RC_size; unsigned char blockAddr; String mynum = ""; status = Mfrc522.Request(PICC_REQIDL, str); if (status == MI_OK) { Serial.println("Card detected"); Serial.print(str[0],BIN); Serial.print(" , "); Serial.print(str[1],BIN); Serial.println(" "); digitalWrite(BLUE_LED, HIGH); delay(1000); digitalWrite(BLUE_LED, LOW); } else{ digitalWrite(RED_LED, HIGH); Serial.println("no dice here"); delay(1000); digitalWrite(RED_LED, LOW); } status = Mfrc522.Anticoll(str); memcpy(serNum, str, 5); if (status == MI_OK) { digitalWrite(BLUE_LED, HIGH); delay(1000); digitalWrite(BLUE_LED, LOW); Serial.println("The card's number is : "); Serial.print(serNum[0]); Serial.print(" , "); Serial.print(serNum[1],BIN); Serial.print(" , "); Serial.print(serNum[2],BIN); Serial.print(" , "); Serial.print(serNum[3],BIN); Serial.print(" , "); Serial.print(serNum[4],BIN); Serial.println(" "); // Should really check all pairs, but for now we'll just use the first if(serNum[0] == 29) { Serial.println("Hello Eelco"); digitalWrite(BLUE_LED, HIGH); delay(1000); digitalWrite(BLUE_LED, LOW); } delay(1000); } else{ digitalWrite(RED_LED, HIGH); Serial.println("no dice"); delay(1000); digitalWrite(RED_LED, LOW); } Mfrc522.Halt(); }
  3. Trying to get the hibernate library to work as in the pastebin example for the tm4c123 here. I've modified it with the request at the end. //#include <DateTimeLibrary.h> #include "driverlib/hibernate.c" boolean redstate = false; boolean bluestate = false; int green = 0; void setup() { uint32_t hibact = HibernateIsActive(); // put your setup code here, to run once: pinMode(GREEN_LED, OUTPUT); pinMode(BLUE_LED, OUTPUT); HibernateEnableExpClk(F_CPU); HibernateRTCEnable(); HibernateRTCMatchSet(0,HibernateRTCGet()+5); HibernateIntRegister(HibernateHandler); HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0); HibernateRTCTrimSet(0x7FFF); } void HibernateHandler(void) { //Use this to reset interrupt flag uint32_t ui32Status = HibernateIntStatus(1); HibernateIntClear(ui32Status); //Place here code to execute every second, ex: LCD or 7 segment display //Altough it should be as fastest as possible redstate = !redstate; //To keep the interrupt hapening every second you need this HibernateRTCMatchSet(0,HibernateRTCGet()+5); } void loop() { // put your main code here, to run repeatedly: bluestate = !bluestate; if(redstate ==0){ green = 0; } else green = 64; analogWrite(GREEN_LED, green); if (bluestate) { analogWrite(BLUE_LED, 64); } else { analogWrite(BLUE_LED, 0); } delay(750); HibernateRequest(); } Been reading through 16.2 API Functions for the hibernate module here and can figure out whats going on. I just want the hibernate module to be requested once main has run, this doesn't seem to happen and the hibernate interrupt just seems to function as a timer running alongside the main function...??? Tried adding HibernateWakeSet(HIBERNATE_WAKE_RTC); to the setup
  4. phaseform

    getting the hibernate library to play nice

    Thanks Fmilburn, the example you linked looks like it will be fine
  5. phaseform

    getting the hibernate library to play nice

    I don't understand how TI brought this out to go against Arduino when example codes for the hardware are so scarce, clearly they don't focus on the hobbyist market, or at least they really suck at doing it. Energia is linked on the launchpad website.. should it be confusing something as simple as power management would appear so tricky. I guess I'm just going to keep poking it with a stick until it works?
  6. phaseform

    getting the hibernate library to play nice

    Ok so I want to save battery life, I thought I could get the chip to power down when hibernating (which I assumed meant main would not run?). I also thought not as relevantly I could save power by powering via vbus and removing the jumper pin to (I hoped) disconnect the debug chip... I dont need calendar mode since I'm using a timedate library. Am I totally misunderstanding the hibernate module??!
  7. phaseform

    TM4C129 Hibernation RTC and Calendar Mode

    is something required in main to go to sleep, HibernateRequest(void)?
  8. Just been able to get an RTC output on an I2C LCD working on a TM4C123. Using this RTC Library which I understand uses the chips built in RTC/hibernate function and this I2C LCD Library, which seems to only like I2C(3) // Core library for code-sense - IDE-based #if defined(WIRING) // Wiring specific # include "Wiring.h" #elif defined(ENERGIA) // LaunchPad specific # include "Energia.h" #else // error # error Platform not defined #endif // end IDE // Include application, user and local libraries // The time library provides all the tools. // No need for reinventing them! #include "time.h" #define CEST 2*60*60 #include "DateTimeLibrary.h" const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets //LCD #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 character, 2 line display // Prototypes char * datestamp = __DATE__; char * timestamp = __TIME__; // Define variables and constants time_t myEpochRTC; tm myTimeRTC; DateTime myRTC; // Add setup code void setup() { Wire.begin(3); Wire.setModule(3); lcd.init(); // initialize the lcd Serial.begin(9600); delay(300); myRTC.begin(); myRTC.setTimeZone(tz_GMT); Serial.print("*** datestamp = "); Serial.println(datestamp); Serial.print("*** timestamp = "); Serial.println(timestamp); // Fri, 31 Jul 2015 20:41:48 GMT myEpochRTC = 946743570; // Set time to RTC, only once myRTC.setTime(myEpochRTC); Serial.print("Set RTC = "); Serial.println(myEpochRTC, DEC); myEpochRTC = 0; } // Add loop code void loop() { lcd.backlight(); lcd.setCursor(0,0); lcd.print("Session time:"); // Local time zone myEpochRTC = myRTC.getLocalTime(); lcd.setCursor(0,1); //lcd.print(stringDateTime(myEpochRTC)); // Even more flexible output! // see http://www.cplusplus.com/reference/ctime/strftime/ convertEpoch2Structure(myEpochRTC, myTimeRTC); lcd.print(stringFormatDateTime("%I:%M:%S %p.", myTimeRTC)); delay(100); }
  9. In the sketchbook location (under file > preferences) is a libraries folder, extract your library there
  10. phaseform

    TM4C129 Hibernation RTC and Calendar Mode

    would someone be able to explain the function of hibernate, in post #21 I don't understand why main is running concurrently to the hibernate timer?
  11. phaseform

    Building low power into Energia

    I'm just thinking in as far as using the launchpad for a project, unless I'm understanding the process wrong, the debugging chip is only used as usb serial and debugging? Yer thats what I thought, if I remove the jumper possibly I could remove the ICDI from VBUS? then I'd just have to use an external 5v other than USB..?
  12. phaseform

    Building low power into Energia

    How can I remove power from the ICDI on a Launchpad board? It seems my lm4f120 will use 40mA through my usb power meter when in sleep, and 70mA when not in sleep.. (sleepSeconds) I've been looking through the users manual on the product page and can't find anything useful in the scematic or the hibernate section.
  13. On the stellaris, is it possible to power from VBUS while using debug usb? I was intending to use the debug serial sometimes to connect to the board, but I want it to run all the time, even when not connected to the debug USB. Is this possible?! I was going to source a 5v power supply to run the VBUS. thanks!
  14. phaseform

    RC522 Library on Stellaris

    Heres the Library I modified to work with the Stellaris, not sure how that affects the MSP430 Mfrc522_Stellaris.zip
  15. I have a whole bunch of problems getting my Stellaris to play nice with my ebay 522 reader... EDIT: got it here So far I cant get the serial monitor to send anything back to the computer. I've tried changing the baud rate - 9600 and 2400. also, I'm confused at to the pin connection, I've tried: // SDA on Stellaris pinmap SDA(0) is PB_3 // SCK on Stellaris pinmap SCK(0) is PA_2 // Mosi on Stellaris pinmap MOSI(0) is PA_5 // Miso on Stellaris pinmap MISO(0) is PA_4 // IRQ - not connected // GND - GND // RST - 1.3 on 430 refers to PUSH2; on Stellaris = PF_0... not sure bout this // VCC - 3.3v I tried: SPI.setModule(0); in the setup and this returned nothing in the serial monitor.. from here I modified the code to send *something* back to the computer over serial.. status = Mfrc522.Request(PICC_REQIDL, str); if (status == MI_OK) { Serial.println("Card detected"); Serial.print(str[0],BIN); Serial.print(" , "); Serial.print(str[1],BIN); Serial.println(" "); } else{ //added this Serial.println("nope"); } and still I'm getting NOTHING back over serial. which confuses me, I thought Id be getting 'nope' on a new line constantly *confused* in the 'working' code, I'm not rly sure what the line int NRSTDP = 5; refers to, seemingly PUSH2, so I tried changing that to 17 to correspond with the stellaris, not sure if this makes any difference. After this I tried changing the pin wiring around to suit the "default" for SPI http://forum.43oh.com/topic/3387-spi-pin-map-for-stellaris-launchpad-lm4f120/ // Pinout // SDA - 2.2 (430 launchpad) -> 10 (stellaris launchpad) // SCK - 1.5 (430) -> PB_4 (stellaris) // Mosi - 1.7 (430) -> PB_7 (stellaris) // Miso - 1.6 (430) -> PB_6 (stellaris) // IRQ - Not connected // GND - GND // RST - 1.3 (430) -> 1.3 refers to PUSH2; PF_0... not sure bout this // VCC - VCC and leaving SPI.setModule(0); out of the code... nothing. I tried putting SPI.setModule(2); in the code..nothing. this is the most recent code, which is basically an amalgamation of the above problems /* Example file for communicating with the NFRC522. The program prints the card data. Created by Eelco Rouw - Originally adapted by Grant Gibson. */ // Pinout // SDA - 2.2 on pinmap SDA(0) is PB_3.. default - PA_7 or maybe 10 // SCK - 1.5 on pinmap SCK(0) is PA_2.. default - PB_4 // Mosi - 1.7 on pinmap MOSI(0) is PA_5.. default (no SPI.setModule) - PB_7 // Miso - 1.6 on pinmap MISO(0) is PA_4.. default - PB_6 // IRQ - NC // GND - GND // RST - 1.3 on pinmap... 1.3 refers to PUSH2; PF_0... not sure bout this // VCC - VCC #include <Mfrc522.h> // the sensor communicates using SPI, so include the library: #include <SPI.h> int chipSelectPin = 10; //SDA on reader (pin 10 is PA_7 on stellaris) although try PB_3 as above instead of 10 int NRSTDP = 17; Mfrc522 Mfrc522(chipSelectPin,NRSTDP); unsigned char serNum[5]; void setup() { Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 2400bps // Start the SPI library: SPI.setModule(2); // taken from http://forum.43oh.com/topic/3387-spi-pin-map-for-stellaris-launchpad-lm4f120/ SPI.begin(); // Initialize the Card Reader digitalWrite(chipSelectPin, LOW); pinMode(RED_LED, OUTPUT); Mfrc522.Init(); } void loop() { unsigned char i,tmp; unsigned char status; unsigned char str[MAX_LEN]; unsigned char RC_size; unsigned char blockAddr; String mynum = ""; status = Mfrc522.Request(PICC_REQIDL, str); if (status == MI_OK) { Serial.println("Card detected"); Serial.print(str[0],BIN); Serial.print(" , "); Serial.print(str[1],BIN); Serial.println(" "); } else{ Serial.println("Card detected"); } status = Mfrc522.Anticoll(str); memcpy(serNum, str, 5); if (status == MI_OK) { Serial.println("The card's number is : "); Serial.print(serNum[0]); Serial.print(" , "); Serial.print(serNum[1],BIN); Serial.print(" , "); Serial.print(serNum[2],BIN); Serial.print(" , "); Serial.print(serNum[3],BIN); Serial.print(" , "); Serial.print(serNum[4],BIN); Serial.println(" "); // Should really check all pairs, but for now we'll just use the first if(serNum[0] == 29) { Serial.println("Hello Eelco"); digitalWrite(RED_LED, HIGH); delay(1000); digitalWrite(RED_LED, LOW); } delay(1000); } //Serial.println(" "); Mfrc522.Halt(); } So far, no dice. Any help with this would be appreciated! thanks!
  16. phaseform

    Reading LM4F120 internal temp sensor

    I'm not having any luck getting this to compile for my lm4f120. Are there libraries that need to be added, if so where can I find them?! "Energia.h" was used as an example library?! thanks!
×