I'm using Arduino Micro 3.3V and via the TX and RX i can send data via serial monitor to my USB TTL via putty. My settings are 115200, 8,1,none, none,implicit CR in every LF on putty.
When I connect my USB TTL to SIM7020X it works. Sending AT gets a reply OK etc.
When I use Arduino Micro to send serial to SIM7020X i don't get a reply.
below is the code that i used.
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
char receivedChars1[numChars];
boolean newData = false;
boolean newData1 = false;
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
recvWithEndMarker();
recvSerial1();
showNewData();
showNewData1();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void recvSerial1() {
static byte ndx1 = 0;
char endMarker1 = '\r';
char rc1;
while (Serial1.available() > 0 && newData1 == false) {
rc1 = Serial1.read();
Serial.println(rc1);
if (rc1 != endMarker1) {
receivedChars1[ndx1] = rc1;
ndx1++;
if (ndx1 >= numChars) {
ndx1 = numChars - 1;
}
}
else {
receivedChars1[ndx1] = '\0'; // terminate the string
Serial.println(ndx1);
ndx1 = 0;
newData1 = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
if(receivedChars[0] == 0x41){
Serial1.write(0x41);//A
Serial1.write(0x54);//T
Serial1.write(0x0D);//CR
Serial1.write(0x0A);//LF
// Serial1.println('AT');//also doesn't work.
}else{
Serial1.write(receivedChars);
}
newData = false;
}
}
void showNewData1() {
if (newData1 == true) {
Serial.print("This from NB ... ");
Serial.println(receivedChars1);
newData1 = false;
}
}
I've tried with an Arduino micro 5v board and its also not working. I used a multimeter to measure the RX TX of the usb ttl it's 3.3v so I assume i would need a Arduino micro 3.3v board.
Please help. I've tried about everything i know.