Hirdetés
- Luck Dragon: Asszociációs játék. :)
- Real Racing 3 - Freemium csoda
- Meggyi001: Kórházi ellátás: kuka vagy finom?
- Oldman2: A KOReader ebook olvasó program
- Brogyi: CTEK akkumulátor töltő és másolatai
- Elektromos rásegítésű kerékpárok
- sziku69: Fűzzük össze a szavakat :)
- GoodSpeed: WindowBlinds 11
- 20230101_102713676_iOS
- Flashback: Építsünk PC-t akciós alkatrészekből, lassan. upd: 10.03
-
LOGOUT
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
junhum
tag
Sziasztok!
Volna egy olyan problémám, hogy ez a kód:
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xAD, 0xBD, 0xCD, 0xED, 0xFD, 0x0D};
IPAddress ip(192, 168, 0, 100);
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "xxxxxxxxxxxxxxxxxxx";
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
// wait for serial port to connect. Needed for Leonardo only
// Start Ethernet on Arduino
startEthernet();
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit, celsiuss;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(850);
return;
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
ds.select(addr);
ds.write(0x44); // start conversion, use ds.write(0x44,1) with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
celsiuss = round(celsius);
String analogValue0 = String(celsiuss, DEC);
Serial.println(celsius);
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println("...disconnected");
Serial.println();
client.stop();
}
// Update ThingSpeak
// if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
// {
updateThingSpeak("field1="+analogValue0);
// }
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}
lastConnected = client.connected();
}
void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
//String tsData;
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println("Connecting to ThingSpeak...");
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();
lastConnectionTime = millis();
}
}
void startEthernet()
{
client.stop();
Serial.println("Connecting Arduino to network...");
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}
delay(1000);
}
No more adresses dob serialon és nem is megy tovább a program, legalábbis Thingspeaken nem látnám hogy akarmi menne (api kód kitöltve), ha csak egy sima példa programot futtatok akkor ott küld adatot.
Ha csak onewire példát futtatok akkor működik.
Egybe a kettőt nem tudom.
Uno van w5100 shielddelszerk.:
A shieldet elég egyébként csak spi-n összekötni? pl ha nanoval akarom majd összehozni?
Új hozzászólás Aktív témák
- Ryzen5 4500/ RTX2060/ 16GB DDR4 alapú konfig/ garancia/ ingyen foxpost
- Régi okostelefon tokok - 500 Ft/darab
- Corsair VENGEANCE LPX 2x16GB DDR4 3200MHz CL16 - Új, bontatlan - Eladó!
- LG UltraGear 32GQ85X-B LED IPS Monitor! 2560x1440 / 240Hz / 1ms / FreeSync / G-Sync
- LG UltraWide 34WQ75X-B Ívelt Monitor! 34" 3440x1440 / 4K / 99% sRGB!
- HIBÁTLAN iPhone 14 Pro 256GB Deep Purple -1 ÉV GARANCIA - Kártyafüggetlen, MS3516, 94% Akkumulátor
- Nagyakkus, mobilnetes - Dell Latitude 5330 i3-1215U 6mag! 16GB 1000GB 13.3" FHD 1 év gar
- HIBÁTLAN iPhone 14 128GB Midnight -1 ÉV GARANCIA - Kártyafüggetlen, MS3527, 100% Akkumulátor
- ÁRGARANCIA!Épített KomPhone Ryzen 7 5700X 16/32/64GB RAM RX 9060 XT 8GB GAMER PC termékbeszámítással
- Eladó Samsung Galaxy A32 5G 4/128GB / 12 hó jótállás
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
ekkold
