Loop stopt bij print na read touchscreen

Arduino specifieke Software
Berichten: 3
Geregistreerd: 03 Nov 2020, 21:54

Loop stopt bij print na read touchscreen

Berichtdoor jomosoft » 03 Nov 2020, 22:11

Ik ben een touchscreen controlled fm radio aan het maken. alles gaat goed totdat ik tft.print ga gebruiken nadat ik de buttons heb uitgelezen (met de functie displayInfo()). De gezamelijk gebruikte pins worden ge-restored na het lezen van het touchscreen maar toch gaat er iets mis. De main loop loopt vast. Misschien is er hier iemand die ziet wat ik fout doe ?
Code: Alles selecteren
#include  <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
#include <VMA11.h>
#include <Wire.h>

#define MINPRESSURE 200
#define MAXPRESSURE 1000

const int XP = 8, XM = A2, YP = A3, YM = 9; //320x480 ID=0x9486
const int TS_LEFT = 123, TS_RT = 908, TS_TOP = 944, TS_BOT = 91;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button freq_btn, vol_btn, mute_btn, rds_btn, fup_btn, vup_btn, fdown_btn, vdown_btn;

int pixel_x, pixel_y;     //Touch_getXY() updates global vars

int resetPin = 2;
int SDIO = 20;
int SCLK = 21;

VMA11 radio(resetPin, SDIO, SCLK);
int channel;
int volume;
char rdsname[9];
char rdsrt[65];
char previousRadioText[65];
uint8_t lastChar;

void displayInfo()
{
  tft.setCursor(25, 230);
  tft.setTextSize(2);
  tft.setTextColor(BLACK);
  tft.print("Frequentie : "); tft.print(channel);
  tft.print("       Volume : "); tft.print(volume);
}

bool Touch_getXY(void)
{
  TSPoint p = ts.getPoint();
  pinMode(YP, OUTPUT);      //restore shared pins
  pinMode(XM, OUTPUT);
  digitalWrite(YP, HIGH);   //because TFT control pins
  digitalWrite(XM, HIGH);

  bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  if (pressed)
  {
    pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());  //Landscape
    pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
  }
  return pressed;
}

void setup()
{

  uint16_t ID = tft.readID();
  if (ID == 0xD3D3) ID = 0x9486; // write-only shield
  tft.begin(ID);
  tft.setRotation(1);            //PORTRAIT
  tft.fillScreen(BLACK);

  tft.setTextColor(WHITE);               //set text color white
  tft.setTextSize(2);                    //set text size to 2 (1-6)
  tft.println("            JoMoSoft FM Radio");  //print header to screen

  tft.drawRoundRect(10, 20, 460, 300, 6, WHITE); //draw screen outline
  freq_btn.initButton(&tft, 150, 60, 260, 50, WHITE, RED, WHITE, "FREQUENCY", 2);
  fup_btn.initButton(&tft, 375, 60, 50, 50, WHITE, RED, WHITE, "", 2);
  fdown_btn.initButton(&tft, 435, 60, 50, 50, WHITE, RED, WHITE, "", 2);
  vol_btn.initButton(&tft, 150, 120, 260, 50, WHITE, BLUE, WHITE, "VOLUME", 2);
  vup_btn.initButton(&tft, 375, 120, 50, 50, WHITE, BLUE, WHITE, "", 2);
  vdown_btn.initButton(&tft, 435, 120, 50, 50, WHITE, BLUE, WHITE, "", 2);
  mute_btn.initButton(&tft, 310, 120, 40, 50, WHITE, BLUE, WHITE, "X", 3);
  freq_btn.drawButton(false);
  vol_btn.drawButton(false);
  mute_btn.drawButton(false);
  fup_btn.drawButton(false);
  vup_btn.drawButton(false);
  fdown_btn.drawButton(false);
  vdown_btn.drawButton(false);
  tft.fillTriangle(375, 41, 354, 75, 395, 75, WHITE); //draw up triangle for station
  tft.fillTriangle(435, 75, 416, 41, 452, 41, WHITE); //draw down triangle for station
  tft.fillTriangle(375, 100, 354, 134, 395, 134, WHITE); //draw up triangle for volume
  tft.fillTriangle(435, 135, 416, 100, 452, 100, WHITE); //draw down triangle for volume
  tft.fillRoundRect(20, 230, 440, 75, 6, YELLOW); //info box

  radio.powerOn();
  radio.setVolume(1);
  volume = 1;
  channel = 1010;
  radio.setChannel(channel);

  memset(previousRadioText, 0, 65);
  memset(rdsrt, 0, 65);
  Serial.begin(9600);
}

void loop()
{
  bool down = Touch_getXY();
  vup_btn.press(down && vup_btn.contains(pixel_x, pixel_y));
  vdown_btn.press(down && vdown_btn.contains(pixel_x, pixel_y));
  mute_btn.press(down && mute_btn.contains(pixel_x, pixel_y));
  fup_btn.press(down && fup_btn.contains(pixel_x, pixel_y));
  fdown_btn.press(down && fdown_btn.contains(pixel_x, pixel_y));

  if (vup_btn.justReleased())
  {
    volume ++;
    if (volume >= 16) volume = 15;
    radio.setVolume(volume);
  }
  if (vdown_btn.justReleased())
  {
    volume --;
    if (volume < 0) volume = 0;
    radio.setVolume(volume);
  }
  if (mute_btn.justReleased())
  {
    volume = 0;
    radio.setVolume(volume);
  }
  if (fup_btn.justReleased())
  {
    channel = radio.seekUp();
  }
  if (fdown_btn.justReleased())
  {
    channel = radio.seekDown();
  }
  if (radio.readRDSRadioText(rdsrt))
  {

    if (strcmp(rdsrt, previousRadioText))
    {
      Serial.println(rdsrt);
      strcpy(previousRadioText, rdsrt);
    }
  }
  Serial.println(channel);
  displayInfo();
}

Advertisement

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Loop stopt bij print na read touchscreen

Berichtdoor shooter » 04 Nov 2020, 18:33

if radio read .... is dat goed want de tekst moet dan natuurlijk wel weg uit rdsrt want anders blijft het loop daarin draaien
paul deelen
shooter@home.nl

Berichten: 3
Geregistreerd: 03 Nov 2020, 21:54

Re: Loop stopt bij print na read touchscreen

Berichtdoor jomosoft » 04 Nov 2020, 19:20

Ja Paul, dat klopt wel. Als je displayInfo() weg commentarieert dan loopt de main loop helemaal perfect. Zodra ftp.print wordt aangeroepen stopt alles.

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Loop stopt bij print na read touchscreen

Berichtdoor shooter » 05 Nov 2020, 20:33

die ftp zal wel wachten tot iets verzonden is, maar misschien lukt het niet door communicatie fouten
maar er zijn nogal wat libraries aktief en dan wordt het een flink zoekplaatje, zet maar eens een serial.print neer waar je denkt dat het fout gaat.
paul deelen
shooter@home.nl

Berichten: 3
Geregistreerd: 03 Nov 2020, 21:54

Re: Loop stopt bij print na read touchscreen[Opgelost]

Berichtdoor jomosoft » 15 Nov 2020, 09:08

Er bleek uiteindelijk toch een hardware conflict op pin 2 tussen tft shield en radio shield. Kon het alleen oplossen door de radio uit te bouwen en van apparte voeding te voorzien. Ik was er van uit gegaan dat de tft in spi mode zou werken, dat bleek dus niet zo te zijn.

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: adalokuc en 28 gasten