Module is not awake when connect to arduino uno

The SparqEE CELLv1.0 device.
REGSteve
Posts: 10
Joined: Thu Sep 22, 2016 8:02 am

Re: Module is not awake when connect to arduino uno

Postby REGSteve » Mon Oct 03, 2016 5:34 am

This is my program:

ShieldA_Talkv1

Code: Select all

#include <SoftwareSerial.h>
#include "shieldA_lib.h"


//-----------------------------------------------------------------------------
// SETUP ----------------------------------------------------------------------
//-----------------------------------------------------------------------------

void setup() {
  mySerial.begin(115200);
  mySerial.println("");
 
  cmd_setup();                     //set-up shield GPIO
  //cmd_power();                     //power on
  //gpio_turnOn();
 
  //debug_print( "MAIN:", LEVEL_INFO );
}


//-----------------------------------------------------------------------------
// LOOP -----------------------------------------------------------------------
//-----------------------------------------------------------------------------

void loop() {
 // mySerial.listen();
 if (mySerial.available()) {
    char myChar = (char)mySerial.read();
    Serial.print(myChar);
 }
}


void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    mySerial.println(inChar);
    //Serial.print(inChar);
  }
}


ShieldA_lib.h

Code: Select all

//-----------------------------------------------------------------------------
// GLOBALS --------------------------------------------------------------------
//-----------------------------------------------------------------------------


#define pin_rx   0                    //Arduino shield pinout to CELLv1.0
#define pin_tx   1                    //
#define pin_prn  A0                   //PON_RST_N           O - Module reset
#define pin_mwa  4                    //MODULE_WAKEUP_AP    I - Module wakes up AP
#define pin_mp   5                    //MODULE_POWERON      I - Module power-on status
#define pin_mr   6                    //MODULE_READY        I - AP queries Module sleep status
#define pin_ar   7                    //AP_READY            O - Module queries AP sleep status
#define pin_awm  8                    //AP_WAKEUP_MODULE    O - AP wakes up Module
#define pin_po   9                    //POWER_ON            O - Power-on/Power-off

#define pin_ledG 1                    //LED Green
#define pin_ledR 2                    //LED Red
#define pin_ledB 3                    //LED Blue

/*
//ALTERNATE PINOUT
#define pin_rx   0                    //Arduino shield pinout to CELLv1.0
#define pin_tx   1                    //
#define pin_prn  7                    //PON_RST_N           O - Module reset
#define pin_mwa  8                    //MODULE_WAKEUP_AP    I - Module wakes up AP
#define pin_mp   9                    //MODULE_POWERON      I - Module power-on status
#define pin_mr   10                   //MODULE_READY        I - AP queries Module sleep status
#define pin_ar   11                   //AP_READY            O - Module queries AP sleep status
#define pin_awm  12                   //AP_WAKEUP_MODULE    O - AP wakes up Module
#define pin_po   13                   //POWER_ON            O - Power-on/Power-off
*/

#define GLOB_DEBUG     5              //Global debug print level 

#define LEVEL_CRITICAL 1              //ENUM levels for printing (enum requires another module, so using a dict)
#define LEVEL_ERROR    2
#define LEVEL_WARNING  3
#define LEVEL_INFO     4
#define LEVEL_DEBUG    5

#define LED_THRESHOLD  200            //analog threshold for LEDs


//SoftwareSerial for debugging

//ALTERNATE PINOUT
/*
int sw_rx = 2;
int sw_tx = 3;
*/
int sw_rx = 10;
int sw_tx = 11;

SoftwareSerial mySerial(sw_rx, sw_tx); // RX, TX

String buffer = "";                //a string to hold incoming data
int bufferLen = 0;                 //keep track of buffer length
char glob_debug = GLOB_DEBUG;


ShieldA_lib:

Code: Select all


//-----------------------------------------------------------------------------
// GPIO COMMANDS --------------------------------------------------------------
//-----------------------------------------------------------------------------


//description:   Turn module on
//input:         none
//return:        none
void gpio_turnOn() {
  debug_print1( "GPIO: TurnOn",             LEVEL_INFO );
  delay(100);
  digitalWrite(pin_po,  LOW);
  delay(100);
  digitalWrite(pin_po,  HIGH);
}

byte gpio_ledRead(byte ledNum) {
  //This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit
  int led = analogRead(ledNum);       // read the input pin
  debug_printLevel(LEVEL_DEBUG);
  debug_print( "GPIO: ledRead: ",           LEVEL_DEBUG );
  debug_print( String(ledNum),              LEVEL_DEBUG );
  debug_print( " - ",                       LEVEL_DEBUG );
  debug_print( String(led),                 LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
  if (led > LED_THRESHOLD) return 1;
  return 0;
}

//description:   Check if module is connected to a network or not
//input:         none
//return:        0=2G or 3G, 1=unregistered
byte gpio_ledConnected() {
  debug_print1( "GPIO: LED Connected",      LEVEL_INFO );
  byte gpio_ledB = gpio_ledRead(pin_ledB);                      //3G
  //byte gpio_ledR = gpio_ledRead(pin_ledR);                      //Unregistered
  byte gpio_ledG = gpio_ledRead(pin_ledG);                      //2G
  if ((gpio_ledG == 0) or (gpio_ledB == 0)) {
    debug_print1( " Connected to a cellular network", LEVEL_INFO );
    return 0;
  }
  else {
    debug_print1( " SIM Unregistered",      LEVEL_INFO );
    return 1;
  }
}
       
//description:   Check if module power is on (one of the LEDs should be lit with power)
//input:         none
//return:        0=power,1=off
byte gpio_ledLit() {
  debug_print1( "GPIO: LED Lit",            LEVEL_INFO );
  byte gpio_ledB = gpio_ledRead(pin_ledB);                      //3G
  byte gpio_ledR = gpio_ledRead(pin_ledR);                      //Unregistered
  byte gpio_ledG = gpio_ledRead(pin_ledG);                      //2G
 
  if ((gpio_ledG == 0) or (gpio_ledB == 0) or (gpio_ledR == 0)) {
    debug_print1( " On",                    LEVEL_INFO );
    return 0;
  }
  else {
    debug_print1( " Off",                   LEVEL_INFO );
    return 1;
  }
}
       
//-----------------------------------------------------------------------------
// DEBUG COMMANDS -------------------------------------------------------------
//-----------------------------------------------------------------------------

//description:   Print state of network LEDs
//input:         none
//return:        none
void debug_led() {
  debug_print1( "LED",                      LEVEL_DEBUG );
  byte ledR = gpio_ledRead(pin_ledR);
  byte ledG = gpio_ledRead(pin_ledG);
  byte ledB = gpio_ledRead(pin_ledB);
 
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " ledR: ",                   LEVEL_DEBUG );
  debug_print( String(ledR),                LEVEL_DEBUG );
  debug_print( " Red   - Not Connected (0 on, 1 off)", LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
 
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " ledG: ",                   LEVEL_DEBUG );
  debug_print( String(ledG),                LEVEL_DEBUG );
  debug_print( " Green - 2G (0 on, 1 off)", LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
 
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " ledB: ",                   LEVEL_DEBUG );
  debug_print( String(ledB),                LEVEL_DEBUG );
  debug_print( " Blue  - 3G (0 on, 1 off)", LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
}

//description:   Print state of status LEDs
//input:         none
//return:        none
void debug_inputs() {
  debug_print1( "Inputs",                   LEVEL_DEBUG );
 
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " Module Wakeup AP: ",       LEVEL_DEBUG );
  debug_print( String(digitalRead(pin_mwa)),LEVEL_DEBUG );
  debug_print( "(0 wake AP, 1 AP awake)",   LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
   
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " Module Poweron: ",         LEVEL_DEBUG );
  debug_print( String(digitalRead(pin_mp)), LEVEL_DEBUG );
  debug_print( "(0 off, 1 power)",          LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
   
  debug_printLevel(LEVEL_DEBUG);
  debug_print( " Module Ready: ",           LEVEL_DEBUG );
  debug_print( String(digitalRead(pin_mr)), LEVEL_DEBUG );
  debug_print( "(0 awake, 1 asleep)",       LEVEL_DEBUG );
  debug_println( LEVEL_DEBUG );
}
   
//description:   debug print function - debug level for long statements
//input:         none
//return:        none
void debug_printLevel(byte level) {
  if (level <= glob_debug) {
    if (LEVEL_CRITICAL == level)     mySerial.print("CRITICAL:  ");
    else if (LEVEL_ERROR == level)   mySerial.print("ERROR:     ");
    else if (LEVEL_WARNING == level) mySerial.print("WARNING:   ");
    else if (LEVEL_INFO == level)    mySerial.print("INFO:      ");
    else if (LEVEL_DEBUG == level)   mySerial.print("DEBUG:     ");
    else                             mySerial.print("UNDEFINED: ");
  }
}
//description:   debug print function - single string for long statements
//input:         none
//return:        none
void debug_print(String string, byte level) {
  if (level <= glob_debug) {
    mySerial.print(string);
  }
}
//description:   debug print function - newline for long strings
//input:         none
//return:        none
void debug_println(byte level) {
  if (level <= glob_debug) {
    mySerial.println("");
  }
}

//description:   debug print function - print everything for short statements
//input:         none
//return:        none
void debug_print1(String string, byte level) {
  debug_printLevel(level);
  if (level <= glob_debug) {
    mySerial.println(string);
  }
}

//-----------------------------------------------------------------------------
// PROCESSING COMMANDS --------------------------------------------------------
//-----------------------------------------------------------------------------

//description:   Setup GPIO for RasPi shield
//input:         none
//return:        none
void cmd_setup() {
  //debug_print1( "CMD Setup",                LEVEL_DEBUG );
  Serial.begin(115200);
 
  pinMode(pin_prn, OUTPUT);
  pinMode(pin_mwa, INPUT);
  pinMode(pin_mp,  INPUT);
  pinMode(pin_mr,  INPUT);
  pinMode(pin_ar,  OUTPUT);
  pinMode(pin_awm, OUTPUT);
  pinMode(pin_po,  OUTPUT);
// pinMode(sw_rx, INPUT);
// pinMode(sw_tx, OUTPUT);
 
 // digitalWrite(pin_prn, HIGH);            //no reset (toggle to reset)
//  digitalWrite(pin_ar,  LOW);             //AP is awake
 // digitalWrite(pin_awm, LOW);             //AP wakes up module
 // digitalWrite(pin_po,  HIGH);            //high is awake (toggle later to turn on/off)
 digitalWrite(pin_po, HIGH);
   delay(100);
  digitalWrite(pin_po,  LOW);
  delay(1000);
  digitalWrite(pin_po,  HIGH);
}
   
//description    Check if CELLv1.0 is on, if not, turn it on
//input:         none
//return:        none
byte cmd_power() {
  debug_print1( "CMD Power",                LEVEL_DEBUG );
    byte tries = 3;
    byte ret = 1;
    while (tries > 0) {
        tries -= 1;
        debug_led();
        debug_inputs();
       
        byte tries_led=3;                 //in case the LED is flashing
        while ((tries_led > 0) and (ret != 0)) {
            ret &= gpio_ledLit();
            tries_led -= 1;
            delay(1000);
        }
       
        debug_printLevel(LEVEL_DEBUG);
        debug_print( "LED RETURN: ",        LEVEL_DEBUG );
        debug_print( String(ret),           LEVEL_DEBUG );
        debug_print( "(0 1+ LED on, 1 all LEDs off)", LEVEL_DEBUG );
        debug_println( LEVEL_DEBUG );
       
        if (ret != 0) {
            //ret_status = gpio_statusMR();
            //if (ret_status != 0)
            gpio_turnOn();
        }
        else {
            tries = 0;
        }
    }
    if (ret != 0) {
        debug_print1( "FATAL ERROR - Module is not turning on (Check power)", LEVEL_CRITICAL );
             
        //KILLS APP *****
        //while (1);
     
        return 1;
    }
    return 0;
}


This program is only uploaded to the arduino 1. Arduino 2 has no program uploaded to it. Currently, i am using without the shield because it does not work with the shield. I tried using the CELLv1.0 by itself via COM port & modem which works so i suspect something is wrong with the shield.

User avatar
donjohnii
Site Admin
Posts: 686
Joined: Tue Jul 30, 2013 2:19 pm

Re: Module is not awake when connect to arduino uno

Postby donjohnii » Mon Oct 03, 2016 6:41 am

So you mean the cellv1.0 works as you got the modem to work via usb? Is that all you got to work thus far?

If there is no program running on arduino 2, how do u expect to communicate? What are you expecting to happen...?

REGSteve
Posts: 10
Joined: Thu Sep 22, 2016 8:02 am

Re: Module is not awake when connect to arduino uno

Postby REGSteve » Mon Oct 03, 2016 6:51 am

My bad, I will upload a serial.read program to my arduino 2 and try again. Yes, currently i have only tried the modem connection and it works.

REGSteve
Posts: 10
Joined: Thu Sep 22, 2016 8:02 am

Re: Module is not awake when connect to arduino uno

Postby REGSteve » Wed Oct 05, 2016 4:37 am

Code: Select all

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
    if(Serial.available()){
      char test=Serial.read();
    Serial.print(test);
  }



This is my code for the arduino 2 but all i getting is an echo. There is no "OK" response from the CELL when i typed "AT" or "at".

User avatar
donjohnii
Site Admin
Posts: 686
Joined: Tue Jul 30, 2013 2:19 pm

Re: Module is not awake when connect to arduino uno

Postby donjohnii » Wed Oct 05, 2016 6:09 am

I don't think you want to echo on the Arduino2, that's just to test itself... you just need to initialize it in order to use it as a USB-Serial converter. I think, I haven't done that.

The test for the Arduino2 for the final configuration - you should be able to see an echo only if you jumper TX to RX. Then on the actual setup, with the same initialization code, you should be passing TX to the Arduino1 and RX should come back in from the Arduino1 TX which is read and seen on the Arduino2 console. That should be the setup for the Arduino2 acting as a USB/Serial converter.

REGSteve
Posts: 10
Joined: Thu Sep 22, 2016 8:02 am

Re: Module is not awake when connect to arduino uno

Postby REGSteve » Wed Oct 05, 2016 8:53 am

So you mean like this?

Arduino 2 TX <----> Arduino 1 RX
Arduino 1 TX <----> Arduino 2 RX

User avatar
donjohnii
Site Admin
Posts: 686
Joined: Tue Jul 30, 2013 2:19 pm

Re: Module is not awake when connect to arduino uno

Postby donjohnii » Wed Oct 05, 2016 4:02 pm

REGSteve wrote:So you mean like this?

Arduino 2 TX <----> Arduino 1 RX
Arduino 1 TX <----> Arduino 2 RX



Yea, after you validate that the single Arduino 2 echos properly when jumpered
Arduino 2 TX <----> Arduino 2 RX

REGSteve
Posts: 10
Joined: Thu Sep 22, 2016 8:02 am

Re: Module is not awake when connect to arduino uno

Postby REGSteve » Sat Oct 08, 2016 1:09 am

Thanks for the help!! Finally got it to work. Connected the 5v from arduino to Vo instead of Vref. I think the arduino to arduino method is not safe as some of the data coming through are missing. I used the TTL to USB cable instead.


Return to “CELLv1.0”

Who is online

Users browsing this forum: No registered users and 1 guest