본문 바로가기

프로그래밍/아두이노01- 제품개발

아두이노 wifi shield 개발 - 6. 아두이노 + 아두이노 와이파이쉴드 + tft lcd

아두이노, 아두이노 와이파이쉴드, tftlcd(정품)은 사실 같이 쓰지못한다 그이유는 mcu관계에 있어서 서로 slave, master관계가 되어 작동이 되는데(MISO : Master In Slave Out / MOSI : Master Out Slave In) 이 관계는 2개의 관계까지 되기 때문이다. 

아두이노와 와이파이쉴드 그리고 tftlcd(정품)과 아두이노의 관계가 그와 같다. 이같은 상황에서 세개의 칩들을 꼽게 되면 문제가 누가 슬레이브인지 누가 마스터인지 정할수 없는 상황이 되어 작동불능상태에 이른다.


이상황을 해결하기 위해 필요한 MISO / MOSI만 사용하고 나머지는 버리는 방식을 사용하였다. 그중 하나가 TFT LCD에 있는 SD카드를 포기하는 것이다. Arduino Tft lcd(정품)에는 sd카드 슬랏이 붙여져 있는데 그것을 포기하는 핀 제작방식을 사용하면 3개가 동시에 잘 작동하게 된다.




아두이노 UNO R3


아두이노 WIFI shield



아두이노 wifi shield pin manual


Arduino TFT LCD with SD card



--------------------해당소스코드-------------------------

---------------핀설정사진은 코드로 갈무리한다. --------------

-------코드가 매우 지저분해도 양해부탁드림.-------------------

-------빨강색글자가 wifi 와 tft관련 코드이다.------------------


#include <SPI.h>

#include <WiFi.h>

#include <Servo.h> 

#include <OneWire.h>

#include <TFT.h> 

#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

#define SERVO_BUS 3

#define cs   6

#define dc   5

#define rst  4

#define led 2

#define init_servo 50

#define move_servo 90


OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

Servo myservo;

TFT TFTscreen = TFT(cs, dc, rst);

double init_temp;

double init_ph;

char sensorPrintout[5];

char sensorPrintout2[4];

String sensorVal;

String sensorVal2;

char ssid[] = "coalamovement";

char pass[] = "1234512345";

int keyIndex = 0;

int status = WL_IDLE_STATUS;

WiFiClient client;

int plan=0;

void setup() {

//Initialize serial and wait for port to open:

Serial.begin(9600);

pinMode(led, OUTPUT);

digitalWrite(led, HIGH);

TFTscreen.begin();

TFTscreen.background(0, 0, 204);

TFTscreen.stroke(255, 255, 255);

TFTscreen.setTextSize(2);

TFTscreen.text("  Smart Fish \n Care Service", 0, 10);

myservo.attach(SERVO_BUS);

myservo.write(init_servo);

sensors.begin();

while (!Serial) {

;

// wait for serial port to connect. Needed for Leonardo only

}

// check for the presence of the shield:

if (WiFi.status() == WL_NO_SHIELD) {

Serial.println("WiFi shield not present");

while (true);

}

String fv = WiFi.firmwareVersion();

if ( fv != "1.1.0" )

   Serial.println("Please upgrade the firmware");

while (status != WL_CONNECTED) {

TFTscreen.stroke(255, 255, 255);

TFTscreen.setTextSize(2);

TFTscreen.text("Connecting to \nWIFI...", 0, 50);

Serial.print("Attempting to connect to SSID: ");

Serial.println(ssid);

status = WiFi.begin(ssid, pass);

delay(5000);

}

Serial.println("Connected to wifi");

printWifiStatus();

TFTscreen.stroke(0, 0, 204);

TFTscreen.setTextSize(2);

TFTscreen.text("Connecting to \nWIFI...", 0, 50);

}

void loop() {

        myservo.detach();

init_temp = 0;

init_ph = 0;

sensors.requestTemperatures();

init_temp = sensors.getTempCByIndex(0);

init_ph = 6.7;

int now_temp=25;

int now_ph=6;

TFTscreen.stroke(0, 0, 204);

TFTscreen.text(sensorPrintout, 90, 60);

TFTscreen.text(sensorPrintout2, 100, 80);

TFTscreen.stroke(255, 255, 255);

TFTscreen.setTextSize(2);

TFTscreen.text(" TEMP : ", 0, 60);

sensorVal = String(init_temp);

sensorVal.toCharArray(sensorPrintout, 5);

TFTscreen.text(sensorPrintout, 90, 60);

TFTscreen.text(" PH   : ", 0, 80);

sensorVal2 = String(init_ph);

sensorVal2.toCharArray(sensorPrintout2, 4);

TFTscreen.text(sensorPrintout2, 100, 80);

now_temp=(int)(init_temp*10);

now_ph=(int)(init_ph*10);



Serial.println("START=-----------------------START");

        String option0="";

        String option1="";

        String option2="";

while (client.available()) {

char c = client.read();

Serial.print(c);

                option1+=c;

                if(option0.equals("o")&&option1.equals("k"))

                {

                  Serial.println("OOOOOOOOOOOOKKKKKKKKK");

                  plan=0;

                }

                if(option0.equals("f")&&option1.equals("e"))

                {

                  

                  

                  Serial.println("FEEEEEEEEEEDDDDDDDDDDD");

                  plan=1;

                }

                

                option0="";

                option0+=c;

                option1="";

}

Serial.println("END=-----------------------END");



Serial.println("Starting connection to server...");

char server[] = "www.blogpun.ch";

// name address for Google (using DNS)

// http://blogpun.ch/sfs/cmd.php?who=device&t=20&pH=70&id=1234

client.stop();

if (client.connect(server, 80)) {

//String port1 = "GET /sfs/cmd.php?who=device&t="+now_temp+"&pH="+now_ph+"&id=123123 HTTP/1.1";

String port1 = "GET /sfs/cmd.php?who=device&t=";

port1 +=now_temp;

port1 +="&pH=";

port1 +=now_ph;

port1 +="&id=123123";

                if(plan==1)

                {

                  

                  

               myservo.attach(SERVO_BUS);

               myservo.write(move_servo);

                        delay(500);

               myservo.write(init_servo);

                        delay(500);

                        myservo.detach();

                  

                  port1+="&prevresult=ok";

                }

port1 +=" HTTP/1.1";

char charBuf[90];

port1.toCharArray(charBuf, 90);

Serial.println(charBuf);

client.println(charBuf);

client.println("Host: www.blogpun.ch");

client.println("User-Agent: ArduinoWiFi/1.1");

client.println("Connection: close");

client.println();

Serial.println("connected to server vERYGOODDDDDDDDDDDDDDDDDDDDDD");

} else {

Serial.println("Connection fail XXXX");

}

delay(2000);

}

void printWifiStatus() {

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

Serial.println(ip);

// print the received signal strength:

long rssi = WiFi.RSSI();

Serial.print("signal strength (RSSI):");

Serial.print(rssi);

Serial.println(" dBm");

}