ethernet and timer library samen

Geef hier suggesties voor extra onderwerpen of andere dingen die je graag gewijzigd zou willen zien
Berichten: 13
Geregistreerd: 08 Apr 2017, 18:49

ethernet and timer library samen

Berichtdoor sebastiaan_maes » 15 Jul 2017, 13:22

hallo,

ik ben bezig met het maken van een timer, de bedoeling is dat er vanaf een webpagina een timestamp word gepost naar een arduino deze verwerkt de tijd en zal een led laten branden adhv de geposte tijd vanaf de webpagina (dit is nog niet af) ik gebruik hier nu gewoon een variable in mijn code. daarna, wanneer de timer is afgelopen zal deze tijd naar een sql database verstuurd worden. mijn probleem is het volgende: ik heb twee codes geschreven, 1 stuk code verstuurt de tijd naar een database, het andere stuk bevat de timer die de led voor een bepaalde tijd zal laten branden. Deze twee stukken code werken apart perfect echter wanneer ik ze wil samenvoegen gaat het mis, mijn timer niet meer starten en wil de led dus ook niet meer gaan branden. echter wanneer ik in de code het stuk "Ethernet.begin(mac);" uncomment werkt de timer terug perfect. Kan iemand mij hierbij helpen?

de sql database code
Code: Alles selecteren
#include <Ethernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data
int  interval = 5000; // Wait between dumps

void setup() {

  Serial.begin(9600);
  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( "02:00:00" );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}


de timer code
Code: Alles selecteren
#include <RBD_Timer.h>

RBD::Timer timer;

const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 3;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;


void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);
}

void loop() {
 
  timer.setTimeout(TijdHTTP);
 
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  }

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(ledPin, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
  }

  if(timer.isExpired()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  }

  if(timer.isStopped()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  }
 
}


de twee stukken code samengevoegd
Code: Alles selecteren
#include <RBD_Timer.h>
#include <Ethernet.h> // Used for Ethernet

RBD::Timer timer;

int buttonPin = 2;     // the number of the pushbutton pin
int buttonPin1 = 3;     // the number of the pushbutton pin
int Output =  5;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data
int  interval = 5000; // Wait between dumps


void setup() {
  // initialize the LED pin as an output:
  pinMode(Output, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);

  //Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
 
}

void loop() {
 
  timer.setTimeout(TijdHTTP);
 
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  }

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(Output, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
  }

  if(timer.isExpired()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }

  if(timer.isStopped()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( "Thomas" );
    client.print("&");
    client.print("temperature=");
    client.print( "12:00:00" );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

 
 
}

Advertisement

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: ethernet and timer library samen

Berichtdoor Koepel » 15 Jul 2017, 14:18

Kun je een link geven naar die RBD timer library die je gebruikt ?
Volgens mij gebruikt die timer library alleen millis(), en zit dus niet je Ethernet in de weg.

Misschien zit het geheugen van je Uno vol ? Wat zegt de compiler aan het eind over het percentage dynamisch geheugen ?

Berichten: 13
Geregistreerd: 08 Apr 2017, 18:49

Re: ethernet and timer library samen

Berichtdoor sebastiaan_maes » 15 Jul 2017, 15:12

bedankt voor de snelle reactie, dit is de link naar de timer library http://robotsbigdata.com/docs-arduino-timer.html#isstopped
dit staat er wanneer ik de code naar de arduino upload:
Code: Alles selecteren
De schets gebruikt 11.634 bytes (36%)  programma-opslagruimte. Maximum is 32.256 bytes.
Globale variabelen gebruiken 734 bytes (35%) van het dynamisch geheugen. Resteren 1.314 bytes voor lokale variabelen. Maximum is 2.048 bytes.

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: ethernet and timer library samen

Berichtdoor Koepel » 15 Jul 2017, 18:17

Het Ethernet Shield gebruikt de SPI bus.
Dat staat hier beschreven: https://www.arduino.cc/en/Reference/SPI.

Dus daarvoor word in ieder geval pin 11,12,13 gebruikt en ook nog pin 10 (CS) en 4 (CS voor SD kaart).

Vervolgens heb je een led aan pin 10 en 11 gehangen. Dat gaat niet.
Maar je wilt PWM voor de leds met analogWrite.
Dat staat hier beschreven: https://www.arduino.cc/en/Reference/AnalogWrite.
Dus met het Ethernet Shield hou je deze over voor PWM: 3, 5, 6, 9.

Je kunt op de Arduino Uno iedere analoge ingang ook als digitale ingang of uitgang gebruiken (geen PWM).

Berichten: 13
Geregistreerd: 08 Apr 2017, 18:49

Re: ethernet and timer library samen

Berichtdoor sebastiaan_maes » 16 Jul 2017, 11:10

ik heb de output en input pinnen die ik gebruik veranderd. input pins: 3 en 5, output pin: 9. Vervolgends de sketch geupload maar geen resultaat.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ethernet and timer library samen

Berichtdoor nicoverduin » 16 Jul 2017, 13:15

Gooi de serial prints er eens uit....
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 08 Apr 2017, 18:49

Re: ethernet and timer library samen

Berichtdoor sebastiaan_maes » 16 Jul 2017, 18:36

geprobeerd... geen resultaat

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: ethernet and timer library samen

Berichtdoor Koepel » 16 Jul 2017, 18:51

@sebastiaan_maes, oeps, sorry, ik vergeleek het met je verkeerde sketch. Je had de leds al niet meer op de SPI pinnen zitten.

Wanneer je op een forum zegt: "geen resultaat", dan komen we niet verder. @nicoverduin probeerde je zover te krijgen dat je laat zien wat er uit de seriele monitor komt.

Er is iets dat niet werkt. Daarom willen we graag zoveel mogelijk weten. Als je dingen weglaat omdat je zelf al weet dat het wel of niet werkt, dan is dat voor ons niet genoeg. Dat willen we graag zelf kunnen bepalen.

Kun je de volledige sketch laten zien, en daarbij met kopiëren en plakken de seriele monitor gegevens toevoegen ?

Ik zie helaas nog niet waar het probleem zou kunnen zitten. Dus ik weet nog niet of het gaat lukken om de fout te vinden.

Berichten: 13
Geregistreerd: 08 Apr 2017, 18:49

Re: ethernet and timer library samen

Berichtdoor sebastiaan_maes » 21 Jul 2017, 20:52

dit is de code die ik nu heb
Code: Alles selecteren
#include <RBD_Timer.h>
#include <Ethernet.h> // Used for Ethernet

RBD::Timer timer;

int buttonPin = 5;     // the number of the pushbutton pin
int buttonPin1 = 3;     // the number of the pushbutton pin
int Output =  9;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data
int  interval = 5000; // Wait between dumps


void setup() {
  // initialize the LED pin as an output:
  pinMode(Output, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);

  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
 
}

void loop() {
 
  timer.setTimeout(TijdHTTP);
 
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  }

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(Output, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
  }

  if(timer.isExpired()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }

  if(timer.isStopped()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }


  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( "Thomas" );
    client.print("&");
    client.print("temperature=");
    client.print( "12:00:00" );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

 
 
}


wanneer ik de sketch upload
Code: Alles selecteren
De schets gebruikt 15.480 bytes (47%)  programma-opslagruimte. Maximum is 32.256 bytes.
Globale variabelen gebruiken 851 bytes (41%) van het dynamisch geheugen. Resteren 1.197 bytes voor lokale variabelen. Maximum is 2.048 bytes.


seriele monitor
Code: Alles selecteren
Tweaking4All.com - Temperature Drone - v2.0
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

IP Address        : 192.168.0.200
Subnet Mask       : 255.255.255.0
Default Gateway IP: 192.168.0.1
DNS Server IP     : 195.130.131.3
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected
-> Connected

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: ethernet and timer library samen

Berichtdoor Koepel » 23 Jul 2017, 10:58

Met die timer library ben ik niet zo bekend, maar in de code zie ik verder geen bijzonderheden. Voor zover ik kan zien zitten ze elkaar niet in de weg. Werkt het ledje of gaat dat nog steeds verkeerd ?

Volgende

Terug naar Forum suggesties

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 5 gasten