Hello all.
I'm JP, French and I making a part counter for a production machine.
I'm sorry but some of my code comments and variable name will be a mix of French and English. I'll do my best to rename them without destroying the code done.
This counter sends to a Mysql database on the network the counter value and the according time value.
The machine can reset the counter for a new production batch.
And finally the arduino send the time according to a time sent from the PC.
The fianl goal is to see the production figure (counter, # of stop, the reason for that, graph a production day according to these stops) but also for the production expert calculate the MTTR and MTBF (Mean time To Repare and Mean Time between Failure)...
I'll be please to send to the open source community this tool once this one will be up and ready.
I'm using an Arduino UNO and a Ethernet shield.
Before to go further, I would like to thank you all this community and the interessant thing I could have found.
Nethertheless.
#include <SoftwareSerial.h>
#include <Time.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB0, 0xD0 }; // Enter a MAC address for your controller below.
IPAddress serverIP(192,168,1,102); // serveur MySql
EthernetServer server(80); //server port
IPAddress ip(192,168,1,177); // =arduino
// Variables for the counter
int sensorValue ; // value of the counter
int ConnectedPin = 7;
int CompteurLedPin = 9; // Send a data
unsigned long dernierPush; // LastPushTime
// Reset
int ledPin = 6; // LED pin Reset
////////////////////////////////////////////////////
/// Fonction Sends the data to a php file that inserts into a mysql database
////////////////////////////////////////////////////
void Envoie_data(){
EthernetClient client;
Serial.println ("Dans procedure Envoie Data");
if (client.connect(serverIP, 80)) {
// Make a HTTP request:
client.println("GET /temp.php?t="+ String(now()) + "&&t1=" + String(sensorValue) + " HTTP/1.0");
Serial.println("GET /temp.php?t="+ String(now()) + "&&t1=" + String(sensorValue) + " HTTP/1.0");
client.println();
client.stop();
digitalWrite(CompteurLedPin, HIGH); // set the LED on
delay(500); // wait for a 1/2 second
digitalWrite(CompteurLedPin, LOW); // set the LED off
digitalWrite(ConnectedPin, HIGH); // set the LED on
}
else {
// if you didn't get a connection to the server:
digitalWrite(ConnectedPin, LOW); // set the LED off
Serial.println("connection failed");
}
}
/////////////////////////////////////
// counteur interrupt
/////////////////////////////////::::
void CompteurInterrupt(){
digitalWrite(ledPin, LOW); // set the LED off for the First part counted
Serial.print(millis()); Serial.print(" "); Serial.print(dernierPush); Serial.print(" "); Serial.println(millis()-500);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Serial.println("Blabla..!!");
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(dernierPush < (millis() - 500)){
digitalWrite(ledPin, HIGH); // set the LED off
sensorValue ++; // Met à jour le compteur
dernierPush = millis(); // LastPushTime
noInterrupts();
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Envoie_data(); // Send The data to Mysql
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
interrupts();
}
}
/////////////////////////
/// Procedure de setup
//////////////////////////
void setup() {
Serial.begin(9600);
pinMode(ConnectedPin, OUTPUT); // pin connected to the sensor (blinks during acquisition)
pinMode(CompteurLedPin, OUTPUT); // Pin de check de network connection
pinMode(ledPin, OUTPUT); // pin de check reset counter
digitalWrite(ledPin, HIGH); // part counted (set 1)
dernierPush =0; // LastPushTime
// start the Ethernet connection:
Ethernet.begin(mac, ip);
Serial.println("connecting...");
digitalWrite(ConnectedPin, HIGH); // set the LED on
server.begin();
Serial.println("Server.begin");
Serial.println(Ethernet.localIP());
// interrupts();
attachInterrupt(0, CompteurInterrupt, RISING);
}
/////////////////////////
/// Procedure de loop
//////////////////////////
void loop() {
}
Well. Here are my two questions:
1/ Why should I connect the 2 interrupt pins (2 & 3). If I connect 1 pin only like all the exemples and the good tutorial I could have read?
But If I make a small function call, it works fine like that.
2/ In the CompteurInterrupt() liked to the interrupt, this one work fine with Serial.println and led management.. but if I call the function Envoie_data(); then the arduino is block and Serial.println("Blabla..!!"); is not displayed.
But if I comment the function Envoie_data, I get the Serial.println("Blabla..!!"); PLACED BEFORE this call
Any Help will be welcom to understand why this call blocs everything.
Please see the attached file for the connection done: (made with Fritzing)
Many thanks
JP