Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <ModbusMaster.h>
- #define RX_PIN 2
- #define TX_PIN 3
- #define SLAVE_ID 2
- #define BAUD_RATE 9600
- SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
- ModbusMaster node;
- void setup() {
- Serial.begin(9600);
- while (!Serial);
- modbusSerial.begin(BAUD_RATE);
- node.begin(SLAVE_ID, modbusSerial);
- Serial.println("--- Renke Live Radiation Monitor ---");
- }
- void loop() {
- // Read 6 registers starting at 0x0000
- uint8_t result = node.readHoldingRegisters(0x0000, 6);
- if (result == node.ku8MBSuccess) {
- Serial.print("Reg[0]="); Serial.print(node.getResponseBuffer(0));
- Serial.print(" | Reg[1]="); Serial.print(node.getResponseBuffer(1));
- Serial.print(" | Reg[2]="); Serial.print(node.getResponseBuffer(2));
- Serial.print(" | Reg[3]="); Serial.print(node.getResponseBuffer(3));
- Serial.print(" | Reg[4]="); Serial.print(node.getResponseBuffer(4));
- Serial.print(" | Reg[5]="); Serial.println(node.getResponseBuffer(5));
- } else {
- Serial.print("Read Failed. Error: 0x");
- Serial.println(result, HEX);
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment