Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. // Include the libraries we need
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #include <ModbusRtu.h>
  5.  
  6. // Data wire is plugged into port 2 on the Arduino
  7. #define ONE_WIRE_BUS 12
  8. #define TXEN  10
  9. //
  10. uint16_t au16data[6];
  11.  
  12. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  13. OneWire oneWire(ONE_WIRE_BUS);
  14.  
  15. // Pass our oneWire reference to Dallas Temperature.
  16. DallasTemperature sensors(&oneWire);
  17.  
  18. // Aktivieren des ModBus-Slave
  19. Modbus slave(14, 0, TXEN); // this is slave @1 and RS-485
  20.  
  21. // Feste Zuordnung der Sensoren über die Seriennummer
  22. DeviceAddress Sensor0 = {0x28, 0xAA, 0xBA, 0x34, 0x13, 0x13, 0x01, 0x70};
  23. DeviceAddress Sensor1 = {0x28, 0xAA, 0x7C, 0x35, 0x13, 0x13, 0x01, 0x41};
  24. DeviceAddress Sensor2 = {0x28, 0xAA, 0x7A, 0x35, 0x13, 0x13, 0x01, 0xDD};
  25. DeviceAddress Sensor3 = {0x28, 0xAA, 0x15, 0x25, 0x13, 0x13, 0x01, 0x9B};
  26. DeviceAddress Sensor4 = {0x28, 0xAA, 0xA7, 0x32, 0x13, 0x13, 0x01, 0xE9};
  27. DeviceAddress Sensor5 = {0x28, 0xAA, 0xD7, 0x2C, 0x13, 0x13, 0x01, 0xA9};
  28.  
  29. /*
  30.    The setup function. We only start the sensors here
  31. */
  32. void setup(void)
  33.  
  34. {
  35.   slave.begin( 9600 ); // baud-rate at 19200
  36.  
  37.   // Start up the library
  38.   sensors.begin();
  39. }
  40.  
  41. /*
  42.    Main function, get and show the temperature
  43. */
  44. void loop(void)
  45. {
  46.   sensors.requestTemperatures(); // Send the command to get temperatures
  47.   float modbuswert_float_0 = sensors.getTempC(Sensor0);
  48.   au16data[0] = modbuswert_float_0 * 1000;
  49.   float modbuswert_float_1 = sensors.getTempC(Sensor1);
  50.   au16data[1] = modbuswert_float_1 * 1000;
  51.   float modbuswert_float_2 = sensors.getTempC(Sensor2);
  52.   au16data[2] = modbuswert_float_2 * 1000;
  53.   float modbuswert_float_3 = sensors.getTempC(Sensor3);
  54.   au16data[3] = modbuswert_float_3 * 1000;
  55.   float modbuswert_float_4 = sensors.getTempC(Sensor4);
  56.   au16data[4] = modbuswert_float_4 * 1000;
  57.   float modbuswert_float_5 = sensors.getTempC(Sensor5);
  58.   au16data[5] = modbuswert_float_5 * 1000;
  59.   slave.poll( au16data, 6 );
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement