Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 20 of 20

Thread: Arduino_o_phone

  1. #1

    Arduino_o_phone

    Hi,
    Im little new to Teensy 3.1 and i have started to use Teensy 3.1 with Arduino_o_phone code. I have tested Arduino_o_phone from Adafruit and it compiles with Arduino UNO without problem but...

    When i compile Arduino_o_phone with Teensy 3.1 i get this error


    Build options changed, rebuilding all
    In file included from arduin_o_phone.ino:20:0:
    ..../arduino-1.6.5/hardware/teensy/avr/libraries/ILI9341_t3/ILI9341_t3.h:40:0: warning: "ILI9341_RDIMGFMT" redefined [enabled by default]
    #define ILI9341_RDIMGFMT 0x0D
    ^
    In file included from arduin_o_phone.ino:19:0:
    .../arduino-1.6.5/hardware/teensy/avr/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h:45:0: note: this is the location of the previous definition
    #define ILI9341_RDIMGFMT 0x0A
    ^
    arduin_o_phone:81: error: 'ILI9341_DARKGREEN' was not declared in this scope
    arduin_o_phone:81: error: 'ILI9341_DARKGREY' was not declared in this scope
    arduin_o_phone:85: error: 'ILI9341_PINK' was not declared in this scope
    arduin_o_phone:85: error: 'ILI9341_PINK' was not declared in this scope
    arduin_o_phone:86: error: 'Adafruit_GFX_Button' does not name a type
    arduin_o_phone.ino: In function 'void setup()':
    arduin_o_phone:123: error: 'buttons' was not declared in this scope
    arduin_o_phone.ino: In function 'void loop()':
    arduin_o_phone:178: error: 'buttons' was not declared in this scope
    arduin_o_phone:188: error: 'buttons' was not declared in this scope
    arduin_o_phone:193: error: 'buttons' was not declared in this scope
    Multiple libraries were found for "Adafruit_GFX.h"
    Used: .../arduino-1.6.5/hardware/teensy/avr/libraries/Adafruit_GFX
    Not used: .../Arduino/libraries/Adafruit-GFX-Library-master
    'buttons' was not declared in this scope

    My code:
    /*
    does:
    * can make calls on the speaker & mic

    todo:

    * status notification updates in loop()
    * dim screen when no touches in 1 minute
    * receive calls
    * receive texts
    * candy crush

    */


    #include <SPI.h>
    #include <Wire.h> // this is needed even tho we aren't using it
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"
    #include <ILI9341_t3.h>
    #include <Adafruit_STMPE610.h>
    #include <SoftwareSerial.h>
    #include <HardwareSerial.h>
    #include "Adafruit_FONA.h"

    #define FONA_RX 2
    #define FONA_TX 3
    #define FONA_RST 4

    //#define HWSERIAL Serial1
    //HardwareSerial fonaSS = Serial1; // replaces SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


    // For the Adafruit TFT shield, these are the default.
    #define TFT_DC 9
    #define TFT_CS 10

    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

    // The STMPE610 uses hardware SPI on the shield, and #8
    #define STMPE_CS 8
    Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);

    // This is calibration data for the raw touch data to the screen coordinates
    #define TS_MINX 150
    #define TS_MINY 130
    #define TS_MAXX 3800
    #define TS_MAXY 4000

    /******************* UI details */
    #define BUTTON_X 40
    #define BUTTON_Y 100
    #define BUTTON_W 60
    #define BUTTON_H 30
    #define BUTTON_SPACING_X 20
    #define BUTTON_SPACING_Y 20
    #define BUTTON_TEXTSIZE 2

    // text box where numbers go
    #define TEXT_X 10
    #define TEXT_Y 10
    #define TEXT_W 220
    #define TEXT_H 50
    #define TEXT_TSIZE 3
    #define TEXT_TCOLOR ILI9341_WHITE
    // the data (phone #) we store in the textfield
    #define TEXT_LEN 12
    char textfield[TEXT_LEN+1] = "";
    uint8_t textfield_i=0;

    // We have a status line for like, is FONA working
    #define STATUS_X 10
    #define STATUS_Y 65

    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Call", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    uint16_t buttoncolors[15] = {ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_PINK, ILI9341_BLUE, ILI9341_PINK};
    Adafruit_GFX_Button buttons[15];

    // Print something in the mini status bar with either flashstring
    void status(const __FlashStringHelper *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }
    // or charstring
    void status(char *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }

    void setup() {
    Serial.begin(9600);
    Serial.println("Arduin-o-Phone!");

    // clear the screen
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);

    // eep touchscreen not found?
    if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
    }
    Serial.println("Touchscreen started");

    // create buttons
    for (uint8_t row=0; row<5; row++) {
    for (uint8_t col=0; col<3; col++) {
    buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
    BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
    BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
    buttonlabels[col + row*3], BUTTON_TEXTSIZE);
    buttons[col + row*3].drawButton();
    }
    }

    // create 'text field'
    tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);

    status(F("Checking for FONA..."));
    // Check FONA is there
    fonaSS.begin(4800); // if you're using software serial

    // See if the FONA is responding
    if (! fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
    status(F("Couldn't find FONA "));
    while (1);
    }
    status(F("FONA is OK!"));

    // Check we connect to the network
    while (fona.getNetworkStatus() != 1) {
    status(F("Looking for service..."));
    delay(100);
    }
    status(F("Connected to network!"));

    // set to external mic & headphone
    fona.setAudio(FONA_EXTAUDIO);
    }


    void loop(void) {
    TS_Point p;

    if (ts.bufferSize()) {
    p = ts.getPoint();
    } else {
    // this is our way of tracking touch 'release'!
    p.x = p.y = p.z = -1;
    }

    // Scale from ~0->4000 to tft.width using the calibration #'s
    if (p.z != -1) {
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    Serial.print("("); Serial.print(p.x); Serial.print(", ");
    Serial.print(p.y); Serial.print(", ");
    Serial.print(p.z); Serial.println(") ");
    }

    // go thru all the buttons, checking if they were pressed
    for (uint8_t b=0; b<15; b++) {
    if (buttons[b].contains(p.x, p.y)) {
    //Serial.print("Pressing: "); Serial.println(b);
    buttons[b].press(true); // tell the button it is pressed
    } else {
    buttons[b].press(false); // tell the button it is NOT pressed
    }
    }

    // now we can ask the buttons if their state has changed
    for (uint8_t b=0; b<15; b++) {
    if (buttons[b].justReleased()) {
    // Serial.print("Released: "); Serial.println(b);
    buttons[b].drawButton(); // draw normal
    }

    if (buttons[b].justPressed()) {
    buttons[b].drawButton(true); // draw invert!

    // if a numberpad button, append the relevant # to the textfield
    if (b >= 3) {
    if (textfield_i < TEXT_LEN) {
    textfield[textfield_i] = buttonlabels[b][0];
    textfield_i++;
    textfield[textfield_i] = 0; // zero terminate

    fona.playDTMF(buttonlabels[b][0]);
    }
    }

    // clr button! delete char
    if (b == 1) {

    textfield[textfield_i] = 0;
    if (textfield > 0) {
    textfield_i--;
    textfield[textfield_i] = ' ';
    }
    }

    // update the current text field
    Serial.println(textfield);
    tft.setCursor(TEXT_X + 2, TEXT_Y+10);
    tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
    tft.setTextSize(TEXT_TSIZE);
    tft.print(textfield);

    // its always OK to just hang up
    if (b == 2) {
    status(F("Hanging up"));
    fona.hangUp();
    }
    // we dont really check that the text field makes sense
    // just try to call
    if (b == 0) {
    status(F("Calling"));
    Serial.print("Calling "); Serial.print(textfield);

    fona.callPhone(textfield);
    }

    delay(100); // UI debouncing
    }
    }
    }

    I would be werry nice to give some guidens

    Best regards

    Toxic

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by toxic View Post
    #include "Adafruit_ILI9341.h"
    #include <ILI9341_t3.h>
    These 2 libraries do the same thing with the same hardware. Use one or the other, but not both.

  3. #3
    Quote Originally Posted by PaulStoffregen View Post
    These 2 libraries do the same thing with the same hardware. Use one or the other, but not both.
    i have tried this also before you wrote.

    / toxic

  4. #4
    Hi,
    Is there any difference between #include " or #include < with Teensy 3.1 library?
    How can i specify to use AVR and or Teensy library?

    Best regards
    Toxic

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Oh, I believe I see what's wrong.

    Teensyduino has somehow older copies of Adafruit_ILI9341 and Adafruit_GFX. This FONA example is using features Adafruit has recently added to those libraries.

    As a short-term solution, you can probably just delete the copies hardware/teensy/avr/libraries, and install Adafruit's latest versions.

    As a longer-term solution, I really need to update these 2 libs on the next version of Teensyduino.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    I've updated the ILI9341_t3 library for compatibility with these newer Adafruit library features.

    https://github.com/PaulStoffregen/ILI9341_t3

    Please let me know if this works for you?

  7. #7
    Hi,
    Now everything works
    Thank you very much!!!

    Now i can make next step

    I have added latest lib from Adafruit_FONA to make it work.

    Best regards
    Toxic
    Last edited by toxic; 08-08-2015 at 06:05 PM.

  8. #8
    Hi,
    Now i get this error:


    arduin_o_phone:53: error: 'ILI9341_t3' does not name a type
    arduin_o_phone.ino: In function 'void status(const __FlashStringHelper*)':
    arduin_o_phone:105: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void status(char*)':
    arduin_o_phone:113: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void setup()':
    arduin_o_phone:129: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void loop()':
    arduin_o_phone:211: error: 'tft' was not declared in this scope
    arduin_o_phone:261: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readSMS()':
    arduin_o_phone:318: error: 'tft' was not declared in this scope
    arduin_o_phone.ino:316:11: warning: unused variable 'len' [-Wunused-variable]
    arduin_o_phone.ino: In function 'void readVolt()':
    arduin_o_phone:336: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void test()':
    arduin_o_phone:348: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readRSSI()':
    arduin_o_phone:372: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readNetStatud()':
    arduin_o_phone:385: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readVolume()':
    arduin_o_phone:398: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void getCall()':
    arduin_o_phone:405: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void deleteSMS()':
    arduin_o_phone:417: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readBat()':
    arduin_o_phone:438: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readNetTime()':
    arduin_o_phone:452: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void readCCID()':
    arduin_o_phone:461: error: 'tft' was not declared in this scope
    arduin_o_phone.ino: In function 'void setMute()':
    arduin_o_phone:467: error: 'tft' was not declared in this scope
    'tft' was not declared in this scope

    My code:

    /*
    does:
    * can make calls on the speaker & mic

    todo:

    * status notification updates in loop()
    * dim screen when no touches in 1 minute
    * receive calls
    * receive texts
    * candy crush

    */


    #include <SPI.h>
    #include <Wire.h> // this is needed even tho we aren't using it
    #include <Adafruit_GFX.h>
    #include "Adafruit_ILI9341.h"
    //#include <ILI9341_t3.h>
    #include <Adafruit_STMPE610.h>
    #include <SoftwareSerial.h>
    #include <HardwareSerial.h>
    #include "Adafruit_FONA.h"
    #include <avr/interrupt.h>
    #include <SD.h>

    #define FONA_RX 1//2
    #define FONA_TX 0//3
    #define FONA_RST 3//4
    #define FONA_KEY 5
    #define FONA_PS 6

    // Make sure this interrupt pin is connected to FONA RI!
    #define FONA_RI_INTERRUPT 2

    // this is a large buffer for replies
    char replybuffer[255];

    #define HWSERIAL Serial1
    HardwareSerial fonaSS = Serial1; // replaces SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    //SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


    // For the Adafruit TFT shield, these are the default.
    #define TFT_DC 9
    #define TFT_CS 10
    #define TFT_RST 4

    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST);

    // The STMPE610 uses hardware SPI on the shield, and #8
    #define STMPE_CS 8
    Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);

    // SD card reader
    #define SD_CS 7

    // This is calibration data for the raw touch data to the screen coordinates
    #define TS_MINX 150
    #define TS_MINY 130
    #define TS_MAXX 3800
    #define TS_MAXY 4000

    /******************* UI details */
    #define BUTTON_X 40
    #define BUTTON_Y 100
    #define BUTTON_W 60
    #define BUTTON_H 30
    #define BUTTON_SPACING_X 20
    #define BUTTON_SPACING_Y 20
    #define BUTTON_TEXTSIZE 2

    // text box where numbers go
    #define TEXT_X 10
    #define TEXT_Y 10
    #define TEXT_W 220
    #define TEXT_H 50
    #define TEXT_TSIZE 3
    #define TEXT_TCOLOR ILI9341_WHITE
    // the data (phone #) we store in the textfield
    #define TEXT_LEN 12
    char textfield[TEXT_LEN + 1] = "";
    uint8_t textfield_i = 0;

    // We have a status line for like, is FONA working
    #define STATUS_X 10
    #define STATUS_Y 65

    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Call", "Del", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    uint16_t buttoncolors[15] = {ILI9341_GREEN, ILI9341_BLUE, ILI9341_RED,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_RED, ILI9341_BLUE, ILI9341_RED
    };
    Adafruit_GFX_Button buttons[15];

    // Print something in the mini status bar with either flashstring
    void status(const __FlashStringHelper *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }
    // or charstring
    void status(char *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }

    void setup() {
    Serial.begin(9600);
    Serial.println("Arduin-o-Phone!");

    pinMode(FONA_RI_INTERRUPT, INPUT); // sets the digital pin as input
    digitalWrite(FONA_RI_INTERRUPT, HIGH);
    //attachInterrupt(FONA_RI_INTERRUPT, ISR1, FALLING); // interrrupt 1 is data ready

    // clear the screen
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);

    // eep touchscreen not found?
    if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
    }
    Serial.println("Touchscreen started");

    // create buttons
    for (uint8_t row = 0; row < 5; row++) {
    for (uint8_t col = 0; col < 3; col++) {
    buttons[col + row * 3].initButton(&tft, BUTTON_X + col * (BUTTON_W + BUTTON_SPACING_X),
    BUTTON_Y + row * (BUTTON_H + BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
    BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col + row * 3], ILI9341_WHITE,
    buttonlabels[col + row * 3], BUTTON_TEXTSIZE);
    buttons[col + row * 3].drawButton();
    }
    }

    // create 'text field'
    tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_BLUE); //ILI9341_WHITE

    status(F("Checking for FONA..."));
    // Check FONA is there
    fonaSS.begin(4800); // if you're using software serial

    pinMode(FONA_PS, INPUT);
    pinMode(FONA_KEY, OUTPUT);

    while ( digitalRead(FONA_PS) == LOW) {
    digitalWrite(FONA_KEY, LOW); //pull down power set pin
    delay(100);
    }
    digitalWrite(FONA_KEY, HIGH); //pull it back up again


    // See if the FONA is responding
    if (! fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
    status(F("Couldn't find FONA "));
    while (1);
    }
    status(F("FONA is OK!"));
    // Check we connect to the network

    while (fona.getNetworkStatus() != 1) {
    status(F("Wait for FONA..."));
    delay(100);
    }
    status(F("Connected!"));


    setVolMic();
    //test();
    tft.setCursor(10, 15);
    //readBat();
    //readSMS();
    //readRSSI();
    //readCCID();
    //readNetStatud();
    //readVolume();
    //readBat();
    //readNetTime();
    //setMute();
    //powerDownUp();

    }


    void loop(void) {
    TS_Point p;

    if (ts.bufferSize()) {
    p = ts.getPoint();
    } else {
    // this is our way of tracking touch 'release'!
    p.x = p.y = p.z = -1;
    }

    // Scale from ~0->4000 to tft.width using the calibration #'s
    if (p.z != -1) {
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    Serial.print("("); Serial.print(p.x); Serial.print(", ");
    Serial.print(p.y); Serial.print(", ");
    Serial.print(p.z); Serial.println(") ");
    }

    // go thru all the buttons, checking if they were pressed
    for (uint8_t b = 0; b < 15; b++) {
    if (buttons[b].contains(p.x, p.y)) {
    //Serial.print("Pressing: "); Serial.println(b);
    buttons[b].press(true); // tell the button it is pressed
    } else {
    buttons[b].press(false); // tell the button it is NOT pressed
    }
    }

    // now we can ask the buttons if their state has changed
    for (uint8_t b = 0; b < 15; b++) {
    if (buttons[b].justReleased()) {
    // Serial.print("Released: "); Serial.println(b);
    buttons[b].drawButton(); // draw normal
    }

    if (buttons[b].justPressed()) {
    buttons[b].drawButton(true); // draw invert!

    // if a numberpad button, append the relevant # to the textfield
    if (b >= 3) {
    if (textfield_i < TEXT_LEN) {
    textfield[textfield_i] = buttonlabels[b][0];
    textfield_i++;
    textfield[textfield_i] = 0; // zero terminate

    fona.playDTMF(buttonlabels[b][0]);
    }
    }

    // clr button! delete char
    if (b == 1) {

    textfield[textfield_i] = 0;
    if (textfield > 0) {
    textfield_i--;
    textfield[textfield_i] = ' ';
    }
    }

    // update the current text field
    Serial.println(textfield);
    tft.setCursor(TEXT_X + 2, TEXT_Y + 10);
    tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
    tft.setTextSize(TEXT_TSIZE);
    tft.print(textfield);

    // its always OK to just hang up
    if (b == 2) {
    status(F("Hanging up"));
    fona.hangUp();
    }
    // we dont really check that the text field makes sense
    // just try to call
    if (b == 0) {
    status(F("Calling"));
    Serial.print("Calling "); Serial.print(textfield);

    fona.callPhone(textfield);

    }
    tft.setCursor(15, 121);
    tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
    tft.setTextSize(1);
    readRSSI();
    tft.setCursor(15, 171);
    readBat();

    delay(50); // UI debouncing (100)
    }
    }

    }


    /*
    void ISR1() {
    cli();
    setMute();

    //if (b == 0) {
    // status(F("Answer!"));
    // fona.pickUp();
    // Create a small string buffer to hold incoming call number.
    char phone[32] = {0};
    // Check for an incoming call. Will return true if a call is incoming.
    fona.incomingCallNumber(phone);
    tft.print(F("Phone nr: "));
    tft.println(phone);
    sei();
    }
    */

    void readSMS() {
    int8_t n = 1;
    uint16_t smslen;
    char sender[25];
    uint8_t len = fona.readSMS(n, replybuffer, 250, &smslen);
    int8_t smsnum = fona.getNumSMS();
    tft.print(F(" SMS's on SIM:"));
    tft.print(smsnum);
    tft.println();
    tft.println(" SMS: ");
    tft.print(n);
    tft.print(" ");
    //tft.print(len);
    tft.print(replybuffer);
    fona.getSMSSender(n, sender, sizeof(sender));
    sender[0] = 0;
    tft.print(F("From: "));
    tft.println(sender);

    }

    void readVolt() {
    uint16_t adc ;
    fona.getADCVoltage(&adc);
    tft.print(F("ADC = ")); tft.print(adc); tft.println(F(" mV"));
    }

    void test() {

    //uint8_t smsn = 1;
    //uint16_t smslen;
    //tft.print(textfield);
    //tft.println(fona.getSMSSender(smsn, replybuffer, 250));
    //tft.println(smslen);
    //tft.println(fona.readSMS(smsn, replybuffer, 250, &smslen));
    int8_t smsnum = fona.getNumSMS();
    tft.print("SMS in card: ");
    tft.print(smsnum);

    char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
    uint8_t imeiLen = fona.getIMEI(imei);
    if (imeiLen > 0) {
    tft.println(" IMEI: "); tft.println(imei);
    }

    // Enable incoming call notification.
    if (fona.callerIdNotification(true, FONA_RI_INTERRUPT)) {
    tft.println(F("Caller ID on"));
    }
    else {
    tft.println(F("Caller ID off"));
    }

    }

    void readRSSI() {

    uint8_t n = fona.getRSSI();
    int8_t r;

    tft.print(F("RSSI = ")); tft.print(n); tft.print(": ");
    if (n == 0) r = -115;
    if (n == 1) r = -111;
    if (n == 31) r = -52;
    if ((n >= 2) && (n <= 30)) {
    r = map(n, 2, 30, -110, -54);
    }
    tft.print(r); tft.println(F(" dBm"));
    }

    void readNetStatud() {
    // read the network/cellular status
    uint8_t n = fona.getNetworkStatus();
    tft.print(F("Net status "));
    tft.print(n);
    tft.print(F(": "));
    if (n == 0) tft.println(F("Not reg."));
    if (n == 1) tft.println(F("Reg. (home)"));
    if (n == 2) tft.println(F("Not reg. (searching)"));
    if (n == 3) tft.println(F("Denied"));
    if (n == 4) tft.println(F("Unknown"));
    if (n == 5) tft.println(F("Reg. roaming"));
    }

    void readVolume() {
    uint8_t v = fona.getVolume();
    tft.print("Vol: ");
    tft.print(v); tft.println("%");
    }

    void getCall() {
    // call a phone!
    char number[30];
    tft.print(F("Call #"));

    tft.println();
    tft.print(F("Calling "));
    tft.println(number);
    fona.callPhone(number);

    //fona.hangUp();
    //fona.pickUp();
    }

    void deleteSMS() {
    tft.print(F("Delete #"));
    uint8_t smsn;// = readnumber();
    tft.print(F("\n\rDeleting SMS #")); tft.println(smsn);
    if (fona.deleteSMS(smsn)) {
    tft.println(F("OK!"));
    } else {
    tft.println(F("Couldn't delete"));
    }
    }

    void setVolMic() {
    // set to external mic & headphone
    fona.setAudio(FONA_EXTAUDIO);
    fona.setMicVolume(FONA_EXTAUDIO, 10);
    uint8_t vol = 80;//readnumber();
    fona.setVolume(vol);
    }

    void readBat() {
    uint16_t vbat;
    fona.getBattVoltage(&vbat);
    tft.print(F("VBat = "));
    tft.print(vbat);
    tft.print(F(" mV "));
    fona.getBattPercent(&vbat);
    tft.print(F("VPct = "));
    tft.print(vbat);
    tft.print(F("%"));
    tft.println();
    }

    void readNetTime() {
    char buffer[23];
    //fona.enableNTPTimeSync(true, F("pool.ntp.org"));
    //fona.enableNetworkTimeSync(true);
    tft.print(F("Sync time..."));
    fona.getTime(buffer, 23); // make sure replybuffer is at least 23 bytes!
    tft.print(F("Time = "));
    tft.println(buffer);

    }

    void readCCID() {
    fona.getSIMCCID(replybuffer); // make sure replybuffer is at least 21 bytes!
    tft.print(F("SIM CCID = ")); tft.println(replybuffer);
    }

    void setMute() {
    uint8_t vol = 0;
    fona.setVolume(vol);
    tft.print("Mute");
    }

    void setHeadphone() {
    fona.setAudio(FONA_HEADSETAUDIO);
    fona.setMicVolume(FONA_HEADSETAUDIO, 15);
    }

    void setSpeaker() {
    fona.setAudio(FONA_EXTAUDIO);
    fona.setMicVolume(FONA_EXTAUDIO, 10);
    }

    void powerDownUp() {
    if (digitalRead(FONA_PS)) {
    digitalWrite(FONA_KEY, LOW);
    delay(2000);
    digitalWrite(FONA_KEY, HIGH);
    }
    }

    I have latest ILI9341_t3 library today.

    Regards
    Toxic

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by toxic View Post
    Now i get this error:

    arduin_o_phone:53: error: 'ILI9341_t3' does not name a type
    Well, of course ILI9341_t3 is undefined. You commented out the #include line for ILI9341_t3!

  10. #10
    Hi hi hi, i was blind.

    Thanks.

    Now i get this error:


    In file included from arduin_o_phone.ino:20:0:
    /arduino-1.6.5/hardware/teensy/avr/libraries/ILI9341_t3/ILI9341_t3.h:270:7: error: redefinition of 'class Adafruit_GFX_Button'
    class Adafruit_GFX_Button {
    ^
    In file included from arduin_o_phone.ino:18:0:
    /arduino-1.6.5/hardware/teensy/avr/libraries/Adafruit-GFX/Adafruit_GFX.h:96:7: error: previous definition of 'class Adafruit_GFX_Button'
    class Adafruit_GFX_Button {
    ^
    arduin_o_phone.ino: In function 'void setup()':
    arduin_o_phone:145: error: no matching function for call to 'Adafruit_GFX_Button::initButton(ILI9341_t3*, int, int, int, int, int, uint16_t&, int, char [5], int)'
    arduin_o_phone.ino:145:85: note: candidate is:
    In file included from arduin_o_phone.ino:18:0:
    /arduino-1.6.5/hardware/teensy/avr/libraries/Adafruit-GFX/Adafruit_GFX.h:100:8: note: void Adafruit_GFX_Button::initButton(Adafruit_GFX*, int16_t, int16_t, uint8_t, uint8_t, uint16_t, uint16_t, uint16_t, char*, uint8_t)
    void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
    ^
    /arduino-1.6.5/hardware/teensy/avr/libraries/Adafruit-GFX/Adafruit_GFX.h:100:8: note: no known conversion for argument 1 from 'ILI9341_t3*' to 'Adafruit_GFX*'
    arduin_o_phone.ino: In function 'void readSMS()':
    arduin_o_phone.ino:316:11: warning: unused variable 'len' [-Wunused-variable]
    no matching function for call to 'Adafruit_GFX_Button::initButton(ILI9341_t3*, int, int, int, int, int, uint16_t&, int, char [5], int)'


    / Toxic
    Last edited by toxic; 08-12-2015 at 12:06 AM.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by toxic View Post
    Now i get this error:

    /arduino-1.6.5/hardware/teensy/avr/libraries/ILI9341_t3/ILI9341_t3.h:270:7: error: redefinition of 'class Adafruit_GFX_Button'
    Comment out the Adafruit_GFX library. ILI9341_t3 doesn't use it.

    Also comment out Adafruit_ILI9341.h. Hopefully you can see how that's redundant?

  12. #12
    Hi,
    Now it works. It starts up much faster. Wow!

    Thank you very much for your help.

    Toxic

  13. #13
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    I have successfully run the Teensy TouchScreen example ILI9341Test. Now I am trying to implement Adafruit Arduin_O_Phone code to create buttons and button handler. I am not interested in the Fono part. In the code below I have deleted the references to fono.

    Using the libraries in Arduin_O_Phone The compiles for the UNO but not Teensy 3.2.
    For Teensy 3.2 I get this error:

    C:\Users\CoyoteWaits\Documents\Arduino\libraries\W ire\utility\twi.c:27:24: fatal error: compat/twi.h: No such file or directory

    Seems related to the use of Wire.h though it says wire is not used

    #include <Wire.h> // this is needed even tho we aren't using it

    Following guidance in the thread above I deleted
    /*
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"
    #include <Adafruit_STMPE610.h>
    */
    and added
    #include <ILI9341_t3.h>
    #include <font_Arial.h> // from ILI9341_t3
    #include <XPT2046_Touchscreen.h>

    I still get this error
    C:\Users\CoyoteWaits\Documents\Arduino\libraries\W ire\utility\twi.c:27:24: fatal error: compat/twi.h: No such file or directory

    compilation terminated.

    Next I commented I commented out
    //#include <Wire.h> // this is needed even tho we aren't using it

    That gets the compilation past the lack of twi.c
    but now I get a number of errors related to missing library functions

    Teensy_o_phone_JNE:47: error: 'Adafruit_ILI9341' does not name a type
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

    ^

    Teensy_o_phone_JNE:51: error: 'Adafruit_STMPE610' does not name a type
    Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);

    ^

    Teensy_o_phone_JNE: In function 'void status(const __FlashStringHelper*)':
    Teensy_o_phone_JNE:95: error: 'tft' was not declared in this scope
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);

    ^

    Teensy_o_phone_JNE: In function 'void status(char*)':
    Teensy_o_phone_JNE:103: error: 'tft' was not declared in this scope
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);

    ^

    Teensy_o_phone_JNE: In function 'void setup()':
    Teensy_o_phone_JNE:115: error: 'tft' was not declared in this scope
    tft.begin();

    ^

    Teensy_o_phone_JNE:119: error: 'ts' was not declared in this scope
    if (!ts.begin()) {

    ^

    Teensy_o_phone_JNE: In function 'void loop()':
    Teensy_o_phone_JNE:167: error: 'ts' was not declared in this scope
    if (ts.bufferSize()) {

    ^

    Teensy_o_phone_JNE:176: error: 'tft' was not declared in this scope
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());

    ^

    Teensy_o_phone_JNE:226: error: 'tft' was not declared in this scope
    tft.setCursor(TEXT_X + 2, TEXT_Y+10);

    ^

    'Adafruit_ILI9341' does not name a type

    The final version of the code is listed below. I am not locked into using the Arduin_O_Phone code but would like to create buttons and button handlers.

    CODE

    /*
    does:
    * can make calls on the speaker & mic

    todo:

    * status notification updates in loop()
    * dim screen when no touches in 1 minute
    * receive calls
    * receive texts
    * candy crush
    *
    * JACK MODS
    * Starting from Adafruit Arduin_o_Fone trying to make TFT touch screen with buttons and button handler for TEENSY
    * Commented out all of the fono commands as not planning to use fono

    */


    #include <SPI.h>
    //#include <Wire.h> // this is needed even tho we aren't using it

    #include <ILI9341_t3.h>
    #include <font_Arial.h> // from ILI9341_t3
    #include <XPT2046_Touchscreen.h>
    /*
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"
    #include <Adafruit_STMPE610.h>
    */
    //#include <SoftwareSerial.h>
    //#include "Adafruit_FONA.h"
    /*
    #define FONA_RX 2
    #define FONA_TX 3
    #define FONA_RST 4

    SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
    */

    // For the Adafruit TFT shield, these are the default.
    #define TFT_DC 9
    #define TFT_CS 10

    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

    // The STMPE610 uses hardware SPI on the shield, and #8
    #define STMPE_CS 8
    Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);

    // This is calibration data for the raw touch data to the screen coordinates
    #define TS_MINX 150
    #define TS_MINY 130
    #define TS_MAXX 3800
    #define TS_MAXY 4000

    /******************* UI details */
    #define BUTTON_X 40
    #define BUTTON_Y 100
    #define BUTTON_W 60
    #define BUTTON_H 30
    #define BUTTON_SPACING_X 20
    #define BUTTON_SPACING_Y 20
    #define BUTTON_TEXTSIZE 2

    // text box where numbers go
    #define TEXT_X 10
    #define TEXT_Y 10
    #define TEXT_W 220
    #define TEXT_H 50
    #define TEXT_TSIZE 3
    #define TEXT_TCOLOR ILI9341_MAGENTA
    // the data (phone #) we store in the textfield
    #define TEXT_LEN 12
    char textfield[TEXT_LEN+1] = "";
    uint8_t textfield_i=0;

    // We have a status line for like, is FONA working
    #define STATUS_X 10
    #define STATUS_Y 65

    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    uint16_t buttoncolors[15] = {ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
    ILI9341_ORANGE, ILI9341_BLUE, ILI9341_ORANGE};
    Adafruit_GFX_Button buttons[15];

    // Print something in the mini status bar with either flashstring
    void status(const __FlashStringHelper *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }
    // or charstring
    void status(char *msg) {
    tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
    tft.setCursor(STATUS_X, STATUS_Y);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.print(msg);
    }

    void setup() {
    Serial.begin(9600);
    Serial.println("Arduin-o-Phone!");

    // clear the screen
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);

    // eep touchscreen not found?
    if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
    }
    Serial.println("Touchscreen started");

    // create buttons
    for (uint8_t row=0; row<5; row++) {
    for (uint8_t col=0; col<3; col++) {
    buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
    BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
    BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
    buttonlabels[col + row*3], BUTTON_TEXTSIZE);
    buttons[col + row*3].drawButton();
    }
    }

    // create 'text field'
    tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);

    /*
    status(F("Checking for FONA..."));
    // Check FONA is there
    fonaSS.begin(4800); // if you're using software serial

    // See if the FONA is responding
    if (! fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
    status(F("Couldn't find FONA "));
    while (1);
    }
    status(F("FONA is OK!"));

    // Check we connect to the network
    while (fona.getNetworkStatus() != 1) {
    status(F("Looking for service..."));
    delay(100);
    }
    status(F("Connected to network!"));

    // set to external mic & headphone
    fona.setAudio(FONA_EXTAUDIO);
    */
    }


    void loop(void) {
    TS_Point p;

    if (ts.bufferSize()) {
    p = ts.getPoint();
    } else {
    // this is our way of tracking touch 'release'!
    p.x = p.y = p.z = -1;
    }

    // Scale from ~0->4000 to tft.width using the calibration #'s
    if (p.z != -1) {
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    Serial.print("("); Serial.print(p.x); Serial.print(", ");
    Serial.print(p.y); Serial.print(", ");
    Serial.print(p.z); Serial.println(") ");
    }

    // go thru all the buttons, checking if they were pressed
    for (uint8_t b=0; b<15; b++) {
    if (buttons[b].contains(p.x, p.y)) {
    //Serial.print("Pressing: "); Serial.println(b);
    buttons[b].press(true); // tell the button it is pressed
    } else {
    buttons[b].press(false); // tell the button it is NOT pressed
    }
    }

    // now we can ask the buttons if their state has changed
    for (uint8_t b=0; b<15; b++) {
    if (buttons[b].justReleased()) {
    // Serial.print("Released: "); Serial.println(b);
    buttons[b].drawButton(); // draw normal
    }

    if (buttons[b].justPressed()) {
    buttons[b].drawButton(true); // draw invert!

    // if a numberpad button, append the relevant # to the textfield
    if (b >= 3) {
    if (textfield_i < TEXT_LEN) {
    textfield[textfield_i] = buttonlabels[b][0];
    textfield_i++;
    textfield[textfield_i] = 0; // zero terminate

    // fona.playDTMF(buttonlabels[b][0]);
    }
    }

    // clr button! delete char
    if (b == 1) {

    textfield[textfield_i] = 0;
    if (textfield > 0) {
    textfield_i--;
    textfield[textfield_i] = ' ';
    }
    }

    // update the current text field
    Serial.println(textfield);
    tft.setCursor(TEXT_X + 2, TEXT_Y+10);
    tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
    tft.setTextSize(TEXT_TSIZE);
    tft.print(textfield);

    // its always OK to just hang up
    if (b == 2) {
    status(F("Hanging up"));
    // fona.hangUp();
    }
    // we dont really check that the text field makes sense
    // just try to call
    if (b == 0) {
    status(F("Calling"));
    Serial.print("Calling "); Serial.print(textfield);

    // fona.callPhone(textfield);
    }

    delay(100); // UI debouncing
    }
    }
    }

  14. #14
    Senior Member
    Join Date
    Apr 2017
    Posts
    162
    You still have errors in how you are calling the graphics library

    you include this lib from Paul
    #include <ILI9341_t3.h>

    but initialize the adafruit library
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);


    try replacing the object create line to
    ILI9341_t3 tft = ILI9341_t3(10, 9);

    there may be other errors after the above change.

    I have a teensy 3.2 working with Pauls lib and touch screen (using a 240 x 320 9341 chip). I recommend starting a new program and just write a simple "hello world" to the display, then get touch working. Then go for this FONA program--this is a bit complex to get working for a first timer.

    And you should use code tags as it makes reading code easier.

    Hope this helps

  15. #15
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    Quote Originally Posted by KrisKasprzak View Post
    You still have errors in how you are calling the graphics library

    you include this lib from Paul
    #include <ILI9341_t3.h>

    but initialize the adafruit library
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);


    try replacing the object create line to
    ILI9341_t3 tft = ILI9341_t3(10, 9);

    there may be other errors after the above change.

    I have a teensy 3.2 working with Pauls lib and touch screen (using a 240 x 320 9341 chip). I recommend starting a new program and just write a simple "hello world" to the display, then get touch working. Then go for this FONA program--this is a bit complex to get working for a first timer.

    And you should use code tags as it makes reading code easier.

    Hope this helps
    Great, I had to fix a couple more library calls but the modified code draws all of the AdaFruit Arduin-o-phone buttons and responds to the screen touches but they are wrong 8 is 3, 1 is 8, end is clr. This looks like a TFT screen and Touch screen scaling alignment issue so I'll tackle that next.

    Thanks for the help.

  16. #16
    Senior Member
    Join Date
    Apr 2017
    Posts
    162
    I didn't see a line for rotating your screen, but if you do that will mess the tft code up pretty bad. it's not designed to handle rotated screens--at least my lib wasn't. if i remember it didn't handle the x-y orientation change so i fixed by swapping the x and y in the following (also notice my real screen coordinates aren't close to the physical)

    // x = map(p.y, real left, real right, 0, 480);
    // y = map(p.x, real bottom, real top, 320, 0);
    x = map(p.y, 940, 70, 0, 480);
    y = map(p.x, 890, 137, 320, 0);

  17. #17
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    Kris, Thanks for that update. I'll try to implement that logic but I think we are working from different versions of Adafruit Arduin-o-phone. My version from GitHub a couple days ago. A search for map gives me this

    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());

    Here is current code:

    Code:
    /* 
    does:
     * can make calls on the speaker & mic
    
    todo:
    
     * status notification updates in loop()
     * dim screen when no touches in 1 minute
     * receive calls
     * receive texts
     * candy crush
     * 
     * JACK MODS
     * Starting from Adafruit Arduin_o_Fone trying to make TFT touch screen with buttons and button handler for TEENSY
     * Commented out all of the fono commands as not planning to use fono
     
    */
    
    
    #include <SPI.h>
    //#include <Wire.h>      // this is needed even tho we aren't using it
    
    #include <ILI9341_t3.h>
    #include <font_Arial.h> // from ILI9341_t3
    #include <XPT2046_Touchscreen.h>
    /*
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"
    #include <Adafruit_STMPE610.h>
    */
    //#include <SoftwareSerial.h>
    //#include "Adafruit_FONA.h"
    /*
    #define FONA_RX 2
    #define FONA_TX 3
    #define FONA_RST 4
    
    SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
    */
    
    // For the Adafruit TFT shield, these are the default.
    
    #define TFT_DC 9
    #define TFT_CS 10
    
    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
    
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
    // The STMPE610 uses hardware SPI on the shield, and #8
    #define CS_PIN  8
    //#define STMPE_CS 8
    XPT2046_Touchscreen ts(CS_PIN);
    //Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
    
    // This is calibration data for the raw touch data to the screen coordinates
    #define TS_MINX 150
    #define TS_MINY 130
    #define TS_MAXX 3800
    #define TS_MAXY 4000
    
    /******************* UI details */
    #define BUTTON_X 40
    #define BUTTON_Y 100
    #define BUTTON_W 60
    #define BUTTON_H 30
    #define BUTTON_SPACING_X 20
    #define BUTTON_SPACING_Y 20
    #define BUTTON_TEXTSIZE 2
    
    // text box where numbers go
    #define TEXT_X 10
    #define TEXT_Y 10
    #define TEXT_W 220
    #define TEXT_H 50
    #define TEXT_TSIZE 3
    #define TEXT_TCOLOR ILI9341_MAGENTA
    // the data (phone #) we store in the textfield
    #define TEXT_LEN 12
    char textfield[TEXT_LEN+1] = "";
    uint8_t textfield_i=0;
    
    // We have a status line for like, is FONA working
    #define STATUS_X 10
    #define STATUS_Y 65
    
    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    uint16_t buttoncolors[15] = {ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED, 
                                 ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, 
                                 ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, 
                                 ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, 
                                 ILI9341_ORANGE, ILI9341_BLUE, ILI9341_ORANGE};
    Adafruit_GFX_Button buttons[15];
    
    // Print something in the mini status bar with either flashstring
    void status(const __FlashStringHelper *msg) {
      tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
      tft.setCursor(STATUS_X, STATUS_Y);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.print(msg);
    }
    // or charstring
    void status(char *msg) {
      tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
      tft.setCursor(STATUS_X, STATUS_Y);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(1);
      tft.print(msg);
    }
    
    void setup() {
      Serial.begin(9600);
      Serial.println("Arduin-o-Phone!"); 
      
      // clear the screen
      tft.begin();
      tft.fillScreen(ILI9341_BLACK);
      
      // eep touchscreen not found?
      if (!ts.begin()) {
        Serial.println("Couldn't start touchscreen controller");
        while (1);
      }
      Serial.println("Touchscreen started");
    
      // create buttons
      for (uint8_t row=0; row<5; row++) {
        for (uint8_t col=0; col<3; col++) {
          buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X), 
                     BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
                      BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
                      buttonlabels[col + row*3], BUTTON_TEXTSIZE); 
          buttons[col + row*3].drawButton();
        }
      }
      
      // create 'text field'
      tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);
    
      /*
      status(F("Checking for FONA..."));
      // Check FONA is there
      fonaSS.begin(4800); // if you're using software serial
    
      // See if the FONA is responding
      if (! fona.begin(fonaSS)) {           // can also try fona.begin(Serial1) 
        status(F("Couldn't find FONA :("));
        while (1);
      }
      status(F("FONA is OK!"));
      
      // Check we connect to the network
      while (fona.getNetworkStatus() != 1) {
        status(F("Looking for service..."));
        delay(100);
      }
      status(F("Connected to network!"));
     
      // set to external mic & headphone
      fona.setAudio(FONA_EXTAUDIO);
      */
    }
    
    
    void loop(void) {
      TS_Point p;
      
      if (ts.bufferSize()) {
        p = ts.getPoint(); 
      } else {
        // this is our way of tracking touch 'release'!
        p.x = p.y = p.z = -1;
      }
      
      // Scale from ~0->4000 to tft.width using the calibration #'s
      if (p.z != -1) {
        p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
        p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
        Serial.print("("); Serial.print(p.x); Serial.print(", "); 
        Serial.print(p.y); Serial.print(", "); 
        Serial.print(p.z); Serial.println(") ");
      }
      
      // go thru all the buttons, checking if they were pressed
      for (uint8_t b=0; b<15; b++) {
        if (buttons[b].contains(p.x, p.y)) {
          //Serial.print("Pressing: "); Serial.println(b);
          buttons[b].press(true);  // tell the button it is pressed
        } else {
          buttons[b].press(false);  // tell the button it is NOT pressed
        }
      }
    
      // now we can ask the buttons if their state has changed
      for (uint8_t b=0; b<15; b++) {
        if (buttons[b].justReleased()) {
          // Serial.print("Released: "); Serial.println(b);
          buttons[b].drawButton();  // draw normal
        }
        
        if (buttons[b].justPressed()) {
            buttons[b].drawButton(true);  // draw invert!
            
            // if a numberpad button, append the relevant # to the textfield
            if (b >= 3) {
              if (textfield_i < TEXT_LEN) {
                textfield[textfield_i] = buttonlabels[b][0];
                textfield_i++;
    	    textfield[textfield_i] = 0; // zero terminate
                
               // fona.playDTMF(buttonlabels[b][0]);
              }
            }
    
            // clr button! delete char
            if (b == 1) {
              
              textfield[textfield_i] = 0;
              if (textfield > 0) {
                textfield_i--;
                textfield[textfield_i] = ' ';
              }
            }
    
            // update the current text field
            Serial.println(textfield);
            tft.setCursor(TEXT_X + 2, TEXT_Y+10);
            tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
            tft.setTextSize(TEXT_TSIZE);
            tft.print(textfield);
    
            // its always OK to just hang up
            if (b == 2) {
              status(F("Hanging up"));
             // fona.hangUp();
            }
            // we dont really check that the text field makes sense
            // just try to call
            if (b == 0) {
              status(F("Calling"));
              Serial.print("Calling "); Serial.print(textfield);
              
             // fona.callPhone(textfield);
            }
            
          delay(100); // UI debouncing
        }
      }
    }

  18. #18
    Senior Member
    Join Date
    Apr 2017
    Posts
    162
    yep, that's the map function, i just hard coded the TS_MINX with the actual value--but again you may only need to swap the x-y if you are rotating your screen. I would dump the p.x and p.y before and after the map function to a serial monitor and see if where you press is what's determined by the touch lib. I recall some odd mapping in the adafruit libs on some displays. but if you monitor the screen coordinates it could save a ton of time figuring out what the map values are.

    I'm using the same button thingy as a numeric data entry screen in one of my projects--it's pretty cool. I'm also using custom fonts for a very professional look. None of this could be done on an UNO due to low memory. I have around 1200 lines of code and 6 or so libs and i'm around 55% memory capacity on the Teensy. Great product.

  19. #19
    Hi,

    i have RA8875, 5" tft resistive touchscreen for adafruit.

    the code below don't show label on buttons.

    Code:
    ...
    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    
    uint16_t buttoncolors[15] = {RA8875_MAGENTA, RA8875_CYAN, RA8875_RED, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_GREEN, RA8875_BLUE, RA8875_GREEN};
    ...
    
     
      // With hardware accelleration this is instant
      tft.fillScreen(RA8875_BLACK);
     
       // create buttons
      for (uint8_t row=0; row<5; row++) 
        {
          for (uint8_t col=0; col<3; col++)
          {
            buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X), BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
                        BUTTON_W, BUTTON_H, RA8875_WHITE, buttoncolors[col+row*3], RA8875_WHITE,
                        buttonlabels[col + row*3], 2); 
                      
            buttons[col + row*3].drawButton(false);
           
          }
      }
    
    ...
    Hardware work well, all example from Adafruit_RA8875 work.
    I do not see where the problem comes from this code.

    Click image for larger version. 

Name:	20190128_180821.jpg 
Views:	14 
Size:	53.4 KB 
ID:	15766


    all code is below

    Code:
    /******************************************************************
     This is an example for the Adafruit RA8875 Driver board for TFT displays
     ---------------> http://www.adafruit.com/products/1590
     The RA8875 is a TFT driver for up to 800x480 dotclock'd displays
     It is tested to work with displays in the Adafruit shop. Other displays
     may need timing adjustments and are not guanteed to work.
     
     Adafruit invests time and resources providing this open
     source code, please support Adafruit and open-source hardware
     by purchasing products from Adafruit!
     
     Written by Limor Fried/Ladyada for Adafruit Industries.
     BSD license, check license.txt for more information.
     All text above must be included in any redistribution.
     ******************************************************************/
    
    #include <SPI.h>
    #include "Adafruit_GFX.h"
    #include "Adafruit_RA8875.h"
    
    // Library only supports hardware SPI at this time
    // Connect SCLK to UNO Digital #13 (Hardware SPI clock)
    // Connect MISO to UNO Digital #12 (Hardware SPI MISO)
    // Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
    #define RA8875_INT 3
    #define RA8875_CS 10
    #define RA8875_RESET 9
    
    Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
    
    // This is calibration data for the raw touch data to the screen coordinates
    #define TS_MINX 62
    #define TS_MINY 153
    #define TS_MAXX 924
    #define TS_MAXY 917
    
    /******************* UI details */
    #define BUTTON_X 40
    #define BUTTON_Y 100
    #define BUTTON_W 60
    #define BUTTON_H 30
    #define BUTTON_SPACING_X 20
    #define BUTTON_SPACING_Y 20
    #define BUTTON_TEXTSIZE 2
    
    // text box where numbers go
    #define TEXT_X 10
    #define TEXT_Y 10
    #define TEXT_W 220
    #define TEXT_H 50
    #define TEXT_TSIZE 3
    #define TEXT_TCOLOR RA8875_WHITE
    
    // the data (phone #) we store in the textfield
    /*#define TEXT_LEN 12
    char textfield[TEXT_LEN+1] = "";
    uint8_t textfield_i=0;*/
    
    // We have a status line for like, is FONA working
    #define STATUS_X 10
    #define STATUS_Y 65
    
    /* create 15 buttons, in classic candybar phone style */
    char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
    
    uint16_t buttoncolors[15] = {RA8875_MAGENTA, RA8875_CYAN, RA8875_RED, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_BLUE, RA8875_BLUE, RA8875_BLUE, 
                                 RA8875_GREEN, RA8875_BLUE, RA8875_GREEN};
    
    Adafruit_GFX_Button buttons[15];
    
    
    
    // Print something in the mini status bar with either flashstring
    void status(const __FlashStringHelper *msg) {
      tft.fillRect(STATUS_X, STATUS_Y, 240, 8, RA8875_BLACK);
      tft.setCursor(STATUS_X, STATUS_Y);
      tft.setTextColor(RA8875_WHITE);
      tft.setTextSize(1);
      tft.print(msg);
    }
    // or charstring
    void status(char *msg) {
      tft.fillRect(STATUS_X, STATUS_Y, 240, 8, RA8875_BLACK);
      tft.setCursor(STATUS_X, STATUS_Y);
      tft.setTextColor(RA8875_WHITE);
      tft.setTextSize(1);
      tft.print(msg);
    }
    
    
    uint16_t tx, ty;
    
    void setup() 
    {
       
      Serial.begin(9600);
      Serial.println("RA8875 start");
      delay(2000);
      /* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */
      if (!tft.begin(RA8875_800x480)) {
        Serial.println("RA8875 Not Found!");
        while (1);
      }
    
      Serial.println("Found RA8875");
    
      tft.displayOn(true);
      tft.GPIOX(true);      // Enable TFT - display enable tied to GPIOX
      tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
      tft.PWM1out(255);
    
      // With hardware accelleration this is instant
      tft.fillScreen(RA8875_BLACK);
     
       // create buttons
      for (uint8_t row=0; row<5; row++) 
        {
          for (uint8_t col=0; col<3; col++)
          {
            buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X), BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
                        BUTTON_W, BUTTON_H, RA8875_WHITE, buttoncolors[col+row*3], RA8875_WHITE,
                        buttonlabels[col + row*3], 2); 
                      
            buttons[col + row*3].drawButton(false);
           
          }
      }
      
       // create 'text field'
      tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, RA8875_WHITE);
      
      /*status(F("Checking for FONA..."));
      delay(1000);
      status(F("Connected to network!"));*/
    
      pinMode(RA8875_INT, INPUT);
      digitalWrite(RA8875_INT, HIGH);
      
      tft.touchEnable(true);
        
      Serial.print("Status: "); Serial.println(tft.readStatus(), HEX);
      Serial.println("Waiting for touch events ...");
    }
    
    void loop() 
    {
      float xScale = 1024.0F/tft.width();
      float yScale = 1024.0F/tft.height();
    
      /* Wait around for touch events */
      if (! digitalRead(RA8875_INT)) 
      {
        if (tft.touched()) 
        {
          Serial.print("Touch: "); 
          tft.touchRead(&tx, &ty);     
          Serial.print(tx); Serial.print(", "); Serial.println(ty);
          /* Draw a circle */
          tft.fillCircle((uint16_t)(tx/xScale), (uint16_t)(ty/yScale), 4, RA8875_WHITE);
         
        } 
      }
    }
    thanks for your help.

  20. #20
    I found the problem, is not possible to use tft.print with graphics mode, for print text i use the code below and it work.

    Code:
    void printLabel(Adafruit_RA8875 *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h, uint16_t fillColor, uint16_t textcolor, char *label, uint8_t textsize)
    {  
      tft.textMode();
      tft.textSetCursor(x1 + (w/2) - (strlen(label) * 3 * textsize), y1 + (h/2) - (4 * textsize));
      tft.textColor(textcolor, fillColor);
      tft.textEnlarge(0);
      tft.textWrite(label);
      tft.graphicsMode();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •