example application with TFT display and SMS receive send

Dependencies:   C027 C027_Support SeeedStudioTFTv2 TFT_fonts UbloxUSBModem mbed

Fork of C027_DisplayTest by Michael Ammann

This is an application that combines several libraries together and demonstartes the use of cellular, GPS and a Touch enabled TFT on the u-blox C027 board. /media/uploads/mazgch/c027_display.jpg

Committer:
mazgch
Date:
Fri Oct 18 18:30:12 2013 +0000
Revision:
0:bd6ef6f73032
Child:
2:fde6fc911c61
new lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 0:bd6ef6f73032 1 #include "mbed.h"
mazgch 0:bd6ef6f73032 2 #include "C027_PinNames.h"
mazgch 0:bd6ef6f73032 3
mazgch 0:bd6ef6f73032 4 #include "SPI_TFT_ILI9341.h"
mazgch 0:bd6ef6f73032 5 #include "Arial12x12.h"
mazgch 0:bd6ef6f73032 6 #include "Arial24x23.h"
mazgch 0:bd6ef6f73032 7 #include "Arial28x28.h"
mazgch 0:bd6ef6f73032 8 #include "font_big.h"
mazgch 0:bd6ef6f73032 9 #include "UbloxUSBGSMModem.h"
mazgch 0:bd6ef6f73032 10
mazgch 0:bd6ef6f73032 11 void ubxLogo(SPI_TFT_ILI9341* tft, int x0/*120*/, int y0/*160*/, int r)
mazgch 0:bd6ef6f73032 12 {
mazgch 0:bd6ef6f73032 13 int i1=r/8, i1_5=r*3/16, i2=r*2/8, i3=r*3/8,
mazgch 0:bd6ef6f73032 14 i4=r*4/8, i5=r*5/8, i6=r*6/8, i7=r*7/8;
mazgch 0:bd6ef6f73032 15 // the ball
mazgch 0:bd6ef6f73032 16 tft->fillcircle(x0, y0, r, Red);
mazgch 0:bd6ef6f73032 17 // the dot
mazgch 0:bd6ef6f73032 18 tft->fillcircle(x0-i3, y0+i2, i1_5, White);
mazgch 0:bd6ef6f73032 19 // the u
mazgch 0:bd6ef6f73032 20 tft->fillcircle(x0+i3, y0-i4, i3, White);
mazgch 0:bd6ef6f73032 21 tft->fillcircle(x0+i3, y0-i4, i1, Red);
mazgch 0:bd6ef6f73032 22 tft->fillrect( x0-i1, y0-i3, x0+i3, y0-i1, White);
mazgch 0:bd6ef6f73032 23 tft->fillrect( x0-i1, y0-i5, x0+i3, y0-i3, Red);
mazgch 0:bd6ef6f73032 24 tft->fillrect( x0-i1, y0-i7, x0+i6, y0-i5, White);
mazgch 0:bd6ef6f73032 25 }
mazgch 0:bd6ef6f73032 26
mazgch 0:bd6ef6f73032 27 void initC027(void)
mazgch 0:bd6ef6f73032 28 {
mazgch 0:bd6ef6f73032 29 DigitalOut mdmEn(MDMEN);
mazgch 0:bd6ef6f73032 30 DigitalOut mdmPwrOn(MDMPWRON);
mazgch 0:bd6ef6f73032 31 DigitalOut mdmRst(MDMRST);
mazgch 0:bd6ef6f73032 32 DigitalOut gpsEn(GPSEN);
mazgch 0:bd6ef6f73032 33 DigitalOut gpsRst(GPSRST);
mazgch 0:bd6ef6f73032 34
mazgch 0:bd6ef6f73032 35 gpsEn = 1; // LDOEN: 1=on,0=off
mazgch 0:bd6ef6f73032 36 gpsRst = 1; // RESET: 0=reset,1=operating
mazgch 0:bd6ef6f73032 37 mdmPwrOn = 1; // PWRON: 1=idle,0=action
mazgch 0:bd6ef6f73032 38 mdmEn = 1; // LDOEN: 1=on,0=off
mazgch 0:bd6ef6f73032 39 mdmRst = 0; // RESET: 0=reset,1=operating
mazgch 0:bd6ef6f73032 40 Thread::wait(100); // power on sequence is triggered by 50ms reset low and wait for supplies ready
mazgch 0:bd6ef6f73032 41 mdmRst = 1; // RESET: 1=operating,0=reset
mazgch 0:bd6ef6f73032 42 Thread::wait(3000);// modem will be ready after 3 seconds
mazgch 0:bd6ef6f73032 43 }
mazgch 0:bd6ef6f73032 44 int main()
mazgch 0:bd6ef6f73032 45 {
mazgch 0:bd6ef6f73032 46 DigitalOut cs(D4); // sd card cs
mazgch 0:bd6ef6f73032 47 DigitalOut bl(D7); // backlight
mazgch 0:bd6ef6f73032 48 cs = 1;
mazgch 0:bd6ef6f73032 49 bl = 1;
mazgch 0:bd6ef6f73032 50
mazgch 0:bd6ef6f73032 51 SPI_TFT_ILI9341 TFT(D11, D12, D13, D5, D3/*dummy*/, D6, "TFT"); // mosi, miso, sclk, cs, reset
mazgch 0:bd6ef6f73032 52 TFT.background(White); // set background to black
mazgch 0:bd6ef6f73032 53 TFT.foreground(Black); // set chars to white
mazgch 0:bd6ef6f73032 54 TFT.cls(); // clear the screen
mazgch 0:bd6ef6f73032 55 ubxLogo(&TFT, 120, 160, 80);
mazgch 0:bd6ef6f73032 56 TFT.set_font((unsigned char*) Arial12x12); // select the font
mazgch 0:bd6ef6f73032 57 TFT.set_orientation(3);
mazgch 0:bd6ef6f73032 58 TFT.locate(70,220);
mazgch 0:bd6ef6f73032 59 TFT.printf("u-blox C027-C20/U20/G35");
mazgch 0:bd6ef6f73032 60
mazgch 0:bd6ef6f73032 61 initC027();
mazgch 0:bd6ef6f73032 62 UbloxUSBGSMModem modem;
mazgch 0:bd6ef6f73032 63
mazgch 0:bd6ef6f73032 64 //#define MY_PHONE_NUMBER "+41765858801"
mazgch 0:bd6ef6f73032 65 #ifdef MY_PHONE_NUMBER
mazgch 0:bd6ef6f73032 66 printf("Sending the SMS to\r\n" MY_PHONE_NUMBER "\r\n");
mazgch 0:bd6ef6f73032 67 modem.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)");
mazgch 0:bd6ef6f73032 68 #endif
mazgch 0:bd6ef6f73032 69 while(true)
mazgch 0:bd6ef6f73032 70 {
mazgch 0:bd6ef6f73032 71 size_t count;
mazgch 0:bd6ef6f73032 72 if(!modem.getSMCount(&count) && (count > 0))
mazgch 0:bd6ef6f73032 73 {
mazgch 0:bd6ef6f73032 74 char num[17], msg[64];
mazgch 0:bd6ef6f73032 75 printf("%d SMS to read\n", count);
mazgch 0:bd6ef6f73032 76 if(!modem.getSM(num, msg, sizeof(msg)))
mazgch 0:bd6ef6f73032 77 {
mazgch 0:bd6ef6f73032 78 printf("%s : %s\r\n", num, msg);
mazgch 0:bd6ef6f73032 79 TFT.fillrect(0,0,320,35,White);
mazgch 0:bd6ef6f73032 80 TFT.locate(0,5);
mazgch 0:bd6ef6f73032 81 TFT.printf("Phone: %s\nSMS:%s", num, msg);
mazgch 0:bd6ef6f73032 82 }
mazgch 0:bd6ef6f73032 83 }
mazgch 0:bd6ef6f73032 84 Thread::wait(3000);
mazgch 0:bd6ef6f73032 85 }
mazgch 0:bd6ef6f73032 86 }