c++ - DS18b20 fail to read -




i wrote small program in arduino read temperature ds18b20 , transfer nrf24l01. used arduino ng atmega8 mcu compile , burned hex file atmega8 on breadboard. works fine except readings of ds18b20. please take @ code , tell me if there wrong?

#include "rf24network.h" #include "rf24.h" #include "onewire.h"   rf24 radio(10,9); rf24network network(radio); onewire ds(19);  const uint16_t transmit_address = 011; const uint16_t receiver_address = 01;  const unsigned long interval = 100; unsigned long last_sent;  uint8_t count; float temp;  struct payload {   uint8_t count;   uint8_t data1; };  void setup(void) {   radio.begin();   network.begin(90,transmit_address);   radio.setpalevel(rf24_pa_high);   count = 0;   }  void loop() {   temp = gettemp();   network.update();   unsigned long = millis();   if ( - last_sent >= interval) {     count++;     last_sent = now;     payload payload_data = {count, temp};     rf24networkheader header(receiver_address);     network.write(header,&payload_data,sizeof(payload_data));   } }  float gettemp() {   byte data[12];   byte addr[8];   if ( !ds.search(addr)) {     ds.reset_search();     return;   }   ds.reset();   ds.select(addr);   ds.write(0x4e);   ds.write(0x00);   ds.write(0x00);   ds.write(0x1f);   ds.reset();   ds.select(addr);   ds.write(0x44);   delay(300);   ds.reset();   ds.select(addr);       ds.write(0xbe);   (byte = 0; < 9; i++) {     data[i] = ds.read();   }   int16_t raw = (data[1] << 8) | data[0];   raw = raw & ~7;  // 9 bit resolution, 93.75 ms   float temperature = (float)raw / 16.0;   return temperature; } 

thanks again , sorry poor english.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -