Jump to content
43oh

phaseform

Members
  • Content Count

    17
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    phaseform reacted to L.R.A in getting the hibernate library to play nice   
    This type of code as nothing to do with Energia/Arduino!
    This is low level coding with low level libraries (just above register programming)! Like in arduino you can use register programming, or if using a Arduino Due, use low level libraries too, to have full access to your hardware. Of course with time there's high level libraries that appear but this type of feature is MCU specific = less likely for a library to appear.

    Power management = simple? It can actually be quite complex! Which sleep mode? Which peripherals should be on? With which clock on and in which bus? What are the wake up sources? Chose the right core voltage and clock source and speed for different wake up times and consumption.
     
    Granted that there's fewer code examples for some features but don't compare the size of the community + lots of users here go to low level programming for the advantages it brings (or a mix).

    You should be able to use these for delays where the cpu sleeps:
    void sleep(uint32_t milliseconds); void sleepSeconds(uint32_t seconds);

    There's also a void suspend(void); that I think works by using a interrupt as a wake up source.

    And if you really want to go for low level programming with Tivaware libraries, there's actually plenty of examples on the package including some for the hibernate module
  2. Like
    phaseform reacted to Fmilburn in getting the hibernate library to play nice   
    What @L.R.A said, and to elaborate further...
     
    There are several places where sleep(), sleepSeconds(), suspend(), and wakeup() are discussed in 43oh forums.  Energia on the TI microcontrollers actually has fairly sophisticated energy management features.  For example, see this recent post on the 43oh blog and this simple example.  I tried the example just now on the EK-TM4C123GXL with Energia 16 on my Windows 10 machine and it works fine.
  3. Like
    phaseform reacted to OzGrant in [Energia Library] OneWire DS18B20 (430 & Stellaris)   
    Tks Pivden,
    Yes your correct, no idea how the microsec's snuck through, they seem to do that at 2AM.
    Have updated the zip file.
    Tks again
    GFDS18B20V2.zip
  4. Like
    phaseform reacted to Marvi in Trouble with BH1750 (Tiva C-Lm4f123gxl)   
    I tested BH1750FVI board for arduino and it works. But there is few things I have to do before It worked. On the board is 3.3V voltage stabilizer, so you must remove it or use 5V from USB and common ground with microprocessor!  I make few changes in code. Energia 0014 and Launchpad 1.4 (cross RX TX) with MSP430G2553. Here is my working code:
    // SDA to PIN 1.7 //SCL to PIN 1.6 //The iic address = 0x23 when ADDR = LOW; address = 0x3C when ADDR = HIGH #include <Wire.h> //BH1750 I2C Mode slave uint16_t Lux=0; void setup() { Wire.begin(); Serial.begin(9600); } void loop() { Lux=0; Read_BH1750(); Serial.print(Lux,DEC); Serial.println(" LUX"); delay(400); } void Read_BH1750() { byte buff[2]; int i=0; Wire.beginTransmission(0x23); Wire.write(0x10);//1 Lux resolution time 120ms Wire.requestFrom(0x23, 2 ); while(Wire.available()){buff[i] = Wire.read(); i++;} // receive one byte Wire.endTransmission(); if(i==2){Lux=((buff[0]<<8)|buff[1])/(12/10);} }
  5. Like
    phaseform got a reaction from spirilis in NTP from ESP8266 via AT commands   
    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; }
  6. Like
    phaseform got a reaction from bluehash in NTP from ESP8266 via AT commands   
    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; }
  7. Like
    phaseform got a reaction from spirilis in RTC to I2C LCD Working on TM4C123 / LM4F120   
    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); }
     
  8. Like
    phaseform got a reaction from bluehash in RC522 Library on Stellaris   
    Heres the Library I modified to work with the Stellaris, not sure how that affects the MSP430
     
    Mfrc522_Stellaris.zip
  9. Like
    phaseform reacted to eelcor in [Energia Library] NFC card reading with Energia - MF RC 522   
    Hi everybody,
     
    >>> UPDATE - Made "proper" Energia Library out of it. Now with proper named methods/class members<<<
     
    >>> UPDATE 2 - Added "keywords.txt" file for syntax highlighting, added comments to "Mfrc522.cpp" file explaining methods (thanks to Grant) - Added example to read cards contents of block 1 <<<
     
    >>> UPDATE 3 - You need to apply the USCI SPI fix proposed by Spirilis (post #22) in the following thread: http://forum.43oh.com/topic/3237-energia-library-nordic-nrf24l01-library/page-2 , otherwise the card reader won't work! <<<<
     
    I wanted to share my results with the MF RC522 RFID reader. I found an article from Grant Gibson (http://www.grantgibson.co.uk/blog/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/#comments) where he used a cheap reader from eBay to read Mifare cards.  (http://www.ebay.com/itm/Mifare-RC522-RFID-13-56Mhz-Module-SPI-Interface-with-a-IC-Card-/370690680474?pt=LH_DefaultDomain_0&hash=item564ee2e69a)
     
    The command set and technical aspects of the MFRC522 chip can be found in the datasheet: http://www.nxp.com/documents/data_sheet/MFRC522.pdf
     
    I have ported the example to Energia. Very simple by removing all Chinese comments and replacing uchar with unsigned chars. 
     
    After these changes it works like a charm. 
     
    Just connect the following lines:
    MOSI LP -> Pin 3 of the module
    MISO LP -> Pin 4 of the module
    PIn 1.3 LP -> Pin 1 of the module (SS)
    Pin 2.2 LP -> Pin 7 of the module (RST)
    Pin 1.5 LP -> Pin 2 of the module (SCK)
    GND LP -> Pin 6 of the module
    VCC LP -> Pin 8 of the module
    Pin 5 is not connected.
     
    Included is the sketch (Mfrc522.zip) I used. Now onto opening doors and paying electronically!
     
    Kind regards, 
     
    Eelco


×
×
  • Create New...