element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design for a Cause - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Design for a Cause - Design Challenge
  • More
  • Cancel
Design for a Cause - Design Challenge
Blog Need Assistance
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: roborob1266
  • Date Created: 30 Aug 2018 7:24 PM Date Created
  • Views 2295 views
  • Likes 2 likes
  • Comments 4 comments
  • ra8875
  • tft screen
  • adafruit vs1053 mp3 player
  • 5" touch screen
  • design for a cause design challenge
  • sd
  • mp3 player
Related
Recommended

Need Assistance

roborob1266
roborob1266
30 Aug 2018

Hello All

I can get the image on the screen just fine but when I touch the image, the system reboots so I went with a suggestion for now just to draw a rectangle and put code to it.

Here is the code I am using and I can get the rectangles to display, the text to appear inside but the code for touching the screen and playing an associated MP3 file is not working .

 

Can anyone see what could be the problem.

 

Here is my entire code for the RA and VS devices...

 

First everything is tested and a sine wave plays to ensure that the audio player is working.
Then I draw out the rectangles with the phrases inside.Then I detect the touches which put out the X and Y points touched.

Finally, I have it where the display is touched within certain X&Y points, it should play an MP3 audio file depending on where you touch and that is not working.

Any suggestions is appreciated on how to get the audio to play when the screen is touched is appreciated!

 

 

#include <SPI.h>

#include "Adafruit_GFX.h"

#include "Adafruit_RA8875.h"

#include <Adafruit_VS1053.h>

#include <SD.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 2

#define RA8875_CS 9

#define RA8875_RESET 8

#define RA8875_X+ A1

#define RA8875_X- A2

#define RA8875_Y+ A3

#define RA8875_Y- A4

 

 

#define CLK 13       // SPI Clock, shared with SD card

#define MISO 12      // Input data, from VS1053/SD card

#define MOSI 11      // Output data, to VS1053/SD card

 

 

#define SHIELD_RESET -1      // VS1053 reset pin (unused!)

#define SHIELD_CS 7      // VS1053 MCS - chip select pin (output)

#define SHIELD_DCS 6 // VS1053 DCS - data select pin (output)

#define CARDCS 4     // VS1053 CCS - Card chip select pin

#define DREQ 3       // VS1053 DREQ - Data request, ideally an Interrupt pin

 

 

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);;

 

 

Adafruit_GFX_Button btn1;

uint16_t tx, ty;

 

 

void setup()

{

  Serial.begin(9600);

  Serial.println("RA8875 start");

 

 

  /* 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");

 

 

    /* Initialize the music player */

  if (! musicPlayer.begin()) {

    Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));

    while (1);

}

  Serial.println(F("VS1053 found"));

 

  musicPlayer.sineTest(0x44, 500);    // Makes a tone to indicate VS1053 is working

  Serial.println(F("VS1053 Audio Test Completed - Beep"));

 

    if (!SD.begin(CARDCS)) {

    Serial.println(F("SD failed, or not present"));

    while (1);  // don't do anything more

  }

   Serial.println(F("SD Found"));

 

 

    // Set volume for left, right channels. lower numbers == louder volume!

  musicPlayer.setVolume(5,5);

 

 

  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_WHITE);

 

 

  pinMode(RA8875_INT, INPUT);

  digitalWrite(RA8875_INT, HIGH);

 

  tft.touchEnable(true);

   

  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);

  tft.fillScreen(RA8875_BLACK);

 

 

/* Switch to text mode */ 

  tft.textMode();

 

  /* Set the cursor location (in pixels) */

  tft.textSetCursor(10,10);

 

 

  // PWM Use

  for (uint8_t i=255; i!=0; i-=5 )

  {

    tft.PWM1out(i);

    delay(10);

  } 

  for (uint8_t i=0; i!=255; i+=5 )

  {

    tft.PWM1out(i);

    delay(10);

  }

  tft.PWM1out(255);

 

  tft.fillScreen(RA8875_RED);

  delay(500);

  tft.fillScreen(RA8875_YELLOW);

  delay(500);

  tft.fillScreen(RA8875_GREEN);

  delay(500);

  tft.fillScreen(RA8875_CYAN);

  delay(500);

  tft.fillScreen(RA8875_MAGENTA);

  delay(500);

  tft.fillScreen(RA8875_BLACK);

 

  // GFX acceleration

  // first number indicates where box starts (600)

  // second number indicates how far from the top it starts (10)

  // third number indicates how wide the box is (200)

  // fourth number indicates how high the box is (100)

  tft.drawRect(10, 150, 300, 200, RA8875_GREEN);

  tft.drawRect(350, 10, 200, 200, RA8875_CYAN);

  tft.drawRect(575, 10, 200, 200, RA8875_CYAN);

  tft.drawRect(350, 255, 200, 200, RA8875_CYAN);

  tft.drawRect(575, 255, 200, 200, RA8875_CYAN);

 

 

 

 

  /* Change the cursor location and color ... */

  // first number indicates how far from the left side the screen the words are (40)

  // second number indicates what how far from the top of the screen it is (210)

  tft.textSetCursor(40, 210);

  tft.textTransparent(RA8875_WHITE);

  tft.textEnlarge(3);

  tft.textWrite("I Want");

 

 

  tft.textSetCursor(350, 38);

  tft.textTransparent(RA8875_WHITE);

  tft.textEnlarge(2);

  tft.textWrite("A Drink");

 

  tft.textSetCursor(575, 38);

  tft.textTransparent(RA8875_WHITE);

  tft.textEnlarge(2);

  tft.textWrite("My iPad");

 

 

  tft.textSetCursor(350, 275);

  tft.textTransparent(RA8875_WHITE);

  tft.textEnlarge(2);

  tft.textWrite("To Eat");

 

  tft.textSetCursor(575, 275);

  tft.textTransparent(RA8875_WHITE);

  tft.textEnlarge(2);

  tft.textWrite("Potty");

}

void loop()

{

  float xScale = 1024.0F/tft.width();

  float yScale = 1024.0F/tft.height();

 

int Xposn, Yposn;              

 

 

    if (tft.touched()) {          //Verify the touched area

      tft.touchRead(&tx, &ty);

      Serial.print(F("Touch: "));

      Serial.print(tx); Serial.print(", "); Serial.println(ty);

  

               if (tx > 580 && tx < 680 && ty > 370 && ty < 535)

 

 

// code to try and get the touch screen areas to play a file when touched

    if ((tx>=80) && (tx<=400) && (ty>=370) && (ty<=700)) 

         {musicPlayer.startPlayingFile("001.mp3");}

    if ((tx>=440) && (tx<=690) && (ty>=160) && (ty<=470))

         {musicPlayer.startPlayingFile("002.mp3");}

    if ((tx>=730) && (tx<=930) && (ty>=180) && (ty<=480))

         {musicPlayer.startPlayingFile("003.mp3");}

    if ((tx>=460) && (tx<=690) && (ty>=570) && (ty<=875))

         {musicPlayer.startPlayingFile("004.mp3");}

    if ((tx>=730) && (tx<=947) && (ty>=930) && (ty<=913))

          {musicPlayer.startPlayingFile("005.mp3");}

    }

  }

  • Sign in to reply

Top Comments

  • 14rhb
    14rhb over 7 years ago +1
    Hi Rob, You could try adding an infinite loop after you print "Touch" to see if there is any issue before that [e.g. while(1).... ]. Then move that loop and/or add other serial.print statements to see…
  • jomoenginer
    jomoenginer over 7 years ago +1
    Two things I would look at are the hardware that you are using as well as the libraries that are used. I have found in some instances when using multiple devices connected to an Arduino board that the…
  • roborob1266
    roborob1266 over 7 years ago in reply to 14rhb +1
    Hi Rod, That line of code was in the original code I had looked at and after I commented it out and uploaded the sketch, it didn't make a difference so I removed it from the code. Thanks for pointing that…
  • roborob1266
    roborob1266 over 7 years ago in reply to 14rhb

    Hi Rod,

    That line of code was in the original code I had looked at and after I commented it out and uploaded the sketch, it didn't make a difference so I removed it from the code.

    Thanks for pointing that out.

     

    Jon,

    There were no errors reported via the Serial monitor when I touched the image on the screen and it rebooted.

    I will try that sketch again and run some serial statements to help troubleshoot it.

    I am utilizing the MP3 Players SD reader to put the image on the 5" TFT display.
    If I comment it out, I will not be able to get the image to transfer over.I tried one large image (800X480) as well as a smaller image (300X240) and it still did the same thing.

    I will troubleshoot it let everyone know what happened to fix it!

    I do have code to print out the touch events as well and the serial monitor shows the X,Y point as the thing reboots and starts up. Its not a hard reboot cause the serial monitor never clears out, it just appends.

    For the RA8875 module and the VS1053, I use the UNO and for the Ultrasonic Sensor and the ADXL335EB, I use the MKR1000 for this part of the project.

    Thank you for your comments!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • roborob1266
    roborob1266 over 7 years ago

    I was able to resolve the audio issue. I had to change it from startPlayingFile to playFullFile and the audio files started to play when I touched specific spots on the display!

    For now I am going with the rectangle boxes with the text inside and get the audio playing with these boxes.


    The next revision of this device will include the following:

    1. Actual images instead of text.

    2. Connect a battery to both the Arduino devices to work without USB power.

    3. Enable a screen time out to save power.

    4. Get the accelerometer to detect when the device is picked up and "wake" the screen up.

    5. Enable the Ultrasonic Sensor display on the LCD, the distance it is from an object.

     

    I am going to submit my completed project now!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 7 years ago

    Two things I would look at are the hardware that you are using as well as the libraries that are used.  I have found in some instances when using multiple devices connected to an Arduino board that the libraries that are created for each device could conflict with each other,  specifically with how the lib is configuring the IO ports. 

     

    Do you get any error listed in the Arduino IDE console window when this event is seen?

    Also, you have some serial print statements in the code, so are you watching these to see where the code may be getting hung up at?

     

    Do you still see the issue if you taking out the musicPlayer statements and just maybe print out a note indicating that a touch event occurred?

     

    What Arduino board are you using?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • 14rhb
    14rhb over 7 years ago

    Hi Rob,

     

    You could try adding an infinite loop after you print "Touch" to see if there is any issue before that [e.g. while(1).... ]. Then move that loop and/or add other serial.print statements to see how far you get and which bit crashes the system.

     

    There isn't anything after your first if statement ...

    if (tx > 580 && tx < 680 && ty > 370 && ty < 535)

    not sure what happens there?

     

    For info, if you select your code and then use the >> action button, syntax highlighting and then C++, your post will format nicer. You can use the edit button to that effect rather than reposting.

     

    Rod

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube