Convert Arduino Code to Mbed code



I dont receive " the module is up! " In the terminal serie

Understand.
This borad is not Nucleo-F103RB, this is BluePhill ( Bluepill board support for Mbed OS 6 - Custom and community boards - Arm Mbed OS support forum) board and it changes the game a little bit.
The default Mbed console (STDIO) which is used for printf is set to PA_2 and PA_3. So, so you won’t see it until you connect a serial converter to those pins.

I am not sure, about the content in your terminal, but it seems like the comunication between BluePhill and A9G. The Bluephill sent the AT command and A9G responded with OK and that is correct.

BR, Jan

OK understood i decide to use the blue pill with ST-LINK because its seems like Nucleo
the second part i start to generate a library for A9G from the SIM808 library . i will share with you the library

<<library /users/kaoutharidrissi/code/A9G1/>>

<<repo /users/ngomez/code/fona_sim808/file/569bd647c835/fona_sim808.cpp/>>

You share only not complete links and your work is set as private in your repository probably.

Are you sure the Sim808 and A9G are so similar so you can use same library?
However for this old library you need downgrade MbedOS to version 5.15

BR, Jan

that’s the problem idon’t now if the sim808 is similar to A9G

I use this code with GSM LIBRARY but not works
#include “mbed.h”
#include

Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication
Serial GSM(PA_9, PA_10); //tx, rx SIM 900
string result;
char x;

void clearString()
{
result.clear();
}

void callback_rx() {

while (GSM.readable()) {
  x = GSM.getc();
  result += x;
pc.putc(x); // print the answer from SIM900

   }

}

void sendSMS()
{

clearString();
GSM.printf(“AT+CMGF=1\r”); //at command for send sms
wait_ms(1000);
clearString();
wait_ms(1000);
GSM.printf(“AT+CMGS=”);
GSM.putc(’"’);
GSM.printf("+212*********");
wait_ms(1000);
GSM.printf(“test1”);
wait_ms(1000);
GSM.putc(0x1A);
wait_ms(5000);
}

int main() {

pc.printf("\r\n GSM 900 TEST\n");
GSM.attach(&callback_rx);
GSM.baud(9600); //
wait_ms(100);

while(1) {

wait_ms(10);
sendSMS(); // SEND SMS
wait_ms(100);

}

}

Koki, the information

is not very specific.

However, I am already able to send SMS via A9G. You can found the code under same link what I shared few post above.

BR, Jan

ok please share with me the code

I already did it

BR, Jan

hello sir i think that the probleme comes when i use the blue pill not the nucleo lets help me to generate the same code with blue pill connecting to ST-Link

Hello,

what a problem?
You need to change pins in BufferedSerial constructor to yours - PD_5, PD_6D10, D2 and also phone number.
Of course if you don’t have a USB to Serial converter you will not see any output from printf functions, but program should run.

BR, Jan

i use the PA-9 , pA-10 even if i do this i cant send and receive messages
please send me the code that contain the part of send/receive Sms because the last code had just to send AT an receive OK in the serial monitor

#include “mbed.h”

BufferedSerial uart(D10,D2, 115200); // UART TX, RX
ATCmdParser module(&uart,"\r\n");

// setup
int main() {

printf("Mbed A9G test\n");
module.debug_on(true);
bool result = false;
for(int i=0;i<5;i++){
    module.send("AT");
    thread_sleep_for(500);
    result =  module.recv("OK");
    if(result){
        break;
    }
}
if(result){
    printf("Module is up!\n");  
} else {
    printf("No communication with module!\n");  
}

// loop
while(true)

module.send(“AT+CMGF=1”);
thread_sleep_for(1);
module.send(“AT+CSMP?”);

while (1){
 
 thread_sleep_for(2); 

module.send(" AT+CMGS=’+212611630851’> Hello Wrld <Ctrl+Z>");

result =  module.recv("OK");
if  (result)
{
    printf("\nATCmdParser: Message was sent successfully");
} else { 
    printf("\nATCmdParser: Message was not sent");        
}
thread_sleep_for(3);
    
}      

}

Pin masks D10, D2 (Arduino standart) are masks for pins PA_9, PA_10 that means same pins.
I wrote to you two times about I already shared the code with you. So please, be so kind and click on this link Mbed_A9G_test - Test | Mbed and open the main.cpp file.

BR, Jan

ok thanks but i have to put commands using serial monitor or send commands directlyto the module ?

You don’t put commands anywhere.
The code try to establish communication and is waiting for network connection. How the network registration will be done, then will try to send SMS with specific content, string Testerino in this case, to specific phone number (you have to change it).
If your wiring, pin settings, phone number are correct and SIM is not locked… SMS must arrive.

BR, Jan

I think that i have a problrm in serial communication because when ever i send for example AT+CMGF=1 i receive error in the terminal serie