adamboardman / pico-onewire

Raspberry Pi Pico OneWire Library
MIT License
51 stars 12 forks source link

A question: What is the data type of 'rom_address_t address{}' - one_wire.single_device_read_rom(address); ? #10

Open ArrrghIsle opened 5 months ago

ArrrghIsle commented 5 months ago

I will have multiple DS18B20s on different data pins and will need to access them based on that rather than in series on a single One Wire circuit. I've looked at both the CPP and Header files and can't figure it out. My apologies, I am somewhat new to this. I am (attempting) programming in the Arduino IDE.

Here is an example of what I am trying to do:

`#define THERM_BUS_1 6

define THERM_BUS_2 22

One_wire OW_Get_TB1(THERM_BUS_1); One_wire OW_Get_TB2(THERM_BUS_2);

rom_address_t address{};

byte TB1_Address[8]; // ?????? Fails to compile, Error in datatype byte TB2_Address[8]; // ?????? Fails to compile, Error in datatype

void setup() {

OW_Get_TB1.init(); // Initialize the DS18B20 Thermometer

OW_Get_TB1.single_device_read_rom(address); // Assuming a single device is attached, do a Read
                                            // ROM and populate the rom_address_t address{}.

TB1_Address = address; // error: incompatible types in assignment of 'void' to 'byte [8]' {aka 'unsigned char [8]'}

OW_Get_ OW_Get_TB1.set_resolution(TB1_Address, 9); // error: cannot convert 'byte [8]' {aka 'unsigned char [8]'} to 'rom_address_t&'

OW_Get_TB2.init(); // Initialize the DS18B20 Thermometer

OW_Get_TB2.single_device_read_rom(address); // Assuming a single device is attached, do a Read
                                            // ROM and populate the rom_address_t address{}.

TB2_Address = address;

OW_Get_TB2.set_resolution(TB2_Address, 9); // Set the Resolution of the DS18B20 Thermometer

// Compilation error: incompatible types in assignment of 'void' to 'byte [8]' {aka 'unsigned char [8]'} }`

dquadros commented 4 months ago

From one_write.h:

struct rom_address_t {
    uint8_t rom[ROMSize];
};

So, rom_address_t is a structure with one field named rom that is a vector of uint8_t.

You should declare TB1_Address and TB2_Address as rom_address_t:

rom_address_t TB1_Address, TB2_Address;