I try to Get a Uno + data / Ethernet shield communicating with the app "Arduino Ethernet Kit'
I had the Sketch running without the connection involved .
I combine this sketch with an existing Sketch , step by step ( few rules with pieces of code) to get the Analog pin part and the LCD communication running.
The focus is the LCD item because I think i can bring the analog values to LCD .
First question : Is there somewhere a minimum of code available to get the LCD in this sketch running ?
Second : Do I need to establish the ethernet connection in the sketch with extra code because the shield should already carry out that part !
Third: What is the intention of : void setup(void) in this ?
/*
// Test Decimalen en temp wegschrijven
Nu Verschil in hele graden meten voor het wegschrijven
** Pinnummers nu 8, 9 en 10 *************************
Verder d1 Led en A0 tem36 aansluiten
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
//#include <EthernetBonjour.h>//to resolve host names via MDNS (Multicast DNS)
#define lcd_size 3 //this will define number of LCD on the phone app
int refresh_time = 15; //the data will be updated on the app every 5 seconds.
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192, 168, 1, 1); //Uncomment for fixed IP or leave for DHCP
EthernetServer httpServer(80);
EthernetClient client;
char mode_action[54];
int mode_val[54];
Servo myServo[53];
String mode_feedback;
String lcd[lcd_size];
String api, channel, notification, user_id;
String httpOk = "HTTP/1.1 200 OK\r\n Content-Type: text/plain \r\n\r\n";
// SimpleDHT - Version: Latest
#include <SimpleDHT.h>
// DHT_sensor_library-1.3.0 - Version: Latest
#include <DHT.h>
#include <DHT_U.h>
// SD - Version: Latest
#include <SD.h>
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
// The first sensor nr 7
int dataPinSensor = 7;
SimpleDHT22 dht22;
float temperature =0;
float humidity = 0;
float LastTemp = 0;
float NewTestTemp = 0;
File myFile;
// Led and senst intnsor part
const int sensorPin = A1;
void setup() {
// void setup(void){
// }
// while (!Serial) {
// ;// wait for serial port to connect. Needed for Leonardo only
// }
Serial.begin(9600);
Serial.println(F("Please wait for IP... "));
//Ethernet.begin(mac, ip);// Uncomment for fixed IP
Ethernet.begin(mac); // Comment for fixed IP
httpServer.begin();
// EthernetBonjour.begin("ethernet");//Insted of IP you can use hostname http://ethernet.local to connect in the app.-->> for iOS only
// EthernetBonjour.addServiceRecord("ethernet", 80, MDNSServiceTCP);
Serial.println(Ethernet.localIP());
boardInit();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
pinMode(1,OUTPUT);
}
void loop() {
int sensorVal = analogRead(sensorPin);
delay(5);
// convert ADC reading to voltage
float voltage = (sensorVal / 1024.0)* 5.0 ;
Serial.print ("Volts: ");
Serial.print(voltage);
Serial.print("degrees C : ");
float temperature = ( voltage - .5 )*100;
Serial.println( temperature);
digitalWrite(1, LOW);
delay(1000);
Serial.println(" In loop");
byte data[40] = {0};
int err = SimpleDHTErrSuccess;
Serial.println("----------------------------------");
for(int dataPinSensor = 7; dataPinSensor < 10; dataPinSensor++) {
Serial.print("Test Forloop sensornr ");
Serial.print(dataPinSensor);
Serial.print(" Reading ");
if ((err = dht22.read2(dataPinSensor, &temperature, &humidity, data)) != SimpleDHTErrSuccess) {
Serial.print("Communication error with Sensor , err="); Serial.println(err);delay(1000);
return;
}
// converting Celsius to Fahrenheit
byte f = temperature * 1.8 + 32;
Serial.println(" OK:");
Serial.print((float)temperature,2); Serial.print(" *C, ");
Serial.print( " ");
Serial.print((int)humidity); Serial.println(" H humidity");
Serial.println("-----------------------------------");
digitalWrite(1, HIGH);
delay (10000);
digitalWrite(1, LOW);
// Test if there is a change in Outside temp on sensor nr first
// Only then write to file
delay(6000);
Serial.println("=======================");
delay(10000);
Serial.println("Test if difference ");
Serial.print(dataPinSensor);
Serial.print("LastTemp ");
Serial.print((float) LastTemp,2);
Serial.print(" NewTestTemp ");
Serial.println((float) NewTestTemp,2);
if (dataPinSensor == 7){
NewTestTemp = temperature ;
}
Serial.println("Enter disk loop if difference with Last");
// (LastTemp != NewTestTemp){ **** if you want more digits
if (int (LastTemp != NewTestTemp)){
// there is at least 1 degr difference write to file
Serial.println("********In loop Difference");
Serial.print("LastTemp ");
Serial.print((float) LastTemp,2);
Serial.print(" NewTestTemp ");
Serial.println((float) NewTestTemp,2);
delay(1000);
Serial.println("open test.txt");
myFile = SD.open("test.txt", FILE_WRITE);
delay(10000);
Serial.println("************ Writing to disk");
delay(10000);
// if the file opened okay, write to it:
// if (myFile) {
myFile.print(dataPinSensor);
myFile.print(";");
myFile.print(temperature,2);
myFile.print(";");
myFile.print(humidity, 0);
{ // Modify de last dataPinSensor to the larger one.
if (dataPinSensor == 9){
myFile.println(";");
Serial.println(dataPinSensor);
Serial.println(" *** Succes ****");
digitalWrite(1, HIGH);
}
else {
myFile.print(";");
delay(10);
Serial.println(dataPinSensor);
}
myFile.close();
}
}
}
if (dataPinSensor == 7){
LastTemp = NewTestTemp;
}
delay(10000);
delay(6000);
digitalWrite(1, LOW);
// lcd[0] = "Test 1 LCD";// you can send any data to your mobile phone.
// lcd[1] = "Test 2 LCD";// you can send any data to your mobile phone.
// lcd[2] = analogRead(1);// send analog value of A1
// EthernetBonjour.run();
}
I get a message that the nr of characters is too much. i,ll post the 2nd sketch in a reply!
I am not going to try to sew your code back together. Use the Reply icon, NOT the Quick Reply field, and use the Additional Options link to attach your code.
I,ll try to work the other way around and clean the sketch from Statco first.
Cleaning in this case first make it fit for Uno first by removing other types of boards.
I can imagine that you quit for now. I think it is messy too!
Tnx anyhow to give it a try.
Pls just 1 more question:
When just powering up a Uno with Ethernet shield and connected to a router it will have an Ip address.
I think.
where / how can i read that ip address, Tablet , PC , not reading it on the Arduino!
Typically, the router has an IP address that you can put in a browser. That will cause the router, acting as a server, to respond with some information. That may take many forms, but some kind of page should be shown, from which you can learn what devices the router has served address to, and what those addresses are.
If you are using DHCP, you need to ask your DHCP server that question.