Arduino 32u4 (MEGA) with built in GSM for $18





  • I bought the board with the relays as a basis for a smart lock.

    I can't get it to work though, as I'm getting a TSP:FAIL, so a transport fail error.

    First I connected directly to the 3.3v output of the board. No dice.

    Now I'm using a 3.3v regulator board (powerled is on) and an eByte red NRF24L01 module, which are great. But still the same error.

    That leaves a problem with the data connection.

    • Pins 13 through 10 are available normally.
    • I had to route the CE pin to pin 7
    • I have not connected the IRQ pin.

    I thought I'd check:

    • Should I connect the IRQ pin to something? I don't think I have a real IRQ pin on the board available.
    • Is there something about Arduino Leonardo that is different?

    Ah, as far as I can tell the Leonardo is.. different.

    I can try and connect via the ICS pins? Unfortunately they are of a smaller size on this board.

    And I may need to use an extra RF24 library?



  • By connecting the ICSP pins following this reference I got further!

    2010 !TSM:FPAR:NO REPLY
    2010 TSM:FPAR
    2011 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4013 !TSM:FPAR:NO REPLY
    4013 TSM:FPAR
    4014 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6016 !TSM:FPAR:NO REPLY
    6016 TSM:FPAR
    6017 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8019 !TSM:FPAR:FAIL
    8019 TSM:FAIL:CNT=1
    8019 TSM:FAIL:DIS
    8019 TSF:TDI:TSL
    10001 MCO:BGN:STP

    I now have this in my code:

    #define MY_RF24_CE_PIN 7
    #define MY_RF24_CS_PIN 6
    

    And connected the MOSI, MISO and SCK pins of the NRF24 module to the MOSI, MISO and SCK pins of the ICSP header.



  • It seems to connect!

    Here's some quick test code. It doesn't toggle the switches yet, it's just a connection test.

    This is how I've connected the pins:

    NRF24 adapter board -> Electrow GSM relay board
    ---------- -> --------
    5V -> 5V
    GND -> GND
    CE -> Pin 7
    CSN -> Pin 6
    SCK -> middle pin on the inside of the board
    MO -> Middle pin on the outside of the board (right behind the RST button)
    MI -> On the corner pin closest to the middle of the board.
    IRQ-> Not connected

    /*
     * Author: Elecrow Keen
     * Date:6/30/2017
     * IDE V1.8.2 
     * Email:keen@elecrow.com    
     * Function: SMS control relay
     * Please note:
        When the the board receive "R1O" by SMS, the relay 1 will be open and the "R1C" that it will be close. 
        
        "R1O"/""R1C" means:
          R ->  Relay
          1 ->  Relay 1 
          O ->  Open
          C ->  Close
          
        It also used Relay2,Relay3 and Relay4.
     */
    
    #define DEBUG true    //Open the debug information 
    
    // Define Node ID
    #define MY_NODE_ID 15
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    //
    // SETTINGS
    //
    
    // Enable and select the attached radio type
    #define MY_RADIO_RF24                               // This is a common and simple radio used with MySensors. Downside is that it uses the same frequency space as WiFi.
    //#define MY_RADIO_NRF5_ESB                         // This is a new type of device that is arduino and radio all in one. Currently not suitable for beginners yet.
    //#define MY_RADIO_RFM69                            // This is an open source radio on the 433mhz frequency. Great range and built-in encryption, but more expensive and little more difficult to connect.
    //#define MY_RADIO_RFM95                            // This is a LoRaWan radio, which can have a range of 10km.
    
    // MySensors: Choose your desired radio power level. High power can cause issues on cheap Chinese NRF24 radio's.
    //#define MY_RF24_PA_LEVEL RF24_PA_MIN
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    #define MY_RF24_PA_LEVEL RF24_PA_HIGH
    //#define MY_RF24_PA_LEVEL RF24_PA_MAX
    
    // Mysensors security
    //#define MY_ENCRYPTION_SIMPLE_PASSWD "changeme"    // Be aware, the length of the password has an effect on memory use.
    //#define MY_SIGNING_SOFT_RANDOMSEED_PIN A7         // Setting a pin to pickup random electromagnetic noise helps make encryption more secure.
    
    // Mysensors advanced settings
    #define MY_TRANSPORT_WAIT_READY_MS 10000            // Try connecting for 10 seconds. Otherwise just continue.
    //#define MY_RF24_CHANNEL 100                       // In EU the default channel 76 overlaps with wifi, so you could try using channel 100. But you will have to set this up on every device, and also on the controller.
    //#define MY_RF24_DATARATE RF24_1MBPS               // Slower datarate makes the network more stable?
    //#define MY_NODE_ID 10                             // Giving a node a manual ID can in rare cases fix connection issues.
    //#define MY_PARENT_NODE_ID 0                       // Fixating the ID of the gatewaynode can in rare cases fix connection issues.
    //#define MY_PARENT_NODE_IS_STATIC                  // Used together with setting the parent node ID. Daking the controller ID static can in rare cases fix connection issues.
    #define MY_SPLASH_SCREEN_DISABLED                   // Saves a little memory.
    //#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE      // Saves a little memory.
    
    // Enable MySensors debug output to the serial monitor, so you can check if the radio is working ok.
    #define MY_DEBUG 
    
    // MySensors devices form a mesh network by passing along messages for each other. Do you want this node to also be a repeater?
    //#define MY_REPEATER_FEATURE                         // Add or remove the two slashes at the beginning of this line to select if you want this sensor to act as a repeater for other sensors. If this node is on battery power, you probably shouldn't enable this.
    //#define MY_RX_MESSAGE_BUFFER_FEATURE
    
    #define MY_RF24_CE_PIN 7
    #define MY_RF24_CS_PIN 6
    
    
    // LIBRARIES (in the Arduino IDE go to Sketch -> Include Library -> Manage Libraries to add these if you don't have them installed yet.)
    #include <MySensors.h>                              // MySensors library                  
    
    
    
     // the number of the Relay pin
    const int Relay1 = 2;
    const int Relay2 = 3;
    const int Relay3 = 4;
    const int Relay4 = 5;
    /*
    R1O means open  relay 1
    R1C means close relay 1
    The same as others 
    */
    String R1O = "R1O";
    String R1C = "R1C";
    String R2O = "R2O";
    String R2C = "R2C";
    String R3O = "R3O";
    String R3C = "R3C";
    String R4O = "R4O";
    String R4C = "R4C";
    
    char target[] ="CMTI";  
    int sms_no;
    String get_message = "";   
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(F("Elecrow SMS"), F("0.2"));
      
      // Register all sensors to gateway (they will be created as child devices): 
      present(1, S_BINARY);
    }
    
    
    
    void setup() {
    
          delay (2000);
          Serial.begin(19200); 
          Serial1.begin(19200);
          for(int i=2;i<6;i++){ // initialize the Relay pins status:
            pinMode(i,OUTPUT);
            digitalWrite(i,LOW);
          }
          //Power on the SIM800C
          
          pinMode(9,OUTPUT);
          digitalWrite(9,HIGH);
          delay(3000);
          digitalWrite(9,LOW);
          delay(1000);
          
          sendData("AT",2000,DEBUG);
          sendData("AT+CMGF=1",1000,DEBUG);        //Set the SMS in text mode
    } 
    
    void loop() { 
           if(Serial1.available()>0){
            Serial.write(Serial1.read());
                
              if(Serial1.find(target)){                  //If receive a new SMS
                 sms_no = Serial1.parseInt();            //Get the SMS ID        
                 get_message = "AT+CMGR="+(String)sms_no; //The command of the content of the SMS
                 Serial.println("******************** Print the relay status *********************" );
                 Data_handling(get_message,500,DEBUG);    //Get the content of the SMS 
                 Serial.println("*****************************END*********************************" );
             } 
             
         }
         while(Serial1.read() >= 0){}                     // Clear serial buffer   
    }
    
    void Data_handling(String command, const int timeout, boolean debug)  //data handling function
    {
        String response = "";    
        Serial1.println(command); 
        long int time = millis();
        while( (time+timeout) > millis()){
          while(Serial1.available()){       
            response += (char)Serial1.read(); 
          }  
        }    
       if (response.indexOf(R1O)>=0) {
        digitalWrite(Relay1,HIGH);
        if(debug){
        Serial.println("Open Relay 1");
        }
        }
       else if (response.indexOf(R1C)>=0) {
        digitalWrite(Relay1,LOW);
        if(debug){
        Serial.println("Close Relay 1");
        }
       }
       else if(response.indexOf(R2O)>=0) {
        digitalWrite(Relay2,HIGH);
        if(debug){
        Serial.println("Open Relay 2");
        }
       }
       else if(response.indexOf(R2C)>=0) {
        digitalWrite(Relay2,LOW);
        if(debug){
        Serial.println("Close Relay 2");
        }
       }
       else if (response.indexOf(R3O)>=0) {
        digitalWrite(Relay3,HIGH);
        if(debug){
        Serial.println("Open Relay 3");
        }
       }
       else if(response.indexOf(R3C)>=0) {
        digitalWrite(Relay3,LOW);
        if(debug){
        Serial.println("Close Relay 3");
        }
       }
       else if(response.indexOf(R4O)>=0) {
        digitalWrite(Relay4,HIGH);
        if(debug){
        Serial.println("Open Relay 4");
        }
       }
       else if(response.indexOf(R4C)>=0) {
        digitalWrite(Relay4,LOW);
        if(debug){
        Serial.println("Close Relay 4");
        }
       }else
       Serial.println("....Error message....");
    }
    
    void sendData(String command, const int timeout, boolean debug)  //Send command function
    {
        String response = "";    
        Serial1.println(command); 
        long int time = millis();
        while( (time+timeout) > millis()){
          while(Serial1.available()){       
            response += (char)Serial1.read(); 
          }  
        }    
        if(debug){
          Serial.print(response);
        }    
    }
    

 

464
Online

7.9k
Users

8.8k
Topics

94.3k
Posts