Advertisement
pleasedontcode

"Arduino Temperature Modbus" rev_04

Jan 2nd, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Arduino Temperature Modbus"
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-01-02 13:26:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* modbus slave */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <ModBusSlave0.h>
  26. #include <NonBlockingDallas.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void prepareResponse03(uint8_t *frame, uint8_t *data);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t ANALOGSENSOR2_DS18B20_DQ_PIN_D2 = 2;
  35.  
  36. /***** DEFINITION OF ANALOG INPUT PINS *****/
  37. const uint8_t ANALOGSENSOR2_Potentiometer_Vout_PIN_A0 = A0;
  38.  
  39. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  40. OneWire oneWire(ANALOGSENSOR2_DS18B20_DQ_PIN_D2);
  41. DallasTemperature dallasTemp(&oneWire);
  42. NonBlockingDallas sensorDs18b20(&dallasTemp);
  43. ModBusSlave0 mod;
  44.  
  45. void setup(void)
  46. {
  47.   // put your setup code here, to run once:
  48.   Serial.begin(9600);
  49.   sensorDs18b20.begin(NonBlockingDallas::resolution_12, NonBlockingDallas::unit_C, 1500); // Initialize the NonBlockingDallas library
  50.  
  51.   mod.begin(57600, ANALOGSENSOR2_DS18B20_DQ_PIN_D2, 100); // Initialize the ModBusSlave0 library
  52.   mod.prepareResponse03 = prepareResponse03; // Set the callback function for response preparation
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.   sensorDs18b20.update(); // Update the NonBlockingDallas library
  59.   mod.process(); // Process Modbus requests
  60. }
  61.  
  62. void prepareResponse03(uint8_t *frame, uint8_t *data)
  63. {
  64.   // Implement the logic for preparing the response to Modbus function code 03 (Read Holding Registers)
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement