Hi everyone, I bought a sim800l module a while ago and I wanted to send characters in Hebrew, yet when I tried to send it as it is in the sim800l example (taken from the sim800l library : GitHub - cristiansteib/Sim800l: Library sim800l for Arduino UNO (maybe sim900l work) ) on the receiver side I only got blank characters or question marks as if the message wasn't sent as needed (as far as I think)
I tried looking on the internet why it doesn't work and I came up with a thing called UCS2 which is the UTF-16 encoding, but I tried looking on how to enable it on the sim800l (if even possible) and I was unable to find it, if someone can help I would really appreciate this.
Thank you very much.
Although it was a painful thread, have a look at that discussion (ignore the frustration :)) )
I tried understanding what is being explained there, didn't get much logic into it, I was looking into the AT commands for the sim800l and I saw that you can set a command called "AT+CSCS ="UCS2" which did respond to me when I set that up, but from there, is there a possible chance of sending the sms through the AT command list, I also saw that you can send an sms through "AT+CMGS = "(Phone number here)"" and then typing the message you need, but does that send a UCS2 format message through the serial properly?
Say I use the example given in the sim800l library for sending an sms and I want to send the word "שלום" and the decimal line for that is : "642981500643091501", how can I automatically set it up for putting the CSCS mode into UCS2, and possibly use this code:
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
void setup(){
Sim800l.begin(); // initializate the library.
(set this line of code for setting the module up into UCS2 mode I think?)
Sim800l.sendSms("Phone number here","Text message here") //as far as I think the "Text message here" should just be replaced by the decimal number for the hebrew word
}
void loop(){
//do nothing
}
Have you tried what is explained in post #37 to the thread referenced above?
Oh yeah, now I saw it, Well, I used the code that I already had to communicate with the sim800l via AT commands:
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 8
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
int R = 0;
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
But in order to finalize sending the sms I need to use the Ctrl+Z there, I tried editing the code above to use it kinda like you did in your code (I am running it through arduino UNO instead of a MEGA) and it pretty much didn't work..
Not really sure on how to add the Ctrl+Z functionality because when I tried adding an int r in the loop and writing the function:
if((r == '#') & (Serial.available())){
serialSIM800.write(CtrlZ);
}
of course after adding a function with a const byte CtrlZ = 0x1A before the main program...
It didn't work...
Why don’t you use my code which sends the ctrlZ? And just defining gsm
to be the software serial instance?
Man I am a damn idiot lmao, why didn't I think about it before, I was trying to understand why it didn't work the whole day when the answer was literally in front of me just in a different name...
Well, I guess I'll just do it in the morning because it's 2AM now and I am too tired to even use any bit of my brain usefully, I guess we can call it a ggwp.
I'll update this thread if it worked for me or not, if it did I'll put up the code for an UNO configuration, and if not, well... good luck for us I guess.
Update: it works through the serial monitor now, BUT I do need it to work in an automated way, so is it possible to just use a command such as:
gsm.write("AT+CSCS="UCS2"");
Just as an example for the rest, if it is capable working like that, can I just reuse the whole protocol but automate it through the gsm.write commands?
once you understand how things work manually then you can indeed just send the right commands
Say I am using a function to automatically send one work as a reaction to something happening:
void Send1(){
gsm.write("ATZ");
gsm.write("AT+CSCS="UCS2"");
gsm.write("AT+CSMP=17,168,0,8");
gsm.write("AT+CMGF=1");
gsm.write("AT+CMGS="(phone number here in HEX)"");
Serial.write("Message in HEX");
Serial.write("#");
}
The way you blast these commands (which takes time to execute by the modem) will likely lead to an error
if you are lazy, just add delays in between the commands. if you want to do things right, you need to listen back to what the GPRS modem tells you until you see the "OK" or whatever it tells you when the command has been executed correctly
And you don't want to do
Serial.write("#");
to terminate the SMS, that was my hack to be able to send ctrl-Z
by using the console. You need to send ctrl-Z
to the modem with a gsm.write(0x1A); // 0x1A is ctrl-Z code
in the same way you don't want to send your SMS to the console
Serial.write("Message in HEX");
but to the GSM....
Well, I did try sending an sms through the main code, doesn't really work, I did go with the lazy way tho but I am unsure if the delay is just too small or is something wrong with it in general...?
#include<SoftwareSerial.h>
#define SIM800_TX_PIN 8
#define SIM800_RX_PIN 7
SoftwareSerial gsm(SIM800_TX_PIN,SIM800_RX_PIN);
const byte ctrlZ = 0x1A;
void setup() {
Serial.begin(9600);
gsm.begin(9600);
Test();
}
void loop() {
int r;
while (Serial.available()) {
r = Serial.read();
if ((r != -1) & (r != '#')) gsm.write((char) r);
if (r == '#') {
gsm.write(ctrlZ);
}
}
while (gsm.available()) {
r = gsm.read();
if (r != -1) {
if ((r >= ' ') && (r <= 127)) Serial.write((char) r);
if (r == '\n') Serial.println();
}
}
}
void Test(){
gsm.write("ATZ");
delay(2000);
gsm.write("AT+CSCS=\"UCS2\"");
delay(2000);
gsm.write("AT+CSMP=17,168,0,8");
delay(2000);
gsm.write("AT+CMGF=1");
delay(2000);
gsm.write("AT+CMGS=\"Phone number\"");
delay(2000);
gsm.write("05D705E105E8002005E005D905D905E8002005D805D505D005DC05D8002005E905D905E805D505EA05D9002005D105E005D505EA002005E705D505DE05D4002005D0");
delay(2000);
gsm.write(0xA1);
}
I did get some kind of a response from the serial monitor, it has basically spat all these commands back at me so I am quite unsure of why and how to fix it really
I’m unsure of your modem, you might have to send ‘\r\n’ (carriage return and line feed) at the end of each command to get them executed
You can do that either with adding them manually in the command line gsm.write("ATZ\r\n");
or by using the println()
command like this gsm.println("ATZ");
since you are sending ascii codes anyway
Do that for commands, of course not for the sms text unless you want to embed those characters in the message as well
You might want to press ctrl-T in the IDE editor to indent your code properly - all those curly braces in the wrong place are messy and messy code turns buggy quickly
Yes, the problem has been fixed and it now works perfectly automated, I will upload the code I was using here once I have access to my laptop once again.
Good!