Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the libraries we need
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <ModbusRtu.h>
- // Data wire is plugged into port 2 on the Arduino
- #define ONE_WIRE_BUS 12
- #define TXEN 10
- //
- uint16_t au16data[6];
- // 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);
- // Aktivieren des ModBus-Slave
- Modbus slave(14, 0, TXEN); // this is slave @1 and RS-485
- // Feste Zuordnung der Sensoren über die Seriennummer
- DeviceAddress Sensor0 = {0x28, 0xAA, 0xBA, 0x34, 0x13, 0x13, 0x01, 0x70};
- DeviceAddress Sensor1 = {0x28, 0xAA, 0x7C, 0x35, 0x13, 0x13, 0x01, 0x41};
- DeviceAddress Sensor2 = {0x28, 0xAA, 0x7A, 0x35, 0x13, 0x13, 0x01, 0xDD};
- DeviceAddress Sensor3 = {0x28, 0xAA, 0x15, 0x25, 0x13, 0x13, 0x01, 0x9B};
- DeviceAddress Sensor4 = {0x28, 0xAA, 0xA7, 0x32, 0x13, 0x13, 0x01, 0xE9};
- DeviceAddress Sensor5 = {0x28, 0xAA, 0xD7, 0x2C, 0x13, 0x13, 0x01, 0xA9};
- /*
- The setup function. We only start the sensors here
- */
- void setup(void)
- {
- slave.begin( 9600 ); // baud-rate at 19200
- // Start up the library
- sensors.begin();
- }
- /*
- Main function, get and show the temperature
- */
- void loop(void)
- {
- sensors.requestTemperatures(); // Send the command to get temperatures
- float modbuswert_float_0 = sensors.getTempC(Sensor0);
- au16data[0] = modbuswert_float_0 * 1000;
- float modbuswert_float_1 = sensors.getTempC(Sensor1);
- au16data[1] = modbuswert_float_1 * 1000;
- float modbuswert_float_2 = sensors.getTempC(Sensor2);
- au16data[2] = modbuswert_float_2 * 1000;
- float modbuswert_float_3 = sensors.getTempC(Sensor3);
- au16data[3] = modbuswert_float_3 * 1000;
- float modbuswert_float_4 = sensors.getTempC(Sensor4);
- au16data[4] = modbuswert_float_4 * 1000;
- float modbuswert_float_5 = sensors.getTempC(Sensor5);
- au16data[5] = modbuswert_float_5 * 1000;
- slave.poll( au16data, 6 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement