Writing to Arduino's serial monitor box - arduino

I'm trying to send SMS using GPRS attached to Arduino.
I have this code:
// send an SMS!
char sendto[21], message[141];
flushSerial();
Serial.print(F("Send to #"));
readline(sendto, 20);
Serial.println(sendto);
Serial.print(F("Type out one-line message (140 char): "));
readline(message, 140);
Serial.println(message);
if (!fona.sendSMS(sendto, message)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
I tried to send, and it is working perfect, but I have to use the serial monitor box to enter the number and the message, and the library is using only this method. I want the code to run by itself without entering anything in the box.
Is there is any way so I can do that? I mean something like writing automatically to the box from the code.
Thank you in advance!
Best regards,

Take out the parts of the code that read the line from the Serial monitor and replace with lines of code that either have the data it needs hard-coded or has some other way to get that data. You really haven't shown enough of the code to help you figure out how to do that.

Related

Sim800L lag/delay before incoming calls are visible to arduino

I use SIM800L GSM module to detect incoming calls and generally it works fine. The only problem is that sometimes it takes up to 8 RINGS before the GSM module tells arduino that someone is calling (before RING appears on the serial connection). It looks like a GSM Network congestion but I do not have such issues with normal calls (I mean calls between people). It happens to often - so it cannot be network/Provider overload. Does anybody else had such a problem?
ISP/Provider: Plus GSM in Poland
I don't put any code, because the problem is in different layer I think
sorry that I didn't answer earlier. I've tested it and it turned out that in bare minimum code it worked OK! I mean, I can see 'RING' on the serial monitor immediately after dialing the number. So it's not a hardware issue!
//bare minimum code:
void loop() {
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
In my real code I need to compare calling number with the trusted list. To do that I saved all trusted numbers in the contact list on the sim card (with the common prefix name 'mytrusted'). So, in the main loop there's if statement:
while(mySerial.available()){
incomingByte = mySerial.read();
inputString += incomingByte;
}
if (inputString.indexOf("mytrusted") > 0){
isTrusted = 1;
Serial.println("A TRUSTED NUMBER IS CALLING");
}
After adding this "if condition" Arduino sometimes recognize trusted number after 1'st call, and sometimes after 4'th or 5'th. I'm not suspecting the if statement itself , but the preceding while loop, where incoming bytes are combined into one string.
Any ideas, what can be improved in this simply code?
It seems, I found workaround for my problem. I just send a simple 'AT' command every 20 seconds to SIM800L (it replies with 'OK' ). I use timer to count this 20 seconds interval (instead of simply delay function)
TimerObject *timer2 = new TimerObject(20000); //AT command interval
....
timer2->setOnTimer(&SendATCMD);
....
void SendATCMD () {
mySerial.println("AT");
timer2->Stop();
timer2->Start();
}
With this simple modification Arduino always sees incoming call immediately (after 1 ring)

Print line in serial monitor of Arduino

I got a very simple code to run on Arduino. The problem is that when I run the code and open the Serial Monitor then first it shows "Ple" and then adds "Please enter inputs:" which at the end I get "PlePlease enter inputs:"
How can I get rid of the "Ple" or make Serial Monitor not to print before I open it.
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Please enter inputs:\n");
while(true);
}
Try to open the serial monitor with the shortcut (ctrl+shift+m). It triggers the reset and restarts your program. I don't know why this happens only using the shortcut.
Hope this helps.
it's the same for my latest work... in this case it seems that low baudrate could be the problem.
try to bring the baudrate up to 115200 (don't forget to change it also in the down right corner of serial monitor).
Just to be sure, put a small delay (500ms) just before the Serial Print command. Hope this could be useful also for you!
Ciao.

SMS is truncated when I read it from Siemens TC35 GSM module and Arduino

I'm doing some experiments with Arduino+Siemens TC35 GSM module and I would like to be able to read an SMS that I send to this device.
I have assembled my device following more or less this scheme:
with the difference that I don't use a buzzer nor a relay, just an LCD display. You can see the full picture here:
The scheme should work, because for example I have been able to send an SMS from Arduino to my mobile phone, but I'm having some problems parsing the SMS I send to my Arduino.
(note: I will hide my number substituting some numbers with ***)
I initialize the GSM module like this:
mySerial.print("AT+CMGF=1\r\n");
and I try to read my SMS like this:
void readSMS()
{
mySerial.print("AT+CMGR=6\r\n");
delay(1000);
char c;
while (mySerial.available()>0){
c = (char)mySerial.read();
Serial.print(c);
}
}
but I always get a truncated SMS. This is what I see in my Serial monitor:
AT+CMGF=1
OK
AT+CMGR=6
+CMGR: "REC READ","AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
what's wrong with my code?
Thank you so much for any help.
p.s: also other commands that are supposed to work (for example the one to delete all SMS: AT+CMGD=1,4) don't work at all and give me error.
p.p.s: I wish I could use the GSM.h library that is available for Arduino, but I guess it's only compatible with the original Arduino GSM Shield.
I'm not an Arduino expert in any capacity, so there may be better ways to do this in the API, but I'd try something like this (delays can probably be lowered)
void readSMS()
{
mySerial.print("AT+CMGR=6\r\n"); // Send request
int count = 5; // Number of 100ms intervals before
// assuming there is no more data
while(count-- != 0) { // Loop until count = 0
delay(100); // Delay 100ms
while (mySerial.available() > 0){ // If there is data, read it and reset
c = (char)mySerial.read(); // the counter, otherwise go try again
Serial.print(c);
count = 5;
}
}
}
Another - probably better - option would be to just loop without a delay until you get a complete answer. That of course assumes that you know what to look for (<cr><lf>OK<cr><lf> would seem to be the case here, but I'm too weak on the Hayes spec to be sure)

Arduino Serial Communication not receiving entire message

I have a problem with the Arduino communication. It's quite hard to describe so I cant fit it in the title. Anyway here are the following:
So I have this code for my receiving end:
if(Serial1.available())
{
while(Serial1.available())
{
uint8_t inByte = Serial1.read();
inByte = inByte ^ k;
Serial.write(inByte);
}
Serial.println(" done");
}
It's supposed to print in one line and print done when it's done. The Serial1.available() seems to skip the next Serial1.available(), I don't know what's going on. Anyway here's my current, bad, output:
h done
e done
l done
l done
o done
done
when it should be:
hello done
I'm sorry if this could've been phrased better but that's all I can type now, my brain is kinda in pain. I've never experienced this behavior in a Windows c++ console application.
If you are calling that routine in loop() then yes, it will read from the serial buffer and immediately return since you are probably not sending the data fast enough.
A better way to handle this sort of thing is to use a control char which indicates the end of a message OR if you have a specific data format you expect to receive, then keep a count of the chars which have come in until the data format limit is reached.
There is discussion here which you may find useful: Serial Duplex using Arduino Also there are example sketches that ship with the Arduino IDE: Menu: Examples: Communication:
Also, read all the entries under the Serial listing for Arduino. Good stuff there.
So the routine you develop for working with Serial input really depends on your project and the kind of data you are receiving. In your example above, if you were to use a control char, it might look like this:
while(Serial1.available()){
char c = Serial1.read();
if (c == '*'){
Serial.println(" done");
} else {
Serial.write(c);
}
}

Strange initial output using Serial.print

When I'm writing to the serial interface, I'm getting strange and unexpected output when my sketches first run. The output seems to be a variant of what should be printed:
eg:
String text1 = "foobar";
void setup() {
Serial.begin(9600);
Serial.print("\n");
Serial.print(text1);
}
void loop() {
}
Results in the output:
fo
foobar
(the new line appears before "fo" but I couldn't work out how to include it).
So some variant of whatever is supposed to be printed, gets printed before the actual text that is supposed to be printed. Changing the output, changes the anomalous text (sometimes it'll be two characters, sometimes three). Making changes that don't affect the output and recompiling has no effect on the anomalous text.
I'm a total Arduino newbie (I only started writing my own code today), but I can only assume this isn't normal.
I'm using a Freetronics EtherTen and the 1.0 IDE
thanks in advance
Arduino is restarting your sketch when you open its serial port on the computer.
so it prints out, and then initialized again.
after
Serial.begin(9600);
try to put either:
delay(500)
or
while (!Serial); // while the serial stream is not open, do nothing:
This is most likely a Serial communication Reset issue as Eran W pointed out. See my previous answer here.
The Arduino automatically resets when it receives serial communication from most things other than the Arduino IDE. This is why you can send from the IDE but not anything else.
I have an Uno and put a capacitor between Reset and Ground.Here's a page with some good info on the subject.
Good luck. http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
You should probably terminate your string with a 0.
Like:
String text1 = "foobar",0;

Resources