Skip to content

Commit

Permalink
Merge pull request #5 from blemasle/features-optional-pins
Browse files Browse the repository at this point in the history
Reduce required pin count
  • Loading branch information
blemasle committed Feb 15, 2019
2 parents 19b5704 + 7125d00 commit f283818
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/blemasle/arduino-sim808.svg?branch=master)](https://travis-ci.org/blemasle/arduino-sim808)
[![License](https://img.shields.io/badge/license-MIT%20License-blue.svg)](http://doge.mit-license.org)

This library allows to access some of the features of the [SIM808](https://simcom.ee/documents/?dir=SIM808) GPS & GPRS module. It requires at least 3 pins (power, status and reset pins) to work and a TTL Serial.
This library allows to access some of the features of the [SIM808](https://simcom.ee/documents/?dir=SIM808) GPS & GPRS module. It requires only the `RESET` pin to work and a TTL Serial. `STATUS` pin can be wired to enhance the module power status detection, while wiring the `PWRKEY` adds the ability to turn the module on & off.

The library tries to reduces memory consumption as much as possible, but nonetheless use a 64 bytes buffer to communicate with the SIM808 module. When available, SIM808 responses are parsed to ensure that commands are correctly executed by the module. Commands timeouts are also set according to SIMCOM documentation.

Expand Down Expand Up @@ -46,17 +46,19 @@ It does *not* have the pretention to become the new SIM808 standard library, but

SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX)
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
// SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired

void setup() {
simSerial.begin(SIM808_BAUDRATE);
sim808.begin(simSerial);

sim808.powerOnOff(true); //power on the SIM808
sim808.powerOnOff(true); //power on the SIM808. Unavailable without the PWRKEY pin wired
sim808.init();
}

void loop() {
//whatever you need to do
// whatever you need to do
}
```
See examples for further usage.
Expand Down
2 changes: 1 addition & 1 deletion examples/Tester/Tester.ino
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void power() {
return;
}

Log.notice(S_F("%s : %S"), buffer, status ? TO_F(ON) : TO_F(OFF));
Log.notice(S_F("%s : %S" NL), buffer, status ? TO_F(ON) : TO_F(OFF));
}
else if(BUFFER_IS_P(ON)) {
readNext();
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SIM808
version=1.0.1
version=1.1.0
author=Bertrand Lemasle
maintainer=Bertrand Lemasle
sentence=Straightforward Arduino library for the SIM808
Expand Down
9 changes: 8 additions & 1 deletion src/SIM808.Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ TOKEN_TEXT(CFUN, "+CFUN");

bool SIM808::powered()
{
if(_statusPin == SIM808_UNAVAILABLE_PIN) {
sendAT();
return waitResponse(SIMCOMAT_DEFAULT_TIMEOUT) != -1;
}

return digitalRead(_statusPin) == HIGH;
}

bool SIM808::powerOnOff(bool power)
{
if (_pwrKeyPin == SIM808_UNAVAILABLE_PIN) return false;

bool currentlyPowered = powered();
if (currentlyPowered == power) return false;

SIM808_PRINT_P("powerOnOff: %t", power);

digitalWrite(_pwrKeyPin, LOW);
Expand Down
8 changes: 4 additions & 4 deletions src/SIM808.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

TOKEN(RDY);

SIM808::SIM808(uint8_t resetPin, uint8_t pwrKeyPin, uint8_t statusPin)
SIM808::SIM808(uint8_t resetPin, uint8_t pwrKeyPin = SIM808_UNAVAILABLE_PIN, uint8_t statusPin = SIM808_UNAVAILABLE_PIN)
{
_resetPin = resetPin;
_pwrKeyPin = pwrKeyPin;
_statusPin = statusPin;

pinMode(_resetPin, OUTPUT);
pinMode(_pwrKeyPin, OUTPUT);
pinMode(_statusPin, INPUT);
if(_pwrKeyPin != SIM808_UNAVAILABLE_PIN) pinMode(_pwrKeyPin, OUTPUT);
if (_statusPin != SIM808_UNAVAILABLE_PIN) pinMode(_statusPin, INPUT);

digitalWrite(_pwrKeyPin, HIGH);
if(_pwrKeyPin != SIM808_UNAVAILABLE_PIN) digitalWrite(_pwrKeyPin, HIGH);
digitalWrite(_resetPin, HIGH);
}

Expand Down
7 changes: 5 additions & 2 deletions src/SIM808.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#define HTTP_TIMEOUT 10000L
#define GPS_ACCURATE_FIX_MIN_SATELLITES 4
#define SIM808_UNAVAILABLE_PIN 255

class SIM808 : public SIMComAT
{
Expand Down Expand Up @@ -52,16 +53,18 @@ class SIM808 : public SIMComAT
bool setBearerSetting(ATConstStr parameter, const char* value);

public:
SIM808(uint8_t resetPin, uint8_t pwrKeyPin, uint8_t statusPin);
SIM808(uint8_t resetPin, uint8_t pwrKeyPin = SIM808_UNAVAILABLE_PIN, uint8_t statusPin = SIM808_UNAVAILABLE_PIN);
~SIM808();

/**
* Get a boolean indicating wether or not the device is currently powered on.
* The power state is read from either the statusPin if set, or from a test AT command response.
*/
bool powered();
/**
* Power on or off the device only if the requested state is different than the actual state.
* Returns true if the power state has been changed has a result of this call.
* Returns true if the power state has been changed as a result of this call.
* Unavailable and returns false in all cases if pwrKeyPin is not set.
*
* See powered()
*/
Expand Down

0 comments on commit f283818

Please sign in to comment.