Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8427
    LadyStardust
    Participant

    Hi all,

    I am testing now a V.2 card, and accidentaly I didn´t change the pin mapping in the sketch, now the card is not responding, the green led is turning on but Arduino IDE is not recognizing it anymore. The sketch loaded is:
    Have you seen a similar problem?

    /* ************************************************************** 
     * Arduino sketch 
     * Author: Martijn Quaedvlieg / Jan de Laet (january 2017)
     * Generated with Generate script by Jan de Laet
     * 
     * *************************************************************/
    #include <SPI.h>
    
    // define the activation method ABP or OTAA
    #define ACT_METHOD_OTAA
    
    // show debug statements; comment next line to disable debug statements
    #define DEBUG
    
    /* **************************************************************
    * keys for device
    * *************************************************************/
    // The 2 below should be in little endian format (lsb)
    static const uint8_t PROGMEM DEVEUI[8]= {  };
    static const uint8_t PROGMEM APPEUI[8]= { };
    // This should be in big endian format (msb)
    static const uint8_t PROGMEM APPKEY[16] = { };
    
    // Uses LMIC libary by Thomas Telkamp and Matthijs Kooijman (https://github.com/matthijskooijman/arduino-lmic)
    #include <lmic.h>
    #include <hal/hal.h>
    
    // Declare the job control structures
    static osjob_t sendjob;
    
    // These callbacks are only used in over-the-air activation, so they are
    // left empty when ABP (we cannot leave them out completely unless
    // DISABLE_JOIN is set in config.h, otherwise the linker will complain).
    #ifdef ACT_METHOD_ABP
      void os_getArtEui (u1_t* buf) { }
      void os_getDevEui (u1_t* buf) { }
      void os_getDevKey (u1_t* buf) { }
    #else
      void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
      void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
      void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
    #endif
    
    /* ************************************************************** 
     * Pin mapping
     * *************************************************************/
    const lmic_pinmap lmic_pins = {
        .nss = 6,
        .rxtx = LMIC_UNUSED_PIN,
        .rst = 5,
        .dio = {2, 3, LMIC_UNUSED_PIN},
    };
    
    // I2C soil moisture settings (HAS)
    // https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/
    
    //#include <I2CSoilMoistureSensor.h>
    #include <Wire.h>
    #include "DHT.h"
    #define DHTPIN 9 
    #define DHTTYPE DHT22
    
    DHT dht(DHTPIN, DHTTYPE);
    
    //I2CSoilMoistureSensor sensor;
    
    unsigned int temp;    // Kelvin: temp reading + 2731 (includes 1 decimal)
    unsigned int hum;  // 
    unsigned int bat;     // light on a scale from 0 (dark) to 15 (light)
    
    // data to send
    static uint8_t dataTX[4];
    
    /* **************************************************************
     * user settings
     * *************************************************************/
    unsigned long starttime;
    unsigned long cycle_length = 1 * 60 * 1000UL; // cycle * mins_or_secs * 1000;
    
    /* **************************************************************
     * setup
     * *************************************************************/
    void setup() {
      // Wait (max 10 seconds) for the Serial Monitor
      while ((!Serial) && (millis() < 10000)){ }
    
      //Set baud rate
      Serial.begin(9600);
      Serial.println(F("temoperature (template version: 26Dec2016 generated: 17Apr2018)"));
    
      init_node();
      init_sensor();
    
      starttime = millis();
    }
    
    /* **************************************************************
     * loop
     * *************************************************************/
    void loop() {
      
      do_sense();
    
      // check if need to send
      if ((millis() - starttime) > cycle_length) { build_data(); do_send(); starttime = millis(); }
      
    }
    
    /* **************************************************************
     * sensor code, typical would be init_sensor(), do_sense(), build_data()
     * *************************************************************/
    /* **************************************************************
     * init the sensor
     * *************************************************************/
    void init_sensor() {
      //Wire.begin();
      dht.begin(); // reset sensor
      delay(1000); // give some time to boot up
    
    //  #ifdef DEBUG
    //    Serial.print("I2C Soil Moisture Sensor Address: ");
    //    Serial.println(dht.getAddress(),HEX);
    //    Serial.print("Sensor Firmware version: ");
    //    Serial.println(dht.getVersion(),HEX);
    //    Serial.println();
    //  #endif  
    }
    
    /* **************************************************************
     * do the reading
     * *************************************************************/
    void do_sense() {
    //  while (sensor.isBusy()) delay(50); // available since FW 2.3
    
    //  moisture = sensor.getCapacitance();
    //  
    //  int tempC = sensor.getTemperature();
    //  tempK = (unsigned int)(tempC + 2731);
    //
    //  unsigned int lightR = sensor.getLight(true); //request light measurement, wait and read light register
    //  // convert the light value (65535 = dark, 0 = light) to a scale of 0 to 15
    //  light = lightR / 4096.0;   // 15 = dark, 0 = light
    //  light = 15 - light;        // 0 = dark, 15 = light
    //
    //  // put sensor to sleep
    //  sensor.sleep();
    
     float t = dht.readTemperature(); 
     int32_t temp = t * 10;
      
    //  #ifdef DEBUG
    //    Serial.print(F("light:"));
    //    Serial.print(light);
    //    Serial.print(F(" temp:"));
    //    Serial.print(temp);
    //    Serial.print(F(" moisture:"));
    //    Serial.print(moisture);
    //    Serial.println(F(""));
    //  #endif
    }
    
    /* **************************************************************
     * build data to transmit in dataTX
     *
     * Suggested payload function for this data
     *
     *  var light = (bytes[0] & 0xF0) >> 4;
     *  var temp = (((bytes[0] & 0x0F) <<8 | bytes[1]) - 2731) / 10;
     *  var moisture = bytes[2] << 8 | bytes[3];
     *  
     *  return { payload: light + ";" + temp + ";" + moisture };
     *
     * *************************************************************/
    void build_data() {
      dataTX[0] = (hum << 4) | (temp / 256);
      dataTX[1] = temp;
      dataTX[2] = bat / 256;
      dataTX[3] = bat;
    }
    
    /* **************************************************************
     * radio code, typical would be init_node(), do_send(), etc
     * *************************************************************/
    /* **************************************************************
     * init the Node
     * *************************************************************/
    void init_node() {
      #ifdef VCC_ENABLE
         // For Pinoccio Scout boards
         pinMode(VCC_ENABLE, OUTPUT);
         digitalWrite(VCC_ENABLE, HIGH);
         delay(1000);
      #endif
    
      // LMIC init
      os_init();
      // Reset the MAC state. Session and pending data transfers will be discarded.
      LMIC_reset();
    
      #ifdef ACT_METHOD_ABP
        // Disable link check validation
        LMIC_setLinkCheckMode(0);
    
        // TTN uses SF9 for its RX2 window.
        LMIC.dn2Dr = DR_SF9;
    
        // Set data rate and transmit power (note: txpow seems to be ignored by the library)
        LMIC_setDrTxpow(DR_SF7,14);
      #endif
    
      #ifdef ACT_METHOD_OTAA
        // got this fix from forum: https://www.thethingsnetwork.org/forum/t/over-the-air-activation-otaa-with-lmic/1921/36
        LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
      #endif
    
    }
    
    /* **************************************************************
     * send the message
     * *************************************************************/
    void do_send() {
    
      Serial.print(millis());
      Serial.print(F(" Sending.. "));  
    
      send_message(&sendjob);
    
      // wait for send to complete
      Serial.print(millis());
      Serial.print(F(" Waiting.. "));  
     
      while ( (LMIC.opmode & OP_JOINING) or (LMIC.opmode & OP_TXRXPEND) ) { os_runloop_once();  }
      Serial.print(millis());
      Serial.println(F(" TX_COMPLETE"));
    }
      
    /* *****************************************************************************
    * send_message
    * ****************************************************************************/
    void send_message(osjob_t* j) {
      // Check if there is not a current TX/RX job running
      if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
      } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, dataTX, sizeof(dataTX), 0);
        Serial.println(F("Packet queued"));
      }
    }
    
    /*******************************************************************************/
    void onEvent (ev_t ev) {
        case EV_TXCOMPLETE:
          Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
          if (LMIC.dataLen) {
            // data received in rx slot after tx
            Serial.print(F("Data Received: "));
            Serial.write(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
            Serial.println();
          }
          // schedule next transmission
          // os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), send_message);
          break;
        case EV_LOST_TSYNC:
          Serial.println(F("EV_LOST_TSYNC"));
          break;
        case EV_RESET:
          Serial.println(F("EV_RESET"));
          break;
        case EV_RXCOMPLETE:
          // data received in ping slot
          Serial.println(F("EV_RXCOMPLETE"));
          break;
        case EV_LINK_DEAD:
          Serial.println(F("EV_LINK_DEAD"));
          break;
        case EV_LINK_ALIVE:
          Serial.println(F("EV_LINK_ALIVE"));
          break;
        default:
          Serial.println(F("Unknown event"));
          break;
      }
        
    } 

    I normally load this configuration and it works properly:

    // Pin mapping
    const lmic_pinmap lmic_pins = {
      .nss = 5,
      .rxtx = LMIC_UNUSED_PIN,
      .rst = 3,
      .dio = {2, 6, LMIC_UNUSED_PIN},
    };

    Thanks a lot for your help.

    Regards.

    #8440
    LIM PHANG MOH
    Keymaster

    Try to upload a simple blink sketch to the board to get the board out of this state. You can do this by double pressing the reset button in quick succession after you press the upload button on the Arduino IDE. This works all the time.

    Looking at your code, the code uses Serial instead of SerialUSB for debug information. So, unless you are connecting the Serial pins on the board to a USB-Serial converter, you won’t see anything if you connect the Mini Ultra Pro’s USB port to the IDE.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.