ili9340 and virtual wire

Hi,

In my project, I use several library : SPI AdafruitGFX, AdafruitILI9340 and virtualwire.

It seems there is a conflict with virtualwire.
When I try to compile my sketch, I have an error message "tft.begin() tft was not declared in this scope".My tft screen work fine without the others library.

I did a mistake?

starjuice:
I did a mistake?

Obviously. What it was is anyone's guess since we can't see your code.

with the code

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9340.h> 
#define _rst 8
#define _dc 9
      #define _miso 50
      #define _mosi 11
      #define _sclk 13
      #define _cs 10
#include <VirtualWire.h>
const int transmit_ptt_pin = 3;
const int receive_pin = 12;
const int transmit_pin = 5;
float Nombre;
float Consigne=0;
char Message[VW_MAX_MESSAGE_LEN]; 
char Messageenvoi[VW_MAX_MESSAGE_LEN];


void setup() {
  tft.begin();
  Serial.begin(9600);     
  vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_ptt_pin);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(1000);       // Bits per sec
    Serial.println("en fonction");
}

void loop(){
  
  
   vw_rx_start();
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  
  if (vw_get_message(buf, &buflen))
  {
    int i;

    for (i = 0; i < buflen; i++)
    {               
      Message[i] = char(buf[i]);
    }

    Message[buflen] = '\0';

    // Conversion du tableau de chars en int:
    Nombre = atol(Message);
    
     Serial.println(Nombre);
     vw_rx_stop();
     // si recu une demande de consigne avec 111 en reception     
     if (Nombre==111)
          {
       // Conversion du int en tableau de chars appelé "Message"
       Serial.println("envoi consigne");
       Consigne++;
       int Consigne100 =Consigne*100;
        itoa(Consigne100,Messageenvoi,10);  
}

You don't have any variable of any type defined in this code called tft.

Do one of those libraries have such a variable defined? Maybe you need an extern declaration for it.

yes of course, tft is declared inside the libraries.
usually i don't need to declare it.

starjuice:
yes of course, tft is declared inside the libraries.
usually i don't need to declare it.

Well, you don't seem very keen to share this code so good luck to you. I would try to help you solve this problem if I could see all these libraries and what was defined where. But you want me to guess and I don't play guessing games. Maybe posting those libraries or at least links to those libraries will help someone else try to help you.

it's standard libraries, maybe you don't know adafruit...

starjuice:
it's standard libraries, maybe you don't know adafruit...

OK, don't share links. Don't know what it would cost you to do that but if you don't want to I can't make you. Maybe someone comes along that knows those libraries already. Maybe not. It's your problem, if you don't want it solved that's up to you.

If you don't know these libraries please don't try to help me. Otherwise it's just for increase your counter message.

starjuice:
If you don't know these libraries please don't try to help me. Otherwise it's just for increase your counter message.

No, I really want to help. I'm really trying. But I don't have that code so I can't. If I could see that code I could tell you what the issue was in a second. I could care less about post count. I don't appreciate the accusation.

Again, I don't know what it costs you to link us to it. Guess we'll never know what your issue was.

From How to Use This Forum

If you are using a library that does not come with the IDE (in other words, you downloaded it from somewhere) please post a link to this library.

starjuice:
GitHub - adafruit/Adafruit_ILI9340: This is a library for the Adafruit 2.2" SPI display.

Wasn't so hard now was it?

That file doesn't define anything by the name "tft" either. Looks like you should have that definition in your sketch.

ok. Using the adafruit librarie like my project I’m able to compile this one. please let me know where tft is declared.

 /*
                  affiche_geo
            Affichage de figures géomètriques par MEGA 2560
            sur l'afficheur ILI9340
      */
      #include <SPI.h>
      #include <Adafruit_GFX.h>
      #include <Adafruit_ILI9340.h>
     
      // broches utilisées sur la MEGA2560
      #define _rst 48
      #define _dc 49
      #define _miso 50
      #define _mosi 51
      #define _sclk 52
      #define _cs 53
      Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
      void setup()
      {
            tft.begin();
            tft.fillScreen(ILI9340_BLACK);
            essaiLignes();
            essaiCercles();
            essaiRectangle();
            essaiTriangle();
      }
      void loop(void)
      {
      // on ne fait rien
      }
      void essaiCercles() {
            int x, y, r2 = 20,
            w = tft.width() + 10,
            h = tft.height() + 10;
     
            tft.drawCircle(120, 160, 80, 0xFFE0);
            tft.drawCircle(120, 160, 79, 0xFFE0);
            tft.drawCircle(120, 160, 78, 0xFFE0);
            tft.drawCircle(120, 160, 77, 0xFFE0);
            tft.drawCircle(120, 160, 76, 0xFFE0);
      }
      void essaiRectangle()
      {
            tft.drawRect(80, 120, 80, 80, ILI9340_CYAN);
            tft.drawRect(82, 122, 76, 76, ILI9340_CYAN);
            tft.drawRect(84, 124, 72, 72, ILI9340_CYAN);
            tft.drawRect(86, 126, 68, 68, ILI9340_CYAN);
      }
      void essaiTriangle()
      {
            int n, i, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1;
           
     
            n = min(cx, cy);
            for(i=0; i<n; i+=20) {
                  tft.drawTriangle(
                  cx , cy - i, // peak
                  cx - i, cy + i, // bottom left
                  cx + i, cy + i, // bottom right
                  tft.Color565(255, 64, 255));
            }
      }
      void essaiLignes()
      {
            int x1, y1, x2, y2,
            w = tft.width(),
            h = tft.height();
            x1 = y1 = 0;
            y2 = h - 1;
            for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, ILI9340_CYAN);
                  x2 = w - 1;
            for(y2=0; y2<h; y2+=6)
                  tft.drawLine(x1, y1, x2, y2, ILI9340_GREEN);
      }

starjuice:
ok. Using the adafruit librarie like my project I'm able to compile this one. please let me know where tft is declared.

First line after the #defines, last line before setup():

Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);

ok you're right :slight_smile: