• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Wywala błąd w kodzie.
#3
Tak starej wersji oprogramowania używam ponieważ na nowszej nie chciały mi działać niektóre rzeczy. Wink



Kod:
#include <EtherCard.h>
#include <OneWire.h>


int DS18S20_Pin = 5;
OneWire ds(DS18S20_Pin);

static uint8_t mymac[6] = {
 0x54, 0x55, 0x58, 0x10, 0x00, 0x24};                  
static uint8_t ip[4] = {
 192, 168, 0, 185};          
static uint16_t port = 80;
byte Ethernet::buffer[700];
static uint32_t timer;
const char website[] PROGMEM = "api.thingspeak.com";
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
void setup () {
Serial.begin(57600);
Serial.println(F("\n[webClient]"));
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
 float temperature = getTemp();
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
Serial.print(temperature);
int myInt = temperature;  
char myIntAsString[7];
itoa(myInt, myIntAsString, 10);
ether.browseUrl(PSTR("/update?key=1234678&field1="), myIntAsString, website, my_callback);

}
}

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 5 ) != addr[5]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

Powiedzmy taki kod.
 
Odpowiedź
  


Wiadomości w tym wątku
Wywala błąd w kodzie. - przez Kubaa - 20-03-2017, 18:40
RE: Wywala błąd w kodzie. - przez namok - 20-03-2017, 23:13
RE: Wywala błąd w kodzie. - przez Kubaa - 20-03-2017, 23:50
RE: Wywala błąd w kodzie. - przez namok - 21-03-2017, 10:05
RE: Wywala błąd w kodzie. - przez Kubaa - 21-03-2017, 15:23
RE: Wywala błąd w kodzie. - przez Kubaa - 21-03-2017, 16:19
RE: Wywala błąd w kodzie. - przez namok - 21-03-2017, 19:37
RE: Wywala błąd w kodzie. - przez Kubaa - 21-03-2017, 23:26

Skocz do:


Przeglądający: 1 gości