Last active
September 15, 2024 07:53
-
-
Save maxpromer/eea39be6658393d26efd5f4fc329f160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ModbusMaster.h> | |
ModbusMaster decibel; | |
void setup() { | |
Serial.begin(115200); | |
// Modbus communication runs at 9600 baud | |
Serial2.begin(9600, SERIAL_8N1, 27, 26); // IOXESP32 Modbus RTU shield | |
// ATS-DECIBEL init with Modbus slave ID 1 | |
decibel.begin(1, Serial2); | |
} | |
void loop() { | |
// ATS-DECIBEL read | |
uint8_t result; | |
result = decibel.readInputRegisters(1, 2); // Read Input Register start at 1 -> 2 word (0x0001 - 0x0002) | |
if (result == decibel.ku8MBSuccess) { | |
float sound_level_db = decibel.getResponseBuffer(0) / 10.0; | |
Serial.println("Sound Level: " + String(sound_level_db, 1) + " dB"); | |
} else { | |
Serial.println("Read ATS-DECIBEL error, check your serial configs, wiring and power supply"); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment