Last active
July 24, 2020 21:24
-
-
Save jenschr/09c99641651a0208d7e8303ff4e356e1 to your computer and use it in GitHub Desktop.
Simple code snippet for talking to Serial devices - in this case a SIM7600E-H
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
#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