Jump to content
43oh

Bernard

Members
  • Content Count

    68
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Bernard reacted to Rickta59 in Energia bug in Blink without delay tutorial   
    You don't have to worry about this. The unsigned 32 bit wraps around and the math works properly. Take a look at the code below followed by the results. This is just some straight c code you can compile on your desktop pc and run.
     
    #include <stdio.h> #include <stdint.h> const uint32_t intervalMs = 10000; uint32_t currMs = 0; uint32_t prevMs = 0; void check(check) { uint32_t diff = currMs-prevMs; if ( diff > intervalMs ) { printf("currMs=%u-prevMs=%u diff(%u) > interval=(%u) == %s\n", currMs, prevMs, diff, intervalMs, ((diff) > intervalMs ? "T":"F") ); prevMs += intervalMs; } } void main() { do { check(); currMs++; } while(1); } currMs=10001-prevMs=0 diff(10001) > interval=(10000) == T currMs=20001-prevMs=10000 diff(10001) > interval=(10000) == T ... many lines later near the wrap ... currMs=4294960001-prevMs=4294950000 diff(10001) > interval=(10000) == T ... and the first value after currMs wraps around .. currMs=2705-prevMs=4294960000 diff(10001) > interval=(10000) == T currMs=12705-prevMs=2704 diff(10001) > interval=(10000) == T ... and on it goes .. 2705-4294960000=10001 when they are both unsigned 32 bit integers.

    The real bug is using a long instead of an unsigned long for the value previousMillis and interval.

    [edit]
    I just checked over at the arduino github and it looks like someone fixed it here:

    https://github.com/arduino/Arduino/commit/83ef1814cfda808f94cd80a70d7cee8725e24a13

    [/edit]

    -rick
  2. Like
    Bernard got a reaction from spirilis in Energia bug in Blink without delay tutorial   
    Hi,
     
    May be this help : http://playground.arduino.cc/Code/TimingRollover
     
    Salutations
  3. Like
    Bernard reacted to reaper7 in Energia-013 ethernet example doesn't compile   
    look at this:
    https://github.com/energia/Energia/commit/aa5509e8ab146d715e3b0369c755b1a2ef0dcc14
    https://github.com/energia/Energia/issues/464
     
    simply remove
    const IPAddress INADDR_NONE(0,0,0,0); from hardware/lm4f/libraries/Ethernet/Ethernet.h
  4. Like
    Bernard got a reaction from Smakkemeken in Say Hi for a Giveaway entry.   
    Hi
  5. Like
    Bernard reacted to spirilis in TM4C129 +nRF24l01 web server problem   
    LOL oh my! Weird, is the TM4C129 bpak headers just not supplying enough?
  6. Like
    Bernard got a reaction from Rickta59 in TM4C129 nRF24L01 RX working example   
    Hi,
     
    Here is a working example TM4C129 using Enrf24 library
    /* Tiva launchpad connected TM4C129 nRF24L01 RX SPI module 2 25/06/2014 */ #include <Enrf24.h> #include <nRF24L01.h> #include <string.h> #include <SPI.h> Enrf24 radio(PE_0,PE_2,PE_1); // CE, CSN, IRQ + SCK/MOSI/MISO ==> PD_3/PD_0/PD_1 const uint8_t rxaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 }; unsigned long prev_time; void setup() { Serial.begin(9600); Serial.flush(); SPI.setModule(2); SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(1); radio.begin(); // Defaults 1Mbps, channel 0, max TX power dump_radio_status_to_serialport(radio.radioState()); radio.setRXaddress((void*)rxaddr); radio.enableRX(); // Start listening delay(100); } void loop() { char inbuf[33]; delta_set(); while (!radio.available(true)&& delta_get()<1000); if (radio.read(inbuf)) { Serial.println(inbuf); } } void delta_set() { prev_time = millis(); } // TimeOut unsigned long delta_get() { unsigned long time; unsigned long delta; time = millis(); if (time < prev_time) { // TimeOut delta = 0xffffffff - prev_time + time + 1; } else { delta = time - prev_time; } return delta; } void dump_radio_status_to_serialport(uint8_t status) { Serial.print("Enrf24 radio transceiver status: "); switch (status) { case ENRF24_STATE_NOTPRESENT: Serial.println("NO TRANSCEIVER PRESENT"); break; case ENRF24_STATE_DEEPSLEEP: Serial.println("DEEP SLEEP <1uA power consumption"); break; case ENRF24_STATE_IDLE: Serial.println("IDLE module powered up w/ oscillators running"); break; case ENRF24_STATE_PTX: Serial.println("Actively Transmitting"); break; case ENRF24_STATE_PRX: Serial.println("Receive Mode"); break; default: Serial.println("UNKNOWN STATUS CODE"); } } TX is MSP430 + DHT22 sending humidity and temperature
     
    Salutations
     
    Bernard
  7. Like
    Bernard got a reaction from Rickta59 in TM4C129 nRF24L01 RX working example   
    Hi again,
     
    I forgot to post the TX side :
    /* MSP 430g2553 TX DHT22 25/06/2014 */ #include <Enrf24.h> #include <nRF24L01.h> #include <string.h> #include <SPI.h> #include <DHT22_430.h> #define DHTPIN P1_4 DHT22 mySensor(DHTPIN); Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ const uint8_t txaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 }; boolean flag = 0; void dump_radio_status_to_serialport(uint8_t); void setup() { Serial.begin(9600); SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(1); // MSB-first mySensor.begin(); radio.begin(); // Defaults 1Mbps, channel 0, max TX power //radio.setCRC(1,1); radio.setTXaddress((void*)txaddr); } void loop() { char str[16]; long h = mySensor.humidityX10(); long t = mySensor.temperatureX10(); flag = mySensor.get(); if (!flag) { radio.print("DHT error"); } else{ sprintf(str, "%ld",h/10); radio.print(str); radio.print("."); sprintf(str, "%ld",h%10); radio.print(str); radio.print("---"); sprintf(str, "%ld",t/10); radio.print(str); radio.print("."); sprintf(str, "%ld",t%10); radio.print(str); radio.flush(); // Force transmit (don't wait for any more data) } delay(1000); } My project is to centrally manage several rf sensors on Tiva connected board and make a  web server.
    I have spent many time to add  the Ethernet part in the loop and so far no success ... any help would be appreciate
    Salutations
    Bernard
  8. Like
    Bernard got a reaction from energia in TM4C129 nRF24L01 RX working example   
    Hi,
     
    Here is a working example TM4C129 using Enrf24 library
    /* Tiva launchpad connected TM4C129 nRF24L01 RX SPI module 2 25/06/2014 */ #include <Enrf24.h> #include <nRF24L01.h> #include <string.h> #include <SPI.h> Enrf24 radio(PE_0,PE_2,PE_1); // CE, CSN, IRQ + SCK/MOSI/MISO ==> PD_3/PD_0/PD_1 const uint8_t rxaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 }; unsigned long prev_time; void setup() { Serial.begin(9600); Serial.flush(); SPI.setModule(2); SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(1); radio.begin(); // Defaults 1Mbps, channel 0, max TX power dump_radio_status_to_serialport(radio.radioState()); radio.setRXaddress((void*)rxaddr); radio.enableRX(); // Start listening delay(100); } void loop() { char inbuf[33]; delta_set(); while (!radio.available(true)&& delta_get()<1000); if (radio.read(inbuf)) { Serial.println(inbuf); } } void delta_set() { prev_time = millis(); } // TimeOut unsigned long delta_get() { unsigned long time; unsigned long delta; time = millis(); if (time < prev_time) { // TimeOut delta = 0xffffffff - prev_time + time + 1; } else { delta = time - prev_time; } return delta; } void dump_radio_status_to_serialport(uint8_t status) { Serial.print("Enrf24 radio transceiver status: "); switch (status) { case ENRF24_STATE_NOTPRESENT: Serial.println("NO TRANSCEIVER PRESENT"); break; case ENRF24_STATE_DEEPSLEEP: Serial.println("DEEP SLEEP <1uA power consumption"); break; case ENRF24_STATE_IDLE: Serial.println("IDLE module powered up w/ oscillators running"); break; case ENRF24_STATE_PTX: Serial.println("Actively Transmitting"); break; case ENRF24_STATE_PRX: Serial.println("Receive Mode"); break; default: Serial.println("UNKNOWN STATUS CODE"); } } TX is MSP430 + DHT22 sending humidity and temperature
     
    Salutations
     
    Bernard
  9. Like
    Bernard got a reaction from spirilis in TM4C129 nRF24L01 RX working example   
    Hi,
     
    Here is a working example TM4C129 using Enrf24 library
    /* Tiva launchpad connected TM4C129 nRF24L01 RX SPI module 2 25/06/2014 */ #include <Enrf24.h> #include <nRF24L01.h> #include <string.h> #include <SPI.h> Enrf24 radio(PE_0,PE_2,PE_1); // CE, CSN, IRQ + SCK/MOSI/MISO ==> PD_3/PD_0/PD_1 const uint8_t rxaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 }; unsigned long prev_time; void setup() { Serial.begin(9600); Serial.flush(); SPI.setModule(2); SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(1); radio.begin(); // Defaults 1Mbps, channel 0, max TX power dump_radio_status_to_serialport(radio.radioState()); radio.setRXaddress((void*)rxaddr); radio.enableRX(); // Start listening delay(100); } void loop() { char inbuf[33]; delta_set(); while (!radio.available(true)&& delta_get()<1000); if (radio.read(inbuf)) { Serial.println(inbuf); } } void delta_set() { prev_time = millis(); } // TimeOut unsigned long delta_get() { unsigned long time; unsigned long delta; time = millis(); if (time < prev_time) { // TimeOut delta = 0xffffffff - prev_time + time + 1; } else { delta = time - prev_time; } return delta; } void dump_radio_status_to_serialport(uint8_t status) { Serial.print("Enrf24 radio transceiver status: "); switch (status) { case ENRF24_STATE_NOTPRESENT: Serial.println("NO TRANSCEIVER PRESENT"); break; case ENRF24_STATE_DEEPSLEEP: Serial.println("DEEP SLEEP <1uA power consumption"); break; case ENRF24_STATE_IDLE: Serial.println("IDLE module powered up w/ oscillators running"); break; case ENRF24_STATE_PTX: Serial.println("Actively Transmitting"); break; case ENRF24_STATE_PRX: Serial.println("Receive Mode"); break; default: Serial.println("UNKNOWN STATUS CODE"); } } TX is MSP430 + DHT22 sending humidity and temperature
     
    Salutations
     
    Bernard
  10. Like
    Bernard got a reaction from Duloxetinepka in Say Hi for a Giveaway entry.   
    Hi
  11. Like
    Bernard reacted to energia in My first attempt TM4C129   
    The Sketch below (Example->Ethernet->EthernetWebserver) should work as expected. The only difference that I see is that "EthernetClient client;" is outside of loop ()rather than inside loop(). I will give you Sketch above a try later today to see if I can reproduce the issue.
    /* Web Server Created: October 16, 2013 by Robert Wessels (http://energia.nu) Derived from example Sketch by Hans Scharler (http://www.iamshadowlord.com) */ #include "Ethernet.h" // Prototypes void printConfig(); void printEthernetData(); void printIndex(); void printHelp(); EthernetServer server(80); int statusConfig = 0; void setup() { Serial.begin(115200); pinMode(D1_LED, OUTPUT); pinMode(D2_LED, OUTPUT); pinMode(PUSH1, INPUT_PULLUP); // released = HIGH, pressed = LOW pinMode(PUSH2, INPUT_PULLUP); Serial.println("Connecting to Ethernet...."); IPAddress ip = IPAddress(146,252,242,129); IPAddress dns = IPAddress(146,252,242,12); IPAddress gw = IPAddress(146,252,242,254); IPAddress mask = IPAddress(255,255,255,0); Ethernet.begin(0); // Ethernet.begin(0, ip, dns, gw); server.begin(); printEthernetData(); } EthernetClient client; void loop() { client = server.available(); if (client) { // if you get a client, Serial.print("new client on port "); // print a message out the serial port Serial.println(client.port()); String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then // This lockup is because the recv function is blocking. Serial.print(c); if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { break; } else { // if you got a newline, then clear currentLine: currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } if (currentLine.endsWith("GET / ")) { statusConfig = 0; printIndex(); } if (currentLine.endsWith("GET /config.html ")) { statusConfig = 1; printConfig(); } if (currentLine.endsWith("GET /index.html ")) { statusConfig = 0; printIndex(); } // Check to see if the client request was "GET /H" or "GET /L": if (currentLine.endsWith("GET /RED_LED_H")) {digitalWrite(D1_LED, HIGH);printConfig();} if (currentLine.endsWith("GET /RED_LED_L")) {digitalWrite(D1_LED, LOW);printConfig();} if (currentLine.endsWith("GET /GREEN_LED_H")) {digitalWrite(D2_LED, HIGH);printConfig();} if (currentLine.endsWith("GET /GREEN_LED_L")) {digitalWrite(D2_LED, LOW);printConfig();} } } // close the connection: client.stop(); //Serial.println("client disonnected"); } } void printIndex() { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: // Serial.println("Index"); client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); client.println("<html><head><title>CC3000 Energia Webpage</title></head><body align=center>"); client.println("<h1 align=center><font color=\"red\">Welcome To CC3000 Web Server</font></h1>"); client.println("</br><font size=\"4px\"><table border=\"0\" align=center width=1200px height=590px>"); client.println("<tr><td align=center width=375></td><td width=450px align=left valign=\"top\">"); client.println("<p>Using CC3000 WLAN connectivity, Web Server provides "); client.println("capability to remotely read and write GPIOs "); client.println("on/off.</p></br></br>"); client.println("<p><a href=\"/config.html\">Click here</a> "); client.println("to check status and configure the board</p>"); client.println("<td align=cneter width=375></td></tr></table></font></body></html>"); client.println(); } void printConfig() { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); client.println("<html><head><title>CC3000 Energia Webpage</title></head><body align=center>"); client.println("<h1 align=center><font color=\"red\">Welcome To CC3000 Web Server</font></h1>"); // the content of the HTTP response follows the header: // Added: nicer buttons client.print("<font color='green'>GREEN_LED</font> <button onclick=\"location.href='/GREEN_LED_H'\">HIGH</button>"); client.println(" <button onclick=\"location.href='/GREEN_LED_L'\">LOW</button><br>"); client.print("<font color='red'>RED_LED</font> <button onclick=\"location.href='/RED_LED_H'\">HIGH</button>"); client.println(" <button onclick=\"location.href='/RED_LED_L'\">LOW</button><br><br>"); client.println("PUSH1 "); if(digitalRead(PUSH1))client.print("is HIGH<br>"); else client.print("is LOW<br>"); client.println("PUSH2 "); if(digitalRead(PUSH2))client.print("is HIGH<br>"); else client.print("is LOW<br>"); client.println("<a href=\"/config.html\" >refresh</a> <br>"); client.println("<a href=\"/index.html\" >home</a> <br>"); client.println("</body></html>"); // The HTTP response ends with another blank line: client.println(); // break out of the while loop: } void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); switch(inChar) { case 'h': printHelp(); break; case 'i': printEthernetData(); break; default: Serial.println(); Serial.println("Invalid menu option"); } } } void printHelp() { Serial.println(); Serial.println("+++++++++++++++++++++++++++++++++++++"); Serial.println("Help menu:"); Serial.println("\th: This help menu"); Serial.println("\ti: IP address information"); Serial.println("+++++++++++++++++++++++++++++++++++++"); } void printHex(int num, int precision) { char tmp[16]; char format[128]; sprintf(format, "%%.%dX", precision); sprintf(tmp, format, num); Serial.print(tmp); } void printEthernetData() { // print your IP address: Serial.println(); Serial.println("IP Address Information:"); IPAddress ip = Ethernet.localIP(); Serial.print("IP Address:\t"); Serial.println(ip); // print your MAC address: IPAddress subnet = Ethernet.subnetMask(); Serial.print("NetMask:\t"); Serial.println(subnet); // print your gateway address: IPAddress gateway = Ethernet.gatewayIP(); Serial.print("Gateway:\t"); Serial.println(gateway); // print your gateway address: IPAddress dns = Ethernet.dnsServerIP(); Serial.print("DNS:\t\t"); Serial.println(dns); }
  12. Like
    Bernard reacted to spirilis in Simple IRC example   
    Ok this is just silly, but I had to do it.
     
    Simple IRC client that pops into #energia, says hi and runs.
    /* IRC Example * Simple IRC client which connects gracefully, joins #energia and says a simple Hello before quitting and indefinitely sleeping. */ #include <Ethernet.h> #include <IPAddress.h> #include <string.h> byte ourMac[] = { 0x52, 0x54, 0xFF, 0xFF, 0xFF, 0x01 }; EthernetClient client; const char *ircserver_name = "chat.freenode.net"; //#define IRC_USE_IP_NOT_DNS //IPAddress ircserver(62,231,75,133); // ^ Required for connecting through an SSH tunnel for getting around a firewall // Comment out #define IRC_USE_IP_NOT_DNS to use the ircserver_name DNS to connect. #define IRCSERVER_PORT 6667 const char *irc_nick = "SpirTivaLP"; const char *irc_user = "tm4c129"; const char *irc_user_description = "Energia Warrior"; const char *irc_channel = "#energia"; void dispatch_composite_message(uint8_t, int); void process_inbound_message(uint8_t, int); void setup() { IPAddress ip; Serial.setBufferSize(2048, 64); Serial.begin(115200); // Wait for USR_SW1 to be pressed before continuing (10ms resolution polling the button)... // This just gives me time to open the Serial Monitor before proceeding. pinMode(USR_SW1, INPUT_PULLUP); uint32_t lastmillis = millis(); while (digitalRead(USR_SW1)) { if ( (millis() - lastmillis) > 1000 ) { Serial.println("Waiting for USR_SW1 press to begin..."); lastmillis = millis(); } delay(10); } // Initialize network. Serial.println("\n\nDHCP IRC Client Example"); Serial.print("DHCP init: "); if (!Ethernet.begin(ourMac)) { Serial.println("Failed to configure Ethernet using DHCP. Halting."); while(1) delay(1000); } Serial.print("done; IP="); ip = Ethernet.localIP(); ip.printTo(Serial); Serial.println("\n"); } volatile boolean is_connected = false; volatile int prot_stage = 0; volatile boolean prot_stage_latched = false; /* ^ Determines if the current event stage has been carried out, in which * case we're waiting for some reply or some other event to proceed to * the next event stage. */ // IRC protocol event stages #define PROT_STAGE_WAITINIT 0 #define PROT_STAGE_NICK 1 #define PROT_STAGE_USER 2 #define PROT_STAGE_JOIN 3 #define PROT_STAGE_SAYHELLO 4 #define PROT_STAGE_QUIT 5 #define PROT_STAGE_DONE 6 void loop() { uint8_t buf[2049]; int len; // Main loop if (!is_connected || !client.connected()) { Serial.print("Connecting to: "); Serial.println(ircserver_name); #ifdef IRC_USE_IP_NOT_DNS if (client.connect(ircserver, IRCSERVER_PORT)) { #else if (client.connect(ircserver_name, IRCSERVER_PORT)) { #endif Serial.println("connected\n"); is_connected = true; prot_stage = PROT_STAGE_WAITINIT; } else { is_connected = false; Serial.println("Failed; pausing 5 seconds before retrying"); delay(5000); } } else { // Process incoming data first if (client.available()) { if ((len = client.read(buf, 2048)) > 0) { buf[len] = '\0'; Serial.print("Inbound msg: "); Serial.write(buf, len); Serial.println(); dispatch_composite_message(buf, len); // TODO: Use a ring-buffer with this code as the producer and dispatch_composite_message as the consumer. } } // Check protocol event stage and perform outbound messages switch (prot_stage) { case PROT_STAGE_NICK: if (!prot_stage_latched) { Serial.println("Registering NICK-\n"); // Compose NICK command buf[0] = 0; strcat((char *)buf, "NICK "); strcat((char *)buf, (char *)irc_nick); strcat((char *)buf, "\r\n"); client.print((char *)buf); prot_stage++; // No reply needed to advance to next step } break; case PROT_STAGE_USER: if (!prot_stage_latched) { Serial.println("Registering USER-\n"); client.print("USER "); client.print(irc_nick); client.print(" "); client.print(irc_user); client.print(" "); client.print(ircserver_name); client.print(" :"); client.print(irc_user_description); client.print("\r\n"); prot_stage_latched = true; // Must wait for RPY_ENDOFMOTD before proceeding } break; case PROT_STAGE_JOIN: if (!prot_stage_latched) { Serial.print("Joining "); Serial.print(irc_channel); Serial.println("-"); client.print("JOIN "); client.print(irc_channel); client.print("\r\n"); prot_stage_latched = true; // Must wait for RPY_TOPIC before proceeding } break; case PROT_STAGE_SAYHELLO: if (!prot_stage_latched) { Serial.print("Writing to "); Serial.print(irc_channel); Serial.println("-"); client.print("PRIVMSG "); client.print(irc_channel); client.print(" :"); client.print("Hi everyone! I am a TI TM4C129 LaunchPad connecting to IRC and sending you a brief message."); client.print(" Currently using Energia release "); client.print(12, DEC); client.println(".\r\n"); prot_stage++; // No reply needed to proceed with the next step } break; case PROT_STAGE_QUIT: if (!prot_stage_latched) { Serial.println("Issuing QUIT-\n"); client.print("QUIT :Bye for now!\r\n"); prot_stage++; } break; case PROT_STAGE_DONE: Serial.println("Done."); while (1) delay(1000); break; } /* switch(prot_stage) */ } /* if (is_connected) */ } /* loop() */ /* Process a packet into a sequence of \r\n-terminated lines; Note this should be replaced * with a ring-buffer design, as data which flows across multiple packets will not be * processed correctly; the last request will be truncated and the beginning of the next * request will be handled improperly. */ void dispatch_composite_message(uint8_t *buf, int len) { uint8_t *bufptr = buf; uint8_t *nl = (uint8_t *)strstr((char *)bufptr, "\r\n"); int sublen = 0; while (nl != NULL) { sublen = (int) (nl - bufptr); process_inbound_message(bufptr, sublen); bufptr += sublen + 2; if ( (bufptr - buf) >= len ) return; nl = (uint8_t *)strstr((char *)bufptr, "\r\n"); } } /* Process individual line. */ void process_inbound_message(uint8_t *buf, int sublen) { uint8_t *arg1, *arg2; int len; // Process inbound message buf[sublen] = '\0'; arg1 = (uint8_t *)strstr((char *)buf, " "); if (arg1 == NULL) return; *arg1 = '\0'; arg1++; int i=0; while (arg1[i] != ' ' && arg1[i] != '\0') i++; arg1[i] = '\0'; if ( (arg1 + i - buf) >= sublen ) arg2 = NULL; else arg2 = arg1 + i + 1; Serial.print("Reply ARG: "); Serial.println((char *)arg1); // WAITINIT waits for any sort of reply from the IRC server indicating it has connected if (prot_stage == PROT_STAGE_WAITINIT) { prot_stage++; prot_stage_latched = false; return; } // Perform PING reply if (!strcmp((char *)buf, "PING")) { Serial.print("Received PING "); Serial.print((char *)arg1); Serial.println("; sending PONG"); client.print("PONG "); if (arg1[0] == ':') client.print((char *)(arg1+1)); else client.print((char *)arg1); client.print("\r\n"); } // RPY_ENDOFMOTD to advance past USER if (prot_stage == PROT_STAGE_USER && !strcmp((char *)arg1, "376")) { prot_stage++; prot_stage_latched = false; } // RPY_TOPIC to advance past JOIN if (prot_stage == PROT_STAGE_JOIN && !strcmp((char *)arg1, "332")) { prot_stage++; prot_stage_latched = false; } } Probably a lot of things I can improve on, not the least of which is a proper ring-buffer for the inbound data and a better parser.  But it works:
    14:17 -!- SpirTivaLP [~SpirTivaL@<hostname_redacted>] has joined #energia 14:17 < SpirTivaLP> Hi everyone! I am a TI TM4C129 LaunchPad connecting to IRC and sending you a brief message. Currently using Energia release 12. 14:17 -!- SpirTivaLP [~SpirTivaL@<hostname_redacted>] has quit [Client Quit] We'll call it the beginnings of a Tiva-C IRC bot...
  13. Like
    Bernard reacted to chicken in MSP430G2553 and Rotary encoder   
    Serial print can be very slow and should be avoided inside an interrupt routine.
     
    Better to write the state/result into a global variable (declared with the "volatile" prefix) and process it in the main loop. You might need to add some additional logic to detect whether the encoder is still moving, e.g. by setting a flag in interrupt routine and resetting it in the main loop.
  14. Like
    Bernard got a reaction from aduckysoods in How to come back to IP.Board   
    Hello,
     
    days ago I switched to IP.Board mobile ( just curious) and I cannot come back to Ip.Board. I haven't found how to do that. some help needed.
     
    Thank you
     
    Bernard
  15. Like
    Bernard reacted to simpleavr in M-Clock build, M for Minimalist, Multi-mode or Matrix   
    Are we voting for this round of POTM soon?
     
    Time to reveal my Easter Egg "game" for upvotes. 
     

     
    Source code now host on github. https://github.com/simpleavr/mclock
  16. Like
    Bernard got a reaction from spirilis in dtostrf in Energia   
    Hello,
     
    I finally got sprintf working. I am able to send and receive datas from BMP085
     
     
    here is my working code:
    /* Stellaris LM4F120 nRF24L01 TX BMP085 SPI module 2 I2C module 0 21/01/2014 */ #include<Wire.h> #include "BMP085_t.h" // in a IDE tab .. template from chicken #include <Enrf24.h> #include <nRF24L01.h> #include <string.h> #include <SPI.h> Enrf24 radio(PA_5,PA_6,PA_7); // CE, CSN, IRQ + SCK/MOSI/MISO ==> PB_4/PB_7/PB_6 char txaddr[] = {'d','e','v','-','0','\0'}; BMP085<0> PSensor; void setup() { Serial.begin(9600); Wire.setModule(0); Wire.begin(); // initialize I2C that connects to sensor PSensor.begin(); // initalize pressure sensor SPI.setModule(2); // SPI 2 SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(1); radio.begin(); // Defaults 1Mbps, channel 0, max TX power radio.setTXaddress((void*)txaddr); } //************************************************************************ void loop() { char str[5]; long value; PSensor.refresh(); // read sensor data BMP085 PSensor.calculate(); value = ((PSensor.pressure+50)/100); sprintf(str, "%.2d", value); radio.print(str); radio.print("---"); value = (PSensor.temperature/10); sprintf(str, "%.2d", value); radio.print(str); radio.flush(); // Force transmit (don't wait for any more data) delay(1000); } //************************************************************************* LM4F120 on the receiver side.
     
    Thank you all who helped me.
     
    Salutations
  17. Like
    Bernard reacted to spirilis in dtostrf in Energia   
    Huh, doing a quick google search, apparently dtostrf is a unique function that only comes with the AVR libc. Energia probably doesn't support it but it doesn't sound hard to emulate.
  18. Like
    Bernard reacted to energia in dtostrf in Energia   
    I have not looked at it in detail but it seems that sprintf() for floats is broken in Arduino/AVR. It seems that dtostrf() was implemented to offered as an alternative.
    The details are here: http://dereenigne.org/arduino/arduino-float-to-string
     
    On Stellaris sprintf() for floats is fully functional and you should use this to convert floats to strings.
    // Allocate enough to store PI with with 4 decimals. char str[5]; void setup() { Serial.begin(115200); Serial.print("PI in a string: "); // Print PI to a string with 4 decimals sprintf(str, "%.4f", PI); // Print the string to the serial terminal Serial.println(str); } void loop() { // Nothing to do here }
  19. Like
    Bernard got a reaction from Smakkemeken in How to come back to IP.Board   
    Hi,
    Thank you very much Bluehash .. it is ok
  20. Like
    Bernard got a reaction from Smakkemeken in How to come back to IP.Board   
    Hello,
     
    days ago I switched to IP.Board mobile ( just curious) and I cannot come back to Ip.Board. I haven't found how to do that. some help needed.
     
    Thank you
     
    Bernard
  21. Like
    Bernard got a reaction from sirri in Reading LM4F120 internal temp sensor   
    Hello,
     
    Here is a ino file that allow to display temperature  from LM4F120 internal sensor.
     
    It is based on example from TI workbook , ported a la mode Energia.
     
    Nothing spectacular. I am slowly learning ARM and I wanted to share.
     
    /* Read internal temperature sensor of LM4F120 Stellaris Launchpad Example from TI LM4F120 workbook A la mode Energia */ #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" #include "Energia.h" unsigned long ulADC0Value[4]; volatile unsigned long ulTempAvg; volatile unsigned long ulTempValueC; volatile unsigned long ulTempValueF; void setup() { Serial.begin(9600); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 250 ADCSequenceDisable(ADC0_BASE, 1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); } void loop() { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; ulTempValueC = (1475 - ((2475 * ulTempAvg)) / 4096)/10; ulTempValueF = ((ulTempValueC * 9) + 160) / 5; Serial.println(ulTempValueC); delay(300); } Salutations.
     
    Bernard
     
     
     
     
     
     
     
     
  22. Like
    Bernard got a reaction from pedroarbs in Timer interrupt on LM4F120 using TimerIntRegister issue   
    Hi,
     
    Thanks to patolin my problem is solved
  23. Like
    Bernard got a reaction from jcR in attachInterrupt on Stellaris Launchpad   
    Hello JCR,
     
    Contrary to arduino documentation on Stellaris you can use all  GPIO pins as first argument of the "attachinterrupt function"
     
    ex:
    attachInterrupt (PB_3, isrFunction, mode); Here is an example using PUSH1  on PF_4 that toggle RED_LED
     
    /* Test interruption et antirebond */ unsigned long DebounceTime; unsigned long LastDebounceTime = 0; volatile int FlagStateRedLed = LOW; volatile int FlagStateGreenLed = LOW; void setup() { Serial.begin(9600); pinMode(RED_LED, OUTPUT); pinMode(PUSH1, INPUT_PULLUP); attachInterrupt(PUSH1, ChangeStateRedLed, FALLING); } void loop() { for (int i = 0; i < 100; i++) { Serial.println(" Waiting for push1 pressed"); delay(10); } } void ChangeStateRedLed() { DebounceTime = millis(); if ( DebounceTime - LastDebounceTime > 200 || DebounceTime < LastDebounceTime) { FlagStateRedLed = !FlagStateRedLed; digitalWrite(RED_LED, FlagStateRedLed); LastDebounceTime = DebounceTime; } } Hope this help
     
    Cheers
     
    Bernard
  24. Like
    Bernard reacted to bluehash in How to come back to IP.Board   
    I need to switch you manually because of a bug... hold on.
     
    Edit: Check now. If not.. PM me.
  25. Like
    Bernard got a reaction from trungkiena6 in Help me about TIMER   
    Hi Trungkiena6,
     
    You could download EK-LM4F120XL LaunchPad Workshop Student Guide and Lab Manual from TI site.
     
    It includes a nice tutorial for interrupts and the timers.
     
    Cheers
     
    Bernard
     
     
     
     
     
×
×
  • Create New...