Jia and Jason handled most of the fabrication, while I wrote most of the code to handle the GSM module's interaction with the Arduino. We used a software serial connection to communicate with the module, and used a series of basic commands to initiate the sending of an SMS message when one of the black symbols is squeezed by the user's fingers.
One of the key things to remember is to send the AT+CMGF=1 command anytime the GSM module has restarted. This command sets the module's SMS mode to text, allowing the subsequent command to send the message, AT+CMGS, to function properly. If you don't do this, you will be unable to send messages at all.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GSM Paper Fortune Teller | |
* Towers of Power - Spring 2015 - ITP/NYU | |
* Jason Dunne, Jiashan Wu, Abe Rubenstein | |
*/ | |
/* | |
* Includes portions of CapacitiveSense Library Demo Sketch | |
* Paul Badger 2008 | |
* Slightly adapted by Bare Conductive 2011 | |
* Uses a high value resistor e.g. 10 megohm between send pin and receive pin | |
* Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values. | |
* Receive pin is the sensor pin - try different amounts of Bare Paint | |
* Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet | |
*/ | |
#include <AltSoftSerial.h> | |
#include <CapacitiveSensor.h> | |
AltSoftSerial Gsm; // DOUT -> 8, DIN -> 9 | |
String AT_CMGF = "at+cmgf=1\n\r"; | |
String AT_CMGS = "at+cmgs=\"7752247691\", 129\n\r"; | |
String testMsg = "hello world!"; | |
String messages[] = { | |
"Patience is a virtue.", | |
"Happiness comes to those who wait.", | |
"Do not go gentle into that good night.", | |
"Nothing gold can stay.", | |
"A diamond is forever.", | |
"Built Ford Tough.", | |
"Just do it.", | |
"Will the real Slim Shady please stand up?" | |
}; | |
char delimiter = 0x1A; | |
char inChar = 0; | |
// 10MΩ resistor btw pins 12 and 13 | |
CapacitiveSensor cs_12_13 = CapacitiveSensor(12,13); // sensor = pin 13 | |
// 10MΩ resistor btw pins 10 and 11 | |
CapacitiveSensor cs_10_11 = CapacitiveSensor(10,11); // sensor = pin 11 | |
// 10MΩ resistor btw pins 4 and 2 | |
CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3); // sensor = pin 9 | |
CapacitiveSensor cs_6_7 = CapacitiveSensor(6,7); // sensor = pin 7 | |
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // sensor = pin 5 | |
CapacitiveSensor cs_14_15 = CapacitiveSensor(14,15); // sensor = pin 15 | |
CapacitiveSensor cs_16_17 = CapacitiveSensor(16,17); // sensor = pin 17 | |
CapacitiveSensor cs_18_19 = CapacitiveSensor(18,19); // sensor = pin 3 | |
CapacitiveSensor sensors[] = { | |
cs_12_13, | |
cs_10_11, | |
cs_2_3, | |
cs_6_7, | |
cs_4_5, | |
cs_14_15, | |
cs_16_17, | |
cs_18_19, | |
}; | |
long totals[] = {0, 0, 0, 0, 0, 0, 0, 0}; | |
void setup() { | |
for (int i = 0; i < 8; i++) { | |
sensors[i].set_CS_AutocaL_Millis(0xFFFFFFFF); // autocalibrate off | |
messages[i].concat(delimiter); | |
} | |
Serial.begin(9600); | |
Gsm.begin(115200); | |
delay(2000); | |
Gsm.print(AT_CMGF); | |
delay(2000); | |
} | |
void loop() { | |
for (int i = 0; i < 8; i++) { | |
totals[i] = sensors[i].capacitiveSensor(30); | |
if (totals[i] > 125) { | |
sendMessage(i); | |
break; | |
} | |
} | |
for (int i = 0; i < 8; i++) { | |
if (i < 7) { | |
Serial.print(totals[i]); | |
Serial.print(","); | |
} | |
else { | |
Serial.println(totals[i]); | |
} | |
} | |
if (Gsm.available()) { | |
inChar = Gsm.read(); | |
Serial.write(inChar); | |
delay(20); | |
} | |
if (Serial.available() > 0) { | |
Gsm.write(Serial.read()); | |
} | |
} | |
void sendMessage(int m) { | |
Gsm.print(AT_CMGS); | |
Serial.println("sent cmgs command"); | |
delay(1000); | |
Gsm.print(messages[m]); | |
Serial.println("sent msg body"); | |
delay(2000); | |
} | |
No comments:
Post a Comment
Speak now...