-
Notifications
You must be signed in to change notification settings - Fork 5
How to avoid the simcom module turning on at boot #8
Comments
Some update on this issue. I am basically unable to turn the module off by pulling down the power pin. I have looked at the power off procedure for the a7608 here, and here is some code to demonstrate how the procedure fails #define PWR_PIN 4
// A7608 Power off
// see simcom-A7608 hardware design document
void modem_hw_poweroff() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW); delay(3000); // this is Toff
digitalWrite(PWR_PIN, HIGH);
}
void setup() {
// setup ports
Serial.begin(9600); delay(1000);
Serial.println("start");
delay(15000); // module will power on automatically at boot during this delay
// initiate power off
Serial.println("try poweroff");
modem_hw_poweroff(); // this does not work
Serial.println("done?"); // here module should be off, but it's not
delay(50000);
} I have tried keeping the power pin low for different times, but I am basically unable to turn the module off via the power pin. Using the Basically what I am asking is how can I shutdown the module, or prevent it from starting at boot. |
You can declare a variable (RTC_DATA_ATTR int num ). Judgment to the tenth time then execute start A7608 |
Hi @LilyGO, I see what you mean, but that is not sufficient. For some reason the module wakes up automatically at boot. It would be nice to understand why. Anyway, I found this issue which uses the functions Also, given how the GPIO 4 is connected to the POWER KEY of the simcom module (see schematic) a void modem_hw_poweroff() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, HIGH); delay(3000); // this is Toff
digitalWrite(PWR_PIN, LOW); delay(2000);
// avoid modem starting when waking up from sleep
gpio_deep_sleep_hold_en();
gpio_hold_en(GPIO_NUM_4);
} This can be closed. EDIT: the code above works but hold the pin state during sleep makes it impossible to reach low currents (i get about 1.5 mA). See comment below for the correct implementation. |
Some updates on this issue in case people have similar issues. I have finally discovered what is the purpose of the // pins
#define BAT_EN 12
#define PWR_PIN 4
#define RESET 5
// enable modem on battery power
void enable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, HIGH);
}
// disable modem on battery power (not a power off, just avoid it waking up by itself)
void disable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, LOW);
}
// A7608 Power off
// see simcom-A7608 hardware design document
void modem_hw_poweroff() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW); delay(100);
digitalWrite(PWR_PIN, HIGH); delay(3000); // this is Toff
digitalWrite(PWR_PIN, LOW);
}
// A7608 Power on
// see simcom-A7608 hardware design document
void modem_hw_poweron() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW); delay(100);
digitalWrite(PWR_PIN, HIGH); delay(1000); // this is Ton
digitalWrite(PWR_PIN, LOW); delay(20000); // wait for module to start
}
// persistent variable after sleep
RTC_DATA_ATTR int bootCount = 0;
// microseconds to seconds
int us_to_s_factor = 1000000;
void setup() {
// start serial
Serial.begin(9600); delay(100);
// update
bootCount++;
Serial.print("bootCount = "); Serial.println(bootCount);
// turn on every five boots (useful to send data every N sampling periods)
if (bootCount == 1 || bootCount == 5) {
// battery enable
// withouth this, the simcom module cannot turn on while on battery power
Serial.print("enabling battery ...");
enable_battery_functions();
Serial.println("done");
// power on
Serial.print("modem power on ...");
modem_hw_poweron();
Serial.println("done");
// do stuff with the network ...
// battery disable
// withouth this, modem wakes up autonomously during deep sleep
Serial.print("disabling battery ...");
disable_battery_functions();
Serial.println("done");
// reset bootCount
bootCount = 1;
}
// some task, e.g. sample a sensor, etc..
delay(15000);
// shutdown
if (bootCount == 1) {
Serial.print("modem power off ...");
modem_hw_poweroff();
Serial.println("done");
// modem does not wake up after this if
// disable_battery_functions has been called
}
// go to sleep
Serial.print("going to sleep");
esp_sleep_enable_timer_wakeup(5 * us_to_s_factor); delay(100);
esp_deep_sleep_start();
}
void loop() {}
The simcom module is powered on when Note that all of this only works when on battery power. If the board is attached to usb, the |
Reopening this issue, as I have not been able to find a solution for my use case. Here is a minimal working example of what I am trying to do. The board should periodically wake up from sleep to take a measurement from a sensor and every I have flashed this code on the three boards I purchased and none of them works. The modem never wakes up. I have plugged a multimeter in series with the battery to measure the current use to debug what is going on and here are my conclusions. All is good until I wonder if this might have to do with the board design, but I would appreciate some help on this. Perhaps there is a software solution this this problem. Thanks. #define TINY_GSM_MODEM_SIM7600
#include <TinyGsmClient.h>
TinyGsm modem(Serial1);
// pins
#define BAT_EN 12
#define PWR_PIN 4
#define RESET 5
#define PIN_TX 26
#define PIN_RX 27
const char apn[] = "em";
const char gprsUser[] = "";
const char gprsPass[] = "";
// enable battery
void enable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, HIGH);
}
// disable battery
void disable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, LOW); delay(100);
}
// A7608 Reset
// see simcom-A7608 hardware design document
void modem_hw_reset() {
pinMode(RESET, OUTPUT);
digitalWrite(RESET, HIGH); delay(1000);
digitalWrite(RESET, LOW); delay(100);
}
// A7608 Power on
// see simcom-A7608 hardware design document
void modem_hw_poweron() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, HIGH); delay(1000); // this is Ton
digitalWrite(PWR_PIN, LOW); delay(15000);
}
RTC_DATA_ATTR int bootCount = 0;
int s_to_us_factor = 1000000;
void setup() {
// some delay to see current draw on multimeter
delay(3000);
// start main serial port
Serial.begin(115200);
while (!Serial) {}
// bootcount keeps increasing on usb power
Serial.print("bootcount: ");
bootCount++;
Serial.println(bootCount);
// start modem every three boots
if (bootCount % 3 == 0) {
Serial.println("Enabling battery ...");
enable_battery_functions();
// wait modem to start. Does not happen. I think esp just restarts
Serial.println("Resetting modem ...");
modem_hw_reset();
delay(15000);
// start serial communication with simcom module?
Serial1.begin(115200, SERIAL_8N1, PIN_RX, PIN_TX);
while (!Serial1) {}
Serial.print("Initializing modem ...");
if (modem.init()) {
Serial.println(" done");
} else {
Serial.println(" failed");
}
Serial.print("Waiting for network ...");
if (modem.waitForNetwork()) {
Serial.println(" done");
} else {
Serial.println(" failed");
}
Serial.print("Connecting to access point ...");
if (modem.gprsConnect(apn, gprsUser, gprsPass)) {
Serial.println(" done");
} else {
Serial.println(" failed");
}
Serial.println("Disconnecting GPRS ...");
modem.gprsDisconnect();
Serial.println("Powering off modem ...");
modem.poweroff();
// on usb power modem wakes up anyway during sleep, but on battery
// power this allows the modem to remain off
Serial.println("Disabling battery functions");
disable_battery_functions();
}
Serial.print("Going to sleep");
esp_sleep_enable_timer_wakeup(15 * s_to_us_factor); delay(200);
esp_deep_sleep_start();
}
void loop() {
}
|
//A7608 Power on
|
Hi @LilyGO, thanks, but I am not sure I understand what you mean – i hope you can clarify. The reset and power on should only be executed once every Secondly, what do you mean by "handling" the BAT_EN status? Thanks. |
Also @LilyGO , I do not think the reset and power on are so important. Here is an even simpler sketch that demonstrates that enabling the battery in the if statement resets the board. Put an LED on, for example, pin 32 to debug the sketch and see what it is doing. // pins
#define BAT_EN 12
#define PWR_PIN 4
#define RESET 5
#define PIN_TX 26
#define PIN_RX 27
// put an LED on pin 32
#define LED_PIN 32
// enable battery
void enable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, HIGH);
}
// disable battery
void disable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, LOW);
}
RTC_DATA_ATTR int bootCount = 0;
int s_to_us_factor = 1000000;
void setup() {
// some delay
delay(3000);
// enable pin
pinMode(LED_PIN, OUTPUT);
// bootcount keeps increasing on usb power
bootCount++;
// flash the LED slowly, as many times as bootCount
for (int i=0; i<bootCount; i++) {
digitalWrite(LED_PIN, HIGH); delay(500);
digitalWrite(LED_PIN, LOW); delay(500);
}
// start modem every three boots
if (bootCount % 3 == 0) {
enable_battery_functions();
// some delay
delay(1000);
// this stuff never gets executed: you will never see the LED flashing quickly.
// Instead, after three flashes, you'll see one flash, because the esp
// has restarted, bootCount has been reset to zero and the code has produced
// one flash as instructed few lines above here
for (int i=0; i<10; i++) {
digitalWrite(LED_PIN, HIGH); delay(100);
digitalWrite(LED_PIN, LOW); delay(100);
}
// this also never gets executed
disable_battery_functions();
}
esp_sleep_enable_timer_wakeup(5 * s_to_us_factor); delay(200);
esp_deep_sleep_start();
}
void loop() {} You will never see four or more flashes - the board gets reset by |
Use battery power only. Everything goes according to plan #define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds / RTC_DATA_ATTR int bootCount = 0; #include "soc/soc.h"
#if TINY_GSM_POWERDOWN #endif
} } |
OK, some updates. Thanks @LilyGO for suggesting to turn off the brownout detector with Here is the final version of my example code, in case people need a similar application #define TINY_GSM_MODEM_SIM7600
#include <TinyGsmClient.h>
TinyGsm modem(Serial1);
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
// pins
#define BAT_EN 12
#define PWR_PIN 4
#define RESET 5
#define PIN_TX 26
#define PIN_RX 27
// access point - change to your sim operator
const char apn[] = "em";
const char gprsUser[] = "";
const char gprsPass[] = "";
// enable reading battery voltage and using battery power
void enable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, HIGH);
}
// disable battery
void disable_battery_functions() {
pinMode(BAT_EN, OUTPUT);
digitalWrite(BAT_EN, LOW);
}
// A7608 Reset
// see simcom-A7608 hardware design document
void modem_hw_reset() {
pinMode(RESET, OUTPUT);
digitalWrite(RESET, LOW); delay(100);
digitalWrite(RESET, HIGH); delay(1000);
digitalWrite(RESET, LOW);
}
// A7608 Power on
// see simcom-A7608 hardware design document
void modem_hw_poweron() {
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW); delay(100);
digitalWrite(PWR_PIN, HIGH); delay(1000); // this is Ton
digitalWrite(PWR_PIN, LOW); delay(15000); // wait for power on
}
RTC_DATA_ATTR int bootCount = 0;
int s_to_us_factor = 1000000;
void setup() {
// serial port - connect a second board to GPIO 3 and 1 to read output when on battery power
Serial2.begin(115200, SERIAL_8N1, GPIO_NUM_3, GPIO_NUM_1);
while (!Serial2) {}
// disable brownout detector
Serial2.println("Disabling detector ... ");
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
// some delay
delay(15000);
// bootcount
bootCount++;
Serial2.print("bootCount = "); Serial2.println(bootCount);
// start modem every three boots
if (bootCount % 3 == 0) {
// enable battery
Serial2.print("Enabling battery ... ");
enable_battery_functions();
// reset and power on modem
Serial2.println("Resetting modem ... ");
modem_hw_reset();
Serial2.println("Powering on modem ... ");
modem_hw_poweron();
// start serial communication with simcom module
Serial1.begin(115200, SERIAL_8N1, PIN_RX, PIN_TX);
while (!Serial1) {}
Serial2.print("Initializing modem ...");
if (modem.init()) {
Serial2.println(" done");
} else {
Serial2.println(" failed");
}
Serial2.print("Waiting for network ...");
if (modem.waitForNetwork()) {
Serial2.println(" done");
} else {
Serial2.println(" failed");
}
Serial2.print("Connecting to access point ...");
if (modem.gprsConnect(apn, gprsUser, gprsPass)) {
Serial2.println(" done");
} else {
Serial2.println(" failed");
}
delay(2000);
Serial2.println("Disconnecting GPRS ...");
modem.gprsDisconnect();
Serial2.println("Powering off modem ...");
modem.poweroff();
Serial2.println("Disable battery functions ... ");
disable_battery_functions();
}
Serial2.println("Going to sleep ... ");
esp_sleep_enable_timer_wakeup(5 * s_to_us_factor); delay(200);
esp_deep_sleep_start();
}
void loop() {}
|
Hi,
the simcom module is set to turn on automatically when the board wakes up from deep sleep. This is inconvenient, since I do not need the modem to turn on every time the board wakes up from sleep, as I only need the network every 10 or so cycles.
How can I make sure the simcom module remains off? Currently, I am shutting down the module manually in
setup()
using this codebut the 3 second delay is too long and the modules turns on before going off.
I wonder if keeping the
PWR_PIN
toLOW
all the time would achieve what I am after.Thanks
The text was updated successfully, but these errors were encountered: