Problem with Freeduino Mega, ethernet shiled, tft ST7735 and SPI

Hi all,

I'm planning to enjoy a weather station with a Freeduino Mega 2560 to display the data on a TFT 1.8 "LCD and then records them on the portal COSM.COM as feed.
Well, but here lies the problem. The library SPI controls both the ethernet shield is the small display 1.8 "TFT ST7735, and then following the directions I found on the internet, first off the SS pin of the ethernet shield (I think it's 53) then enable the SS pin display (SS = 7) visualize the data correctly, the pin off of the display, the active pin ethernet shield and forwarding the data on the internet, finally turning off the SS pin of said shield.
But when I get to the point of sending data over the internet, the project stops.
the problem as I said is right in the SPI library management, someone who has already had to deal with this library can check the code and give me some tips? the ethernet shield on a Freeduino Mega 2560 has the SS on pin 53?
The ethernet shield is connected to an AP TP-LINK TL-MR3020, configured as a client and connected to another router with ADSL, WiFi everything to make the project (also this AP also supports the Internet Key as well as having the opportunity be programmed as a client and in bridge mode).

Thank you in advance for any straight that solves the problem described.

I enclose a sketch (still quite primitive) and libraries used (data for COSM.COM not Real, only test):

Files and libraries on: https://github.com/icnmfabro/meteofabro

first off the SS pin of the ethernet shield (I think it's 53)

This is wrong. The SS of the Ethernet Shield is always pin 10, also on the Mega.

You can take a look at the sketch, is located here:
https://github.com/icnmfabro/meteofabro

however, should always be turned off in the sketch? activated or when I use the ethernet?

The w5100 slave select is digital pin 10 on any Arduino.
Change your setup to disable all the SPI interfaces first.

void setup() {
  
    // disable w5100 SPI
    pinMode (ss, OUTPUT);
    digitalWrite(ss,HIGH);

    // disable TFT SPI
    pinMode (ss1, OUTPUT);
    digitalWrite(ss1,HIGH);

    // disable SD SPI if using an SD card
    // pinMode (4, OUTPUT);
    // digitalWrite(4,HIGH);
    
    Serial.begin(9600);
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();
    // start the SPI library:

    while (Ethernet.begin(mac) != 1)
    {
      Serial.println("Error getting IP address via DHCP, trying again...");
      delay(15000);
    }
    // the Ethernet.begin() function leaves pin 10 LOW (SPI enabled), so back to HIGH
    digitalWrite(ss,HIGH);

    // rest of your setup stuff

Does that do any better?

nothing - it does not work, perhaps there is something I do not understand ... any other suggestions?. but does anyone know where to find a sketch of reference that combines both devices? TFT LCD + Ethernet with SPI? HELPPPP.
I found a sketch that works with the TFT and the ethernet shield but 023 for the compiler and libraries are still quite dated. must modify the library del'ST7735?

Nothing? No LEDs light at all? Then the board or power supply has failed.

edit: You must be more specific than "nothing" if you want help. Do you get any output on the serial monitor? I recommend adding some serial output to your setup function so you can troubleshoot that section.

Did you try these devices separately? Does the ethernet work ok if used alone? Does that TFT display have a microSD card slot? Is there a card in the slot? What pin is the SD slave select on?

It all works separately with the same PIN and with the same cables DuPoint, the TFT turns on but nothing is displayed, white screen, then the ethernet shield hangs. tried to debug the code with the Serial.print but also locks the serial monitor. SD card is a memory card 2GB but not used. yet at least in this part of the code. however, or even tried to remove it but arduino crashes too ...

Try this code to start. It downloads Google home every 30 seconds. I know it will work with other SPI compatible devices.
http://www.arduino.cc/playground/Code/WebClient
Change the network settings, the server to your server ip and page.

After the Serial.begin(9600) call in setup, add this:

  // disable TFT SPI
  pinMode(6,OUTPUT);
  digitalWrite(6,HIGH);

Your code has pin 6 as the slave select for the TFT display. Is that still correct?

Does that part work ok?

thanks for the test code. this I have slightly modified your code to test the ethernet shield combined with the ST7735 tft looks like it works. I left arduino work for two hours and you are not stuck - it the ethernet shield nor the ST7735. but then where is the problem of the blocks and no views of my code? any ideas? I entered the CS in the ST7735 PIN 7, to help organize the wiring.
you think may be the sensors that stop? however, if not the whole code for the ethernet shield everything works fine.
The project consists of:

  • 1 Freeduino Mega 2560
  • 1 ethernet shield
  • 1 sensor BMP085 on i2c 3V
  • 1 converter logic level hardware
  • 1 RTC to keep time on i2c 5V
  • 1 DHT22 5V on pin 14
  • 1 PIR switch dell'ST7735 or to display data in the presence of humans (but still connected in breadborad to write the code).

If you want to send you detail photos of the project.

this is your code modified by myself to the test:

/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Posted October 2012 by SurferTim
*/



#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,20);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(74,125,227,16); // Google
//IPAddress server(173,194,35,191); // Google

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[32];
// Define pins and Libraries of TFT LCD 1.8"
//#define sclk 13
//#define mosi 11
#define ss1  7
#define dc   9
#define rst  -1  // you can also connect this to the Arduino reset
Adafruit_ST7735 tft = Adafruit_ST7735(ss1, dc, rst);
int i = 1;
void setup() {
  Serial.begin(9600);
  
  // disable TFT SPI
  pinMode(7,OUTPUT);
  digitalWrite(7,HIGH);
  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println("Starting ethernet...");
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println("failed");
  // else Serial.println("ok");

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println("Ready");
  tft.initR(INITR_REDTAB);   // initialize a ST7735R chip, red tab
}

void loop()
{
  digitalWrite(10, LOW);
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print("connecting...");

  if(client.connect(ipBuf,80))
  {
    Serial.println("connected");

    sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
    client.write(outBuf);
  }
  else
  {
    Serial.println("failed");
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println("Timeout");
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println("disconnecting.");
  // close client end
  client.stop();
  digitalWrite(10,HIGH);
  digitalWrite(7, LOW);
  tft.setTextWrap(true);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 5);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);

  tft.setTextColor(ST7735_GREEN);
  tft.println("   Weather Station");
  tft.println("       Fabro1");
  
  Serial.print(i++);
  tft.println(i++);
digitalWrite(7,HIGH);
  return 1;
}

Do not modify pin 10 after the setup function. Delete the "digitalWrite(10,LOW);" from the loop() function. The ethernet library code handles that pin really well. Unless you are in a "client." call, that pin is HIGH, and should be left that way.

I recommend separating the two functions. Leave the getPage function alone. Now write another function that handles the ST7735 display. You may need to use global variables to pass data from one function to the other.

    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");

    // add a function like this here
    displayTFT();

    totalCount++;

Then add a function like this at the end:

void displayTFT() {
    Serial.println("TFT");
}

Do you see the pattern?

hello .. sorry for the delay ...
I'll send you the plan drawn up with fritzing, with your experience can you tell me if at the level of energy we return? I would not pastasse the current or amperes. I'm using a alimetatore from 9V/1000mA.
someone tell me if the schema of the sensors, freeduino, ethernet shield and tft 1.8 "is suitable?

Fritzing Project Weather Station Fabro1.pdf (775 KB)

MeteoFabro1_ETH_LCD1.8.fzz (110 KB)