Main Site Documentation

Build a cellular radio project


#1

Dear all

I am beginner of gadgeteer without any electronics and C# experience. i want to build a cellular project. And i have G120Hdr with board with version and SIM900 cellular radio module.
I check your previous posts to help others to build a CAN interface. And i download 4.2 version G120HDR module.
I try to connect the cellular radio module to the G120HDR.
I check the pins and the socket of the cellular radio. I show it in the picture.
I think i should connect :
pin 4 - 18, P 2.0
pin 5 - 12, P0.16
pin 6 - 17, P0.6
pin7 - 15, p0.17

cause i am the first time do this, i want seek a confirmation from all of you. And i also don’t know which pin should connected with pin 1,pin2,and pin3.

I follow another post shown, open the project G120Hdr_42 which update by @ MikeCormier and edit its socket code, then add it as a reference in my solution, But i still can’t connect the cellular radio to the main board in VS. What should i do for this ?
All suggestion are welcome !!! thank you all


#2

There is no Socket K on G120HDR. You will need something like this:

https://www.ghielectronics.com/catalog/product/405

to “create” an extra Socket(s) of type K. Then you need to modify G120HDR Gadgeteer solution to define that socket in code. Then you need to modify socket definition in xml file so it will “appear” on the image. Only then you will be able to connect it in the designer.

I would try to avoid that and try to instantiate socket instance in the program directly (without the designer) and use it with the module driver. You will still need the physical socket or splice the Gadgeteer cable and connect it to corresponding pads/pins on G120HDR board.


#3

@ Architect -
sorry, i don’t understand well. what is the difference between the socket 4, 6 on the G120HDR and the break out module you suggest me. I can’t do it like my picture shows? Just connect the socket pins to the CUP pins ?
And i also found i can change the socket property directly in the designer. Set socket 6 to use K , and it seems like connected. But i am not sure it will work…


#4

@ 19891003 - G120HDR is not a gadgeteer board. You can use it with pure netmf code. The sockets are there to make an easy way for connecting things but you will need to add the necessary code.


#5

Adding on, I think the best way for a beginner to not use the extra provided sockets.

I will discuss with the team in how we can make this easier and clearer.


#6

@ Gus -
Yes, i know it can work with pure netmf codes. But i have no experience in C# language. Actually i am a automotive engineering student.
ok , you mean, i’d better buy some new extra provided sockets . and connect this socket pins to the CPU pins as the same as i said P4 - P2.0, P5-P0.16…etc ?

But there is a very inconvenient thing, if i want to purchase some new device, i must apply to my prof, and my prof ask the school…and the italian works with poor efficiency…So, can i directly use the socket 4 or 6 on the board even need some additional code ?


#7

Oh, yeah! I forgot that G120HDR has configurable Socket 4 which you can make anything you want. Yes, in addition to pins you have mentioned you will need to connect VCC, 5V, GND and for the Pin 3 use any interrupt capable IO on G120HDR.


#8

@ Architect -
OK, really thank you !!
and i am still not sure for pin3 . forgive my poor English.
It shows
Pin3 - PWRKEY (it means powerkey?)
I can’t find PWRKEY in the figure 2 , i don’t clear which pins should be connected with pin3 ?


#9

Pin 3 can be any digital output pin from MCU. The driver code will use that pin to turn on/off the module. It is power key on the module but it is any digital IO pin on the MCU.


#10

@ Architect -
to be honest… i can’t understand very well :wall: :wall: :wall:
in my understand, you said it can be any input/output from the mainboard . So i can connect it simply with the GND pin or 5V, then i must use some corresponding code tell the board, it should control the module through GND pin or 5V pin.
sorry, i can only explain this by untechnical word.


#11

VCC or 5V and GND are like power plug on your toaster. Pin 3 is the power button that turn the toaster ON/OFF


#12

@ Architect -
Thank you!!! I finished the physical connection. I will buy a SIM card tomorrow and try if it works.
Thank you again!!!


#13

@ Architect -
HI, i try to connect the pins as the same i said.
And i use the download project of G120HDR, then i change the socket 4 pin code and i also download a driver of cellular module.
But when i run it try to send a message to my cellphone ,it shows me that error, and i can not receive any message.

this is the code of my download, i just add the number"3272843093" and the test message

 #region SMS

        /// <summary>
        /// SMS Text Message
        /// </summary>
        public class Sms
        {
            /// <summary>
            /// Number
            /// </summary>
            public string TelephoneNumber;
            /// <summary>
            /// Message content
            /// </summary>
            public string TextMessage;
            /// <summary>
            /// Status of the message
            /// </summary>
            public SmsState Status;
            /// <summary>
            /// Date and time when the message was sent or received
            /// </summary>
            public DateTime Timestamp;
            /// <summary>
            /// Index of the message in the SIM card's memory
            /// </summary>
            public int Index
            {
                get
                {
                    return index;
                }
                internal set
                {
                    index = value;
                }
            }
            private int index;
            /// <summary>
            /// Instantiates a new SMS with empty number, and content, marks it as unsent and with the current time as the timestamp.
            /// </summary>
            public Sms()
            {
                TelephoneNumber = "";
                TextMessage = "";
                Status = SmsState.StoredUnsent;
                Timestamp = DateTime.Now;
                Index = -1;
            }

            /// <summary>
            /// Instantiates a new SMS message with the given parameters.
            /// </summary>
            /// <param name="number">Number</param>
            /// <param name="text">Message content</param>
            /// <param name="state">Status</param>
            /// <param name="timestamp">Timestamp</param>
            public Sms(string number, string text, SmsState state, DateTime timestamp)
            {
                this.TelephoneNumber = number;
                this.TextMessage = text;
                this.Status = state;
                this.Timestamp = timestamp;
            }

            private Sms(string number, string text, SmsState state, DateTime timestamp, int index)
            {
                this.TelephoneNumber = number;
                this.TextMessage = text;
                this.Status = state;
                this.Timestamp = timestamp;
                this.Index = index;
            }

        }

        /// <summary>
        /// Send an SMS text message
        /// </summary>
        /// <param name="number">3272843093</param>
        /// <param name="message">Body of the message</param>
        /// <returns></returns>
        public ReturnedState SendSms(string number, string message)
        {
            // Check if module is on
            if (!isPowerOn) return ReturnedState.ModuleIsOff;

            // Check if serial line is open
            if (serialLine.IsOpen)
            {
                //Check if module is busy
                if (isModuleBusy) return ReturnedState.ModuleBusy;
                isModuleBusy = true;

                serialLine.Write("AT+CMGS=\"+" + number + "\"\r\n");
                Thread.Sleep(100);
                serialLine.Write(message);
                Thread.Sleep(100);
                serialLine.Write((char)26 + "\r");
                //semaphore = true;
                //while (semaphore) Thread.Sleep(10);
                return ReturnedState.OK;
            }
            else return ReturnedState.Error;
        }

        /// <summary>
        /// Requests to read the SMS message in the specified position. Message is returned in the <see cref="SmsRetrieved"/> event.
        /// </summary>
        /// <param name="position">Position in memory where the message is stored</param>
        /// <param name="markAsRead">Whether unread messages will be marked as read</param>
        /// <returns></returns>
        public ReturnedState RetrieveSms(int position, bool markAsRead)
        {
            if (isModuleBusy) return ReturnedState.ModuleBusy;
            requestedMessages.Enqueue(position);
            if (markAsRead)
                return SendATCommand("AT+CMGR=" + position + ",0");
            else
                return SendATCommand("AT+CMGR=" + position + ",1");
        }

        /// <summary>
        /// Delete an SMS message
        /// </summary>
        /// <param name="position">Position in memory where the message is stored</param>
        public ReturnedState DeleteSms(int position)
        {
            return SendATCommand("AT+CMGD=" + position);
        }

        /// <summary>
        /// Requests to get all SMS in a given state or all of them.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public ReturnedState RetrieveSmsList(SmsState state)
        {
            switch (state)
            {
                case SmsState.All:
                    return SendATCommand("AT+CMGL=\"ALL\"");
                case SmsState.ReceivedRead:
                    return SendATCommand("AT+CMGL=\"REC READ\"");
                case SmsState.ReceivedUnread:
                    return SendATCommand("AT+CMGL=\"REC UNREAD\"");
                case SmsState.StoredSent:
                    return SendATCommand("AT+CMGL=\"STO SENT\"");
                case SmsState.StoredUnsent:
                    return SendATCommand("AT+CMGL=\"STO UNSENT\"");
                default:
                    return ReturnedState.InvalidCommand;
            }

        }

        /// <summary>
        /// Deletes all SMS messages stored in the SIM card
        /// </summary>
        /// <returns></returns>
        public ReturnedState DeleteAllSms()
        {
            return SendATCommand("AT+CMGD=0,4");
        }

        #endregion

#14

@ andre.m -
sorry, i don’t have any C# experience.
And i define this follow the example.
physically i connect pin 3 with 5V ,cause pin3 means powerkey
Then the example shows number 1,2 and 10 are 3.3V , 5V and GND. So i write the code like this.
I don’t know what is the correct definition of pin 3

#region Example Sockets

            // For each socket on the mainboard, create, configure and register a Socket object with Gadgeteer.dll
            // This specifies:
            // - the SupportedTypes character array matching the list on the mainboard
            // - the CpuPins array (indexes [3] to [9].  [1,2,10] are constant (3.3V, 5V, GND) and [0] is unused.  This is normally based on an enumeration supplied in the NETMF port used.
            // - for other functionality, e.g. UART, SPI, etc, properties in the Socket class are set as appropriate to enable Gadgeteer.dll to access this functionality.
            // See the Mainboard Builder's Guide and specifically the Socket Types specification for more details
            // The two examples below are not realistically implementable sockets, but illustrate how to initialize a wide range of socket functionality.

            // This example socket 1 supports many types
            // Type 'D' - no additional action
            // Type 'I' - I2C pins must be used for the correct CpuPins
            // Type 'K' and 'U' - UART pins and UART handshaking pins must be used for the correct CpuPins, and the SerialPortName property must be set.
            // Type 'S' - SPI pins must be used for the correct CpuPins, and the SPIModule property must be set 
            // Type 'X' - the NativeI2CWriteRead function pointer is set (though by default "nativeI2C" is null) 
            //socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(1);
            //socket.SupportedTypes = new char[] { 'D', 'I', 'K', 'S', 'U', 'X' };
            //socket.CpuPins[3] = (Cpu.Pin)1;
            //socket.CpuPins[4] = (Cpu.Pin)52;
            //socket.CpuPins[5] = (Cpu.Pin)23;
            //socket.CpuPins[6] = (Cpu.Pin)12;
            //socket.CpuPins[7] = (Cpu.Pin)34;
            //socket.CpuPins[8] = (Cpu.Pin)5;
            //socket.CpuPins[9] = (Cpu.Pin)7;
            //socket.NativeI2CWriteRead = nativeI2C;
            //socket.SerialPortName = "COM1";
            //socket.SPIModule = SPI.SPI_module.SPI1;
            //GT.Socket.SocketInterfaces.RegisterSocket(socket);

            #endregion

#15

@ 19891003 - If you are physically connecting pin 3 to 5V then the driver might not work. It relies on pin 3 to be a digital output pin. By turning that pin HIGH/LOW the driver code controls the device. Just pick some available pin and use that instead of 5V.


#16

@ Architect -
thank you very much. !
I check the pins, if i should connect it with any PWM pins ?


#17

Yes. It should work. Driver code create DigitalOutput instance on that pin.