Multiple ds18b20 rolling through all virtual ports?

I have about six ds18b20, assigned with six Virtual ports. when a gauge is added it rolls through all the six temps even if only one virtual port is chosen on the app. I wanted to have a reading for each one but it reads all of them.

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff
#include <OneWire.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire  ds(2);  // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.
int adr;
float s1;
float s2;
float s3;
float s4;
float s5;
float s6;
float s7;

char auth[] = "8ad631f3a1f145679ca588a566bd3ab1"; // Put your Auth Token here. (see Step 3 above)

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
}

void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...

  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
    byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
//  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {           //we need to drop 8 bytes of data
  }
  adr = (addr[7]);

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, 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


  for ( i = 0; i < 9; i++) {           // we need 9 bytes to drop off
    data[i] = ds.read();
  }
  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;
  if(adr == 0x28, 0xFF, 0xF0, 0x3C, 0x2E, 0x04, 0x00, 0xEF)  {         //replace ??? with value of sensor number 1    
    s1 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 0x28, 0xFF, 0x68, 0x3F, 0x2E, 0x04, 0x00, 0xEE)  {         //replace ??? with value of sensor number 2
    s2 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 0x28, 0xFF, 0x64, 0x3F, 0x2E, 0x04, 0x00, 0xCF)  {         //replace ??? with value of sensor number 3
    s3 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 0x28, 0xFF, 0x7C, 0x81, 0x2D, 0x04, 0x00, 0xED)  {         //replace ??? with value of sensor number 4
    s4 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 0x28, 0xFF, 0xC9, 0x72, 0x3B, 0x04, 0x00, 0x12)  {         //replace ??? with value of sensor number 5
    s5 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 0x28, 0xFF, 0x75, 0x3F, 0x2E, 0x04, 0x00, 0x7E)  {         //replace ??? with value of sensor number 6
    s6 = fahrenheit;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }


Serial.print(" Sensor 1 = ");
Serial.print(s1);
Serial.print(" Sensor 2 = ");
Serial.print(s2);
Serial.print(" Sensor 3 = ");
Serial.print(s3);
Serial.print(" Sensor 4 = ");
Serial.print(s4);
Serial.print(" Sensor 5 = ");
Serial.print(s5);
Serial.print(" Sensor 6 = ");
Serial.print(s6);


  Blynk.virtualWrite(V5, s1);
  Blynk.virtualWrite(V6, s2);
  Blynk.virtualWrite(V7, s3);
  Blynk.virtualWrite(V8, s4);
  Blynk.virtualWrite(V9, s5);
  Blynk.virtualWrite(V10, s6);

  
 
}

Hi there.
I run my DS18B20 temp sensors each on a separate digital pin complete with own one wire function call. It does make the sketch larger.

Hello,

I will be reading more DS18B20’s than the arduino can handle soon on the available ports. I built a system about two years ago with 24,000 temp sensors and was just testing this app to see what it could do for prototyping. i will have a few hundred temp and humidity probes in a few months. the app seams to scroll through all the temps even choosing one virtual port it still rolls threw all the temp probe,s. I have not tried a second string of probes yet.

Best Regards,
Bob

Hi, @bbarker,

First of all, you can’t perform virtual.writes in the main loop. You are causing a flood

Please check PushData example in the library to see how to send data in intervals.

Also, are you on iOS or Android?

Hello,
Pavel

Thank you for the reply, not sure what a flood means yet on this system but it does not sound good so i took the unit off the network.
I am using an Android currently and will do some research on the PushData and intervals as you recommend.

I apologize if this may have caused any issues.

Best Regards,
Bob

Sorry for not specifying it. Read about flood here:

http://docs.blynk.cc/#blynk-main-operations-get-data-from-hardware

Why dont you install DallasTemperature and SimpleTimer library and try making something like this?

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h> 
#include <DallasTemperature.h>

#define Pin 3   //One sensor connected on pin 3
#define Pin2 4  //One sensor connected on pin 4


SimpleTimer timer;

OneWire ourWire(Pin);
OneWire ourWire2(Pin2);

DallasTemperature sensors(&ourWire);
DallasTemperature sensors2(&ourWire2);

char auth[] = "1234512345";

float s1;
float s2;

void setup()
{
  Serial.begin(9600);
  delay(10);
  Blynk.begin(auth, "ssid","pass");
  delay(10);
  sensors.begin();
  delay(10);
  sensors2.begin();
  delay(10);
  sensors.setResolution(10);
  delay(10);
  sensors2.setResolution(10);
  timer.setInterval(1000L, ReadTemp); // Will call the function to measure
              // temperature every 1 second

}

void ReadTemp()
{
sensors.requestTemperatures();
delay(10);
s1 = sensors.getTempCByIndex(0);
delay(10);
sensors2.requestTemperatures();
delay(10);
s2 = sensors2.getTempCByIndex(0);
delay(10);
}

BLYNK_READ(V1)
{
Blynk.virtualWrite(V1, s1);
}

BLYNK_READ(V2)
{
Blynk.virtualWrite(V2, s2);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Please notice that I used some ESP8266 libraries because that’s the only one I have here right now but the basics will stay the same. Using the timer.setInterval(1000L, ReadTemp); will avoid the flood mentioned before. Give it a try. You will have to make some changes but I think this should work and the idea can be made to work with the other sensors too

Hello,
AndreSepulveda

Thank you for the help, I do use the DallsTemperature.h in another project works great. the project i am working now will need about 100 ds18b20 and 15 DHT22 sensors, just wanted to let you know so you understand my problem a little better. I need to use the capabilities of the onewire practical do to limited ports and cables.

I did implement the SimpleTimer and the timer.setInterval, for 10000s to slow it down. Once it works i only need about once a minute or fie minute intervals.

The main problem i currently have is that the widget likes to roll threw all 6 ds18b20 sensors that i have for testing even with the virtual port asigned to only one port on the app. This would be a nice ad on widget later for someone that would like to see all there temps roll back to back.

I am not sure if the issue is my code or a bug in the server but that how testing goes. :slight_smile: ,

Your code/sketch works great for normal test projects and it is clean.
P.S using it on my little test weather station now, thanks

Best Regards,
Bob

It’s showing all measures on the same widget?
How did you set up the app widgets?

Hello

Select gauge then virtual, then v5 for the first virtual port. interval 10 seconds. if i set-up a second gauge on say v6 they both read the same values and they change to the other temp values as they roll threw all six temp prob’s

Best Regards,
Bob

1 Like