• 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
nodemcu v3 ds18b20
#1
Witam,

Chciałem na szybko podłączyć 18b20 do nodecmu v3.
Niestety coś mi nie idzie, niby płytka widzi czujnik i podaje jego id.
Ale jest taki problem że czujnik wskazuje tylko wartość 85C albo 127.5C.

Sprawdziłem na nano v3 i tam wszystko działa, nr id ten sam a temperatura realna i widać reakcję czujnika na bodźce temperaturowe. Działa wszystko prawidłowo. Ostatnim urządzeniem które zamyka test jest nano na którym działają czujniki 18b20 więc nie ma mowy o uszkodzeniu w czasie testowania.

Podłączyłem z rezystorem 4k7 , potem z 2k2 bo na 3v3 podobno dla jednego ds18b20 to 2k2 powinno być ktoś tak radził w internecie.

Proszę o pomoc bo już wyczerpałem pomysły gdzie jest błąd.


Poniżej kod jaki wgrałem na oba scalaki i odpowiedź (jedyna różnica że na nano jest pin 2 a na nodemcu jest D2 - inaczej całkiem nie działa na nodemcu jak bym podłączył pod całkiem inny pin)


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

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 9 // Lower resolution

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

int numberOfDevices; // Number of temperature devices found

DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address

void setup(void)
{
 // start serial port
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");

 // Start up the library
 sensors.begin();
 
 // Grab a count of devices on the wire
 numberOfDevices = sensors.getDeviceCount();
 
 // locate devices on the bus
 Serial.print("Locating devices...");
 
 Serial.print("Found ");
 Serial.print(numberOfDevices, DEC);
 Serial.println(" devices.");

 // report parasite power requirements
 Serial.print("Parasite power is: ");
 if (sensors.isParasitePowerMode()) Serial.println("ON");
 else Serial.println("OFF");
 
 // Loop through each device, print out address
 for(int i=0;i<numberOfDevices; i++)
 {
   // Search the wire for address
   if(sensors.getAddress(tempDeviceAddress, i))
    {
        Serial.print("Found device ");
        Serial.print(i, DEC);
        Serial.print(" with address: ");
        printAddress(tempDeviceAddress);
        Serial.println();
        
        Serial.print("Setting resolution to ");
        Serial.println(TEMPERATURE_PRECISION, DEC);
        
        // set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
        sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
        
         Serial.print("Resolution actually set to: ");
        Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
        Serial.println();
    }else{
        Serial.print("Found ghost device at ");
        Serial.print(i, DEC);
        Serial.print(" but could not detect address. Check power and cabling");
    }
 }

}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
 // method 1 - slower
 //Serial.print("Temp C: ");
 //Serial.print(sensors.getTempC(deviceAddress));
 //Serial.print(" Temp F: ");
 //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit

 // method 2 - faster
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");
 Serial.print(tempC);
 Serial.print(" Temp F: ");
 Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}

void loop(void)
{
 // call sensors.requestTemperatures() to issue a global temperature
 // request to all devices on the bus
 Serial.print("Requesting temperatures...");
 sensors.requestTemperatures(); // Send the command to get temperatures
 Serial.println("DONE");
 
 
 // Loop through each device, print out temperature data
 for(int i=0;i<numberOfDevices; i++)
 {
   // Search the wire for address
   if(sensors.getAddress(tempDeviceAddress, i))
    {
        // Output the device ID
        Serial.print("Temperature for device: ");
        Serial.println(i,DEC);
        
        // It responds almost immediately. Let's print out the data
        printTemperature(tempDeviceAddress); // Use a simple function to print out the data
    }
    //else ghost device! Check your power requirements and cabling
    
 }
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
 for (uint8_t i = 0; i < 8; i++)
 {
   if (deviceAddress[i] < 16) Serial.print("0");
   Serial.print(deviceAddress[i], HEX);
 }
}

Nano :
Kod:
⸮Dallas Temperature IC Control Library Demo
Locating devices...Found 1 devices.
Parasite power is: ON
Found device 0 with address: 2883613C040000B5
Setting resolution to 9
Resolution actually set to: 9
Requesting temperatures...DONE
Temperature for device: 0
Temp C: 28.00 Temp F: 82.40
Requesting temperatures...DONE
Temperature for device: 0
Temp C: 28.00 Temp F: 82.40

nodemcu v3:


Kod:
Dallas Temperature IC Control Library Demo
Locating devices...Found 1 devices.
Parasite power is: ON
Found device 0 with address: 2883613C040000B5
Setting resolution to 9
Resolution actually set to: 9
Requesting temperatures...DONE
Requesting temperatures...DONE
Temperature for device: 0
Temp C: 85.00 Temp F: 185.00
Requesting temperatures...DONE
Requesting temperatures...DONE
Temperature for device: 0

dla rezystancji 4k7 jest 85C
dla rezystancji 2k2 jest 127.5 

brak reakcji na bodźce temperaturowe.


Uprzedzam pytania - tak, bardzo ciepło u mnie w domu i te 28 to prawda.  termometr podobnie wskazuje.

Proszę o pomoc, może ktoś się spotkał z podobnym problemem ?
 
Odpowiedź
#2
Trochę stary temat, ale może komuś się przyda ta "wiedza Wink
Pewnie w tym masz problem:

#define ONE_WIRE_BUS 2

podajesz GPIO2 dla NodeMcuv3, czyli powinienś podłączyć swój DS do pinu D4 lub zadeklarować

#define ONE_WIRE_BUS D4

Jeśli zaś podłączasz do D2, to powinno być:

#define ONE_WIRE_BUS 4


W NodeMCU v3:
D4 - GPIO2
D2 - GPIO4

Powodzenia Smile
 
Odpowiedź
#3
85 stopni, dla DS18B20, to według dokumentacji temperatura, którą odczytuje się po włączeniu termometru do zasilania bez wcześniejszego wydania komendy konwersji temperatury.
127 (-127) stopni, tak zachowują się ułomne Arduinowe programy odczytujące nic, konkretnie, gdy brak termometru na magistrali.
Cała filozofia tej wiedzy, to przeczytanie krótkiej noty DS18B20 i przejrzenie krótkich, niedopracowanych bibliotek Arduino zwłaszcza tej obsługującej DS18B20 ale i znajomość chłamu obsługującego 1-Wire też jest przydatna.
Wszystko to, to 2..3 godziny dla osoby znającej C++, bo zakładam, że zabierając się za programowanie Arduino w C++, język się zna.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości