Hallo,
Ich arbeite mit mehreren Maxim (Dallas) DS18B20, Temperatur sensoren.
Diese werden anfangs alle mit einem jeweiligen Array initialisiert, welcher ihre BUS Identifikationsnummer beinhalten.
Dieser Bus kann ca 128 geräte aufnehmen.
Nun möchte ich nich für jeden einzeln eine Ausgabe programmieren sondern diese eben dynamisch gestalten. Dabei kommt mir die Frage auf wie ich das am besten anstelle.
Vielleicht mit einem Mehrdimensionalen Array?
Ich habe hier schon einem einen Lösungsansatz, welcher vielleicht etwas klarheit schafft, wo mein Problem liegt.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress thermo0 = { 0x28, 0xA0, 0x02, 0xB4, 0x04, 0x00, 0x00, 0xC0 };
DeviceAddress thermo1 = { 0x28, 0x08, 0x43, 0xB4, 0x04, 0x00, 0x00, 0x19 };
DeviceAddress thermo2 = { 0x28, 0xC4, 0x2B, 0xB4, 0x04, 0x00, 0x00, 0xD4 };
DeviceAddress thermo3 = { 0x28, 0xF6, 0x9E, 0xB4, 0x04, 0x00, 0x00, 0xCA };
DeviceAddress thermo4 = { 0x28, 0x9E, 0x13, 0xB4, 0x04, 0x00, 0x00, 0x8F };
DeviceAddress thermo5 = { 0x28, 0xB1, 0xAA, 0xB4, 0x04, 0x00, 0x00, 0xA1 };
DeviceAddress thermo6 = { 0x28, 0x49, 0x2C, 0xB4, 0x04, 0x00, 0x00, 0x25 };
DeviceAddress thermo7 = { 0x28, 0x59, 0x11, 0xB4, 0x04, 0x00, 0x00, 0x16 };
DeviceAddress thermo8 = { 0x28, 0xE3, 0x01, 0xB4, 0x04, 0x00, 0x00, 0xA2 };
DeviceAddress thermo9 = { 0x28, 0xBB, 0xC6, 0xB4, 0x04, 0x00, 0x00, 0x5E };
int i;
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit
sensors.setResolution(thermo0, 10);
sensors.setResolution(thermo1, 10);
sensors.setResolution(thermo2, 10);
sensors.setResolution(thermo3, 10);
sensors.setResolution(thermo4, 10);
sensors.setResolution(thermo5, 10);
sensors.setResolution(thermo6, 10);
sensors.setResolution(thermo7, 10);
sensors.setResolution(thermo8, 10);
sensors.setResolution(thermo9, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
delay(2000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
for(i = 0; i<10; i++){
char b[7] = "thermo";
b[6] = i;
int t = 0;
b = t;
Serial.print("Device "%d" :", i);
printTemperature(t);
Serial.print("\n\r");
}
}
Debug Konsole spuckt folgendes aus:
arduino_ds18b20_temperature_sensor.pde: In function 'void loop()':
arduino_ds18b20_temperature_sensor:69: error: incompatible types in assignment of 'int' to 'char [7]'
arduino_ds18b20_temperature_sensor:70: error: 'd' was not declared in this scope
arduino_ds18b20_temperature_sensor:71: error: invalid conversion from 'int' to 'uint8_t*'
arduino_ds18b20_temperature_sensor:71: error: initializing argument 1 of 'void printTemperature(uint8_t*)'
schonmal vielen dank für eure Hilfe!