Arduino + GPRS m95 not responding - arduino

Im trying to communicate with a Quectel M95 GSM module but im just receiving squares as a response. The module is supposed to auto baud but it seems that it is not working.
The code that im using i took it from David Barnes question:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(rxPin,txPin); // RX, TX
void setup(){
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
Serial.println("Arduino serial initialized!");
delay(10);
mySerial.begin(9600);
Serial.println("Software serial initialized!");
delay(10);
}
void loop(){
issueCommand("AT");
readSerial();
delay(3*1000);
while(true){
readSerial();
}
}
void issueCommand(char* msg){
mySerial.println(msg);
Serial.print(msg);
delay(10);
}
void readSerial(){
while (mySerial.available()){
Serial.write(mySerial.read());
delay(10);
}
}
Im getting the following as an answer from the GSM:
What can it be? I have tried everything :/ Even if i try it using Windows Hyperterminal i dont recieve anything.
Thanks a lot.

Can you please try the same code by switching RX and TX values. I tried your sample and it worked successfully. Maybe you connected RX TX pins wrong.

Related

Sending data from Arduino UNO to NodeMCU over UART and processing received data on NodeMCU

I'm trying to send data from Arduino UNO to NodeMCU via UART.
What I want to do is that when Arduino UNO sends "on" String to the NodeMCU, NodeMCU lights up its builtin LED, when "off" - it turns off.
I send data from Arduino UNO via standard Serial.println (). On the NodeMCU I use the SoftwareSerial library. I assigned rx and tx to pins D7 and D8 accordingly. Serial ports on Arduino(standard) and NodeMCU(SoftwareSerial) are set at 9600 baud rate.
Standard Serial port (USB) of NodeMCU is set to 115200.
I send the string that I receive from the Arduino to the standard serial port of the node (connected to usb)
The question is:
On the standard port of NodeMCU, which I view through the Arduino IDE, messages coming from the arduino are displayed, and displayed correctly (those that were sent), but the NodeMCU does not want to accept them in conditional statements and light up my LED. Why?
At the same time, when I remap the virtual UART to its original pins (connected to USB, GPIO3 and GPIO1, and send the same messages via usb through the COM port view in the Arduino IDE, the LED turns on and off as I programmed it.
Do you have any ideas why this is happening?
By the way, I do not lower voltage coming from Arduino RX and TX pins from 5V to 3.3V, but since messages are recived coorectly, I don't think that this is causing a problem.
Here's my code:
Arduino:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("on");
delay(1000);
Serial.println("off");
delay(1000);
}
NodeMCU:
#include <SoftwareSerial.h>
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
Serial.println(str);
if(str == "on"){
digitalWrite(D4, HIGH);
}
if(str=="off"){
digitalWrite(D4, LOW);
}
}
Screenshot of COM4:
Screenshot of COM4:
UPD: I tried using sending 1 or 0 as int value via Serial.write() and s.read() and it works, maybe the prolem is in String type somehow
You Use İt Maybe Work
#include <SoftwareSerial.h>
String text = "";
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
text = str
Serial.println(text);
if(text == "on"){
digitalWrite(D4, HIGH);
}
if(text =="off"){
digitalWrite(D4, LOW);
}
}

NMEA statements appears infinitely in sim808

when I upload the code on arduino mega with sim808 bk-808-v3.1 , I reach the following output on the serial monitor. A NMEA statements appears infinitely. what is the problem and how to solve it?
Note that i connect SMS antenna and GPS antenna with sim808
the code
#include <SoftwareSerial.h>
SoftwareSerial SIM808(10,11); //(RX-Pin,TX-Pin)
void setup() {
Serial.begin(9600);
SIM808.begin(9600);
}
void loop() {
if (SIM808.available())
Serial.write(SIM808.read());
if (Serial.available())
SIM808.write(Serial.read());
}
I actually don't know about SIM808. But the GPS module seems to properly outputing NMEA packets every seconds by reading the GPGGA packet.
If the problem is that messages are printed out too slowly, try using Serial.readStringUntil('\n') and Serial.print functions instead of Serial.read() and Serial.write() functions.
#include <SoftwareSerial.h>
SoftwareSerial SIM808(10,11); //(RX-Pin,TX-Pin)
void setup() {
Serial.begin(9600);
SIM808.begin(9600);
}
void loop() {
if (SIM808.available())
Serial.print(SIM808.readStringUntil('\n'));
if (Serial.available())
SIM808.print(Serial.readStringUntil('\n'));
}

Arduino Mega and RS485 Modbus Sensor

I'm trying to connect a soil sensor using RS485 communication to arduino mega and I can't get it to work. I'm using the SparkFun RS485 breakout: https://www.sparkfun.com/products/10124
I've connected TX to pin 18, RS to pin 19 and RTS to pin 8.
I've tried to adapt the code from here: https://www.youtube.com/watch?v=tBw15SfmuwI using the sensor's manufacturers default setting:
Modbus address fixed to 0
The communication configuration is 9600,N,8,1(9600bps, no check bit, 8 data bits,
1 stop bit)
Communication protocol is Modbus-RTU
While the addresses I need to read are 0x0000-0x0002.
However, I get random characters as output when I open the serial monitor "?", any idea why? I'd appreciate any help reading the sensor's output.
This is the code I've used:
#include <ModbusMaster.h>
#define MAX485_DE 8
#define MAX485_RE_NEG 8
ModbusMaster node;
void preTransmission () {
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission () {
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup() {
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
node.begin(0,Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop() {
uint8_t resultMain;
resultMain = node.readInputRegisters(0x0000, 3);
if (resultMain == node.ku8MBSuccess) {
Serial.println("-------");
Serial.print("Temp: ");
Serial.println(node.getResponseBuffer(0x00) /100);
Serial.print("VWC: ");
Serial.println(node.getResponseBuffer(0x01) /100);
Serial.print("EC: ");
Serial.println(node.getResponseBuffer(0x02) /100);
}
}
The arduino mega has 3 serial ports:
Serial
Serial1
Serial2
You could think of it as Serial as Serial0 (the zero is never written). This port is hardwired to the USB port on the arduino mega.
Your RS485 breakout board is connected to Serial1. You may notice the screenprinting on the mega next to pins 18 and 19 says TX1 and RX1.
So when you initialize your node at this line:
node.begin(0,Serial);
you should pass it Serial1 instead of Serial
eg
node.begin(0,Serial1);

Serial Communication is not working properly in Arduino connection with HC-05

I am new to Arduino Programming.
This code works fine. It gives the correct output and functioning well. But I wanted to write the commands automatically without typing repeatedly.
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(38400);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop()
{
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
if(Serial.available()){
BTSerial.write(Serial.read());
}
}
So i tried doing the following change in the above code but i could not receive any response.
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(38400);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
BTSerial.write("AT");
}
void loop()
{
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
}
I also tried BTSerial.print("AT"); But still no response.
AT commands are case sensitive and should end up with a terminator like an enter keystroke or a \r\n.
This should do:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(38400);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
BTSerial.write("AT\r\n");
}
void loop()
{
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
}

Arduino SoftwareSerial Rx/Tx pin order error?

I'm writing code to run on an ATtiny being programmed by an Arduino as ISP. The ATtiny is to send AT commands over serial link to an RN42 Bluetooth module.
Since the ATtiny has no UART I'm using SoftwareSerial on pins 0 and 1. It seemed logical to put Tx on the "Data Out"/MISO pin and Rx on the "Data In"/MOSI pin. The documentation says to declare this like SoftwareSerial mySerial(Rx, Tx); but I found it only works if you declare it the other way round like SoftwareSerial mySerial(Tx, Rx);
I've taken a screenshot of my code and the pinout, I feel like I'm missing something but when I do it like this it works and makes the Bluetooth module enter command mode. Is the documentation the wrong way round?
Code and Pinout
I realised the error of my ways, I was unnecessarily setting the pinMode of the Rx and Tx pins. This threw me off as I thought setting the Rx pin to OUTPUT wouldn't work when actually it does, so I was outputting data on my Rx line and receiving it on the Tx line! The answer is to not assign direction and just let SoftwareSerial handle the pins. Pass the parameters in the order (Rx, Tx).
Here is my cleaner code that is working much better:
#include <SoftwareSerial.h>
const int Rx = 0; // pin 5 on ATtiny - DI/MOSI
const int Tx = 1; // pin 6 on ATtiny - DO/MISO
const int ButtonIn = 2;
const int OK_LED = 4;
int buttonState = 0;
SoftwareSerial serialBT(Rx, Tx);
void setup()
{
pinMode(ButtonIn, INPUT);
pinMode(OK_LED, OUTPUT);
serialBT.begin(9600);
}
void loop()
{
buttonState = digitalRead(ButtonIn);
if (buttonState == 0)
{
serialBT.print("$"); // $$$ enters RN42 command mode
serialBT.print("$");
serialBT.print("$");
delay(3000);
serialBT.println("R,1");
digitalWrite(OK_LED, HIGH);
delay(5000);
digitalWrite(OK_LED, LOW);
}
}

Resources