Skip to content

Instantly share code, notes, and snippets.

@macchina
Created February 20, 2017 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macchina/82e82b2a1f9a7c01429ff22f79e1d803 to your computer and use it in GitHub Desktop.
Save macchina/82e82b2a1f9a7c01429ff22f79e1d803 to your computer and use it in GitHub Desktop.
// Demo program for testing DIGI cellular module.
// Looks for "Emergency flasher button was pressed" CAN message in 2006 Ford Fusion and sends text.
// Digi module needs to be set up to send SMS first for this sketch to work:
// http://www.digi.com/resources/documentation/digidocs/90001525/default.htm
// Specifically this example:
// http://www.digi.com/resources/documentation/digidocs/90001525/default.htm#tasks/t_send_sms.htm%3FTocPath%3DGetting%2520started%7CExamples%7C_____2
#include "variant.h"
#include <due_can.h>
#include "SamNonDuePin.h"
// DIGISTUFF //
const int DIGI_Associate_PIN = 48; // the number of the pushbutton pin
const int DIGI_RESET_PIN = X4;
const int GREEN_LED = 23; // the number of the LED pin
int AssociateState = 0; // variable for reading the pushbutton status
const int Yellow = X0; // the number of the LED pin
const int LOWPOW = PIN_EMAC_ERX0;
int flashers = 0; // flashers indicator varible
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 2000; // the debounce time; increase if the output flickers
int lastState = 0;
void setup()
{
Serial.begin(9600); // DIGI Cellular XBEE serial port
SerialUSB.begin(115200);
pinModeNonDue(LOWPOW, OUTPUT);
digitalWriteNonDue(LOWPOW, HIGH);
pinMode(28, OUTPUT);
digitalWrite(28, LOW);
Can1.begin(CAN_BPS_125K);
Can1.watchFor(0x0383);
pinMode(DIGI_Associate_PIN, INPUT);
pinMode(GREEN_LED, OUTPUT);
pinModeNonDue(DIGI_RESET_PIN, OUTPUT);
digitalWriteNonDue(DIGI_RESET_PIN, HIGH);
pinModeNonDue(Yellow, OUTPUT);
}
void loop() {
CAN_FRAME incoming;
static unsigned long lastTime = 0;
if (Can1.available() > 0) {
Can1.read(incoming);
if (incoming.data.low == 192) { //192 = C0 in dec
flashers = 1;
lastDebounceTime = millis();
digitalWriteNonDue(Yellow, LOW); // turn LED ON:
}
}
if ((millis() - lastDebounceTime) > debounceDelay) {
flashers = 0; // resets
digitalWriteNonDue(Yellow, HIGH); // turn LED ON:
}
if (flashers != lastState) { // if flasher variable is different
if (flashers == 1) {
Alert();
}
lastState = flashers;
}
AssociateState = digitalRead(DIGI_Associate_PIN);
if (AssociateState == HIGH) {
// turn LED on:
digitalWrite(GREEN_LED, HIGH);
} else {
// turn LED off:
digitalWrite(GREEN_LED, LOW);
}
}
void Alert()
{
SerialUSB.println("sending SMS");
Serial.println("Macchina M2 and Digi XBEE Cellular test 2/18/17");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment