7.3 KiB
Modbus Reading for Schneider PowerLogic PM8000
This is a specification and implementation of the Arduino-based Modbus data logger for the Schneider PowerLogic PM8000. This software is designed for Vivarox EMS and only Vivarox has right to use and modify this software.
Arduino Implementation:
This project uses an Arduino to connect to Modbus devices, read information, and log it onto an SD card with timestamps.
Hardware needed:
-
Arduino Board Recommended: Arduino MEGA 2560 (for more memory and I/O pins) or Arduino UNO (for simpler projects).
-
RS485 to TTL Module Allows communication between the Arduino and Modbus devices using the RS485 protocol.
-
SD Card Module Allows the Arduino to read from and write data to an SD card.
-
RTC Module To keep track of the current date and time, even when the Arduino is powered off.
-
Power Supply To power the Arduino and connected peripherals.
-
LED Indicators Two LEDs for status indication (not included in original cost estimate).
Wiring
RS485 Module to Arduino:
- RO (Receiver Output) to Arduino RX (pin 8)
- DI (Driver Input) to Arduino TX (pin 7)
- DE (Driver Enable) & RE (Receiver Enable) to Arduino digital pin 4
- VCC to 5V on Arduino
- GND to GND on Arduino
- A & B (RS485 differential pair) to Modbus device
SD Card Module to Arduino:
- VCC to 5V on Arduino
- GND to GND on Arduino
- MOSI to MOSI (pin 51 on MEGA, pin 11 on UNO)
- MISO to MISO (pin 50 on MEGA, pin 12 on UNO)
- SCK to SCK (pin 52 on MEGA, pin 13 on UNO)
- CS (Chip Select) to digital pin 10
RTC Module to Arduino:
- VCC to 5V on the Arduino
- GND to GND on the Arduino
- SDA to SDA (pin 20 on MEGA, pin A4 on UNO)
- SCL to SCL (pin 21 on MEGA, pin A5 on UNO)
LED Indicators:
- LED A to digital pin 3
- LED B to digital pin 5
Software
- Modbus Library: ModbusMaster
- SD Library: SdFat (more advanced than the standard SD library)
- RTC Library: RTClib by Adafruit
- NeoSWSerial: For better latency on software serial communication
Implementation Details
-
Modbus Configuration:
- Slave ID: 101
- Baud Rate: 9600
- Register map: Defined in separate "register_map_pm8000.h" file
-
Data Logging:
- Frequency: Readings taken every second
- File Format: CSV (Comma-Separated Values)
- Filename: "pm8k_YYYYMMDD.csv" (generated daily based on current date)
- Data Structure: Timestamp, followed by register values
- Header Row: Includes register addresses for easy identification
-
Register Types Supported:
- Float (32-bit)
- Integer (32-bit)
- Long (64-bit)
- String (up to 20 characters)
-
Error Handling and Status Indication:
- LED A: Indicates successful data writing and transmission
- LED B: Indicates errors (e.g., SD card issues, RTC problems, Modbus communication errors)
- Serial output for debugging (9600 baud)
-
Special Features:
- Automatic creation of new log file on date change
- Header row written only once per file
- Robust error handling for SD card, RTC, and Modbus communication
Programming Workflow
- Initialize hardware (RTC, SD card, RS485 module)
- Set up Modbus communication parameters
- Enter main loop:
- Read current time from RTC
- Read data from Modbus registers
- Write timestamped data to SD card
- Handle any errors and provide status indication via LEDs
- Delay for 1 second before next reading
Costs
Estimated cost of the hardware from suppliers like Micro Robotics, excluding labor to assemble:
- R617.00 per unit using the Arduino MEGA
- R374.50 per unit using the Arduino UNO
Note: These costs do not include the additional LEDs for status indication.
Additional Notes
- The system is designed to reset and write logs to newly inserted SD cards automatically.
- Error handling includes visual feedback via LED indicators and detailed serial output for debugging.
- The modular design allows for easy expansion of register types and Modbus devices.
For more detailed implementation, refer to the Source Code.
Memory Limitations and Register Customization
Memory Constraints
The Arduino, particularly models like the UNO and MEGA, has limited memory available for storing program code and variables. This limitation affects the number of Modbus registers that can be defined and read in a single project.
- Arduino UNO: 32 KB Flash (program storage), 2 KB SRAM
- Arduino MEGA: 256 KB Flash, 8 KB SRAM
Due to these constraints, the number of registers that can be defined in the register_map_pm8000.h
file is not unlimited. The exact number will depend on the complexity of your code and other libraries used.
Customizing the Register Map
To adapt this project to your specific needs, you can modify the register_map_pm8000.h
file. This file contains the definitions of Modbus registers to be read by the Arduino.
To customize the register map:
-
Open the
register_map_pm8000.h
file in your Arduino IDE or text editor. -
Locate the
registers
array in the file. It should look something like this:const RegisterInfo registers[] PROGMEM = { {40001, 2}, // Example register {40003, 1}, // ... other registers ... };
-
To remove a register, simply comment out its line by adding
//
at the beginning:const RegisterInfo registers[] PROGMEM = { {40001, 2}, // Example register // {40003, 1}, // This register is now commented out and won't be read // ... other registers ... };
-
To add a new register, add a new line to the array with the register address and type:
const RegisterInfo registers[] PROGMEM = { {40001, 2}, // Example register {40003, 1}, {40005, 2}, // New register added // ... other registers ... };
-
Remember to keep the array syntax correct, with commas between entries and a semicolon at the end of the array.
Best Practices
- Start by commenting out registers you don't need before adding new ones.
- If you're using an Arduino UNO, you may need to be more selective about which registers to include due to memory constraints.
- Test your modifications incrementally to ensure the Arduino can handle the memory load.
- If you need to read a large number of registers, consider using an Arduino MEGA or a more powerful microcontroller.
By carefully managing the registers in the register_map_pm8000.h
file, you can customize this Modbus reader to suit your specific requirements while staying within the memory limitations of your Arduino board.