Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple code snippet for talking to Serial devices - in this case a SIM7600E-H
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9);
void setup()
{
delay(500);
Serial.begin(115200);
mySerial.begin(115200); // use this line on a new module using 115200 baud by default
//mySerial.begin(19200); // after setting the baud rate to 19200, we use this speed for mySerial
pinMode(13, OUTPUT);
delay(1000);
}
int counter = 0;
void loop()
{
/* send everything received from the hardware uart to usb serial & vv */
if (Serial.available() > 0) {
Serial.print(">");
delay(100);
while ( Serial.available() ) {
char ch = Serial.read();
Serial.print(ch);
mySerial.print(ch);
}
}
if (mySerial.available() > 0) {
Serial.print(":");
delay(10);
while ( mySerial.available() ) {
digitalWrite(13, HIGH);
char ch = mySerial.read();
if ( ch ) {
Serial.print(ch);
}
}
} else {
digitalWrite(13, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment