Changes for the Arduino Mega setups

This commit is contained in:
warkanum committed 2024-12-07 10:20:29 +02:00
1 parent dc2b3429a6
commit 4c77b98388
45 files changed
+1705

No files matched your search

@@ -0,0 +1,271 @@
#include <Wire.h> // Library for I2C communication
#include <RTClib.h> // Library for Real Time Clock
#include <ModbusMaster.h> // Library for Modbus communication
#include "util.h" // Custom utility functions
#include "register_map.h" // Map of Modbus registers to read
#include <SPI.h> // Library for SPI communication
#include <SdFat.h> // Enhanced SD card library
// ==== PIN CONNECTIONS AND SETTINGS ====
/*
Physical Connections Guide:
SD CARD MODULE:
- CS -> Arduino MEGA pin 53 (Hardware SS)
- MOSI -> Arduino MEGA pin 51
- MISO -> Arduino MEGA pin 50
- SCK -> Arduino MEGA pin 52
- VCC -> 5V
- GND -> GND
RS485 MODULE:
- DI -> Arduino MEGA TX1 (Pin 18)
- RO -> Arduino MEGA RX1 (Pin 19)
- DE & RE -> Arduino MEGA Pin 4
- VCC -> 5V
- GND -> GND
RTC MODULE (DS3231):
- SDA -> Arduino MEGA Pin 20
- SCL -> Arduino MEGA Pin 21
- VCC -> 5V
- GND -> GND
STATUS LEDs:
- LED A -> Arduino MEGA Pin 3
- LED B -> Arduino MEGA Pin 5
*/
// ==== CONFIGURATION SETTINGS ====
#define SD_CS_PIN 53 // SD card chip select pin (MEGA's SS pin)
#define DE_RE_PIN 4 // RS485 direction control
#define SLAVE_ID 101 // Modbus device address
#define SERIAL_BAUDRATE 115200 // Debug communication speed
#define MODBUS_BAUDRATE 9600 // Modbus communication speed
#define LED_A_PIN 3 // Activity LED
#define LED_B_PIN 5 // Error LED
#define MAX_RETRIES 3 // Maximum read attempts
#define ERROR_VALUE -999.99 // Error indicator value
// ==== SD CARD CONFIGURATION ====
#define SPI_CLOCK SD_SCK_MHZ(16) // SD card speed (16MHz for stability)
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
#endif
// ==== GLOBAL OBJECTS ====
RTC_DS3231 rtc; // RTC object
SdFat32 sd; // SD card object
File dataFile; // File object
ModbusMaster node; // Modbus object
// ==== GLOBAL VARIABLES ====
unsigned long lastRefreshTime = 0;
bool headerWritten = false;
bool booted = false;
// ==== UTILITY FUNCTIONS ====
void flicker(uint8_t pin, uint8_t times, uint16_t speed) {
for (uint8_t i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(speed);
digitalWrite(pin, LOW);
delay(speed);
}
}
// ==== SETUP FUNCTION ====
void setup() {
booted = false;
// Initialize status LEDs
pinMode(LED_A_PIN, OUTPUT);
pinMode(LED_B_PIN, OUTPUT);
digitalWrite(LED_A_PIN, LOW);
digitalWrite(LED_B_PIN, HIGH); // Error LED on until setup complete
// Start debug serial communication
Serial.begin(SERIAL_BAUDRATE);
Serial.println(F("Startup"));
// Start Modbus serial communication (Hardware Serial1)
Serial1.begin(MODBUS_BAUDRATE);
// Initialize RTC
if (!rtc.begin()) {
Serial.println(F("RTC initialization failed"));
flicker(LED_B_PIN, 4, 1000);
return;
}
if (rtc.lostPower()) {
Serial.println(F("RTC lost power, setting time"));
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
flicker(LED_B_PIN, 4, 500);
}
// Initialize SD card
pinMode(SD_CS_PIN, OUTPUT);
digitalWrite(SD_CS_PIN, HIGH); // Ensure SS pin is high initially
if (!sd.begin(SD_CONFIG)) {
Serial.println(F("SD card initialization failed"));
flicker(LED_B_PIN, 2, 1000);
return;
}
// Initialize Modbus
pinMode(DE_RE_PIN, OUTPUT);
digitalWrite(DE_RE_PIN, LOW); // Start in receive mode
node.begin(SLAVE_ID, Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
flicker(LED_B_PIN, 10, 100); // Setup success indicator
digitalWrite(LED_B_PIN, LOW);
booted = true;
}
// ==== RS485 CONTROL FUNCTIONS ====
void preTransmission() {
digitalWrite(DE_RE_PIN, HIGH);
digitalWrite(LED_A_PIN, HIGH);
delayMicroseconds(50); // Give RS485 time to switch
}
void postTransmission() {
delayMicroseconds(50); // Give RS485 time to switch
digitalWrite(DE_RE_PIN, LOW);
digitalWrite(LED_A_PIN, LOW);
}
// ==== FILE OPERATIONS ====
String getFilename() {
DateTime now = rtc.now();
char buffer[20];
sprintf(buffer, "pm8k_%d%02d%02d.csv", now.year(), now.month(), now.day());
return String(buffer);
}
void writeDateTime() {
DateTime now = rtc.now();
dataFile.print('\n');
dataFile.print(now.year(), DEC);
dataFile.print('-');
dataFile.print(now.month(), DEC);
dataFile.print('-');
dataFile.print(now.day(), DEC);
dataFile.print(' ');
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(',');
}
// ==== MODBUS OPERATIONS ====
float readRegisterWithRetry(uint16_t addr, uint8_t regtype) {
for (uint8_t retry = 0; retry < MAX_RETRIES; retry++) {
delay(5); // Short delay between attempts
uint8_t result = node.readHoldingRegisters(addr - 1, 2);
if (result == node.ku8MBSuccess) {
switch(regtype) {
case 1: // Integer
return node.getResponseBuffer(0);
case 2: // Float
return getRegisterFloat(node.getResponseBuffer(0), node.getResponseBuffer(1));
case 0: // 32-bit Integer
return getRegisterInt32(node.getResponseBuffer(0), node.getResponseBuffer(1));
case 5: // String
String str;
for (uint8_t j = 0; j < 20; j++) {
uint8_t v = node.getResponseBuffer(j);
if (v == 0) break;
str += (char)v;
}
return str.toFloat();
}
}
Serial.print(F("Read error at register "));
Serial.print(addr);
Serial.print(F(", attempt "));
Serial.println(retry + 1);
delay(50 * (retry + 1)); // Increasing delay between retries
flicker(LED_B_PIN, 1, 50);
}
return ERROR_VALUE;
}
// ==== MAIN LOOP ====
void loop() {
if (!booted) {
Serial.println(F("Boot failed, retrying in 10 seconds"));
delay(10000);
return;
}
if (millis() - lastRefreshTime >= 1000) {
lastRefreshTime += 1000;
String filename = getFilename();
uint8_t errorCount = 0;
if (!dataFile.open(filename.c_str(), FILE_WRITE)) {
Serial.println(F("Failed to open file"));
flicker(LED_B_PIN, 6, 500);
return;
}
if (!headerWritten) {
dataFile.print(F("\nDate Time,"));
const uint16_t totalReg = sizeof(registers) / sizeof(registers[0]);
for (uint16_t i = 0; i < totalReg; i++) {
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
dataFile.print(F("@"));
dataFile.print(regaddr);
dataFile.print(F(","));
}
headerWritten = true;
flicker(LED_A_PIN, 3, 100);
}
writeDateTime();
// Read all registers
const uint16_t totalReg = sizeof(registers) / sizeof(registers[0]);
for (uint16_t i = 0; i < totalReg; i++) {
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
const uint8_t regtype = pgm_read_word(&registers[i].regtype);
if (regaddr > 0) {
float value = readRegisterWithRetry(regaddr, regtype);
if (value == ERROR_VALUE) {
errorCount++;
if (errorCount > 5) {
Serial.println(F("Too many errors, aborting cycle"));
dataFile.close();
return;
}
}
dataFile.print(value);
dataFile.print(F(","));
}
}
dataFile.close();
if (errorCount > 0) {
flicker(LED_B_PIN, errorCount, 200);
} else {
flicker(LED_A_PIN, 1, 100);
}
}
}
@@ -0,0 +1,135 @@
# 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 MEGA 2560 to connect to Modbus devices, read information, and log it onto an SD card with timestamps. The MEGA 2560 is particularly well-suited for this project due to its increased memory capacity and multiple hardware serial ports.
### Hardware needed:
1. Arduino Board
Required: Arduino MEGA 2560 (selected for its 256KB flash memory, 8KB SRAM, and multiple hardware serial ports)
- [Arduino MEGA @ R377.20](https://www.robotics.org.za/MEGA-16U2?search=Arduino%20MEGA%202560)
2. RS485 to TTL Module
Allows communication between the Arduino and Modbus devices using the RS485 protocol.
- [RS485 Module (TTL -> RS485) @ R25.30](https://www.robotics.org.za/RS485-MOD)
- [MAX485 Bus Transceiver (4 Pack) @ R16.00](https://www.robotics.org.za/MAX485-DIP?search=MAX485)
3. SD Card Module
Allows the Arduino to read from and write data to an SD card.
- [Micro SD Card Module @ R25.00](https://www.diyelectronics.co.za/store/memory/512-micro-sd-card-module.html?srsltid=AfmBOoptww8c6kx53xbZWiP2_C_qOE3r9xinyoCO-AZHrZkNQiyxU17c)
4. RTC Module
To keep track of the current date and time, even when the Arduino is powered off.
- [DS3231 Real Time Clock Module @ R55.20](https://www.robotics.org.za/DS3231-MOD?search=DS3231)
5. Power Supply
To power the Arduino and connected peripherals.
- [AC Adapter 9V with barrel jack @ R60](https://www.robotics.org.za/AC-9V-2A-2155?search=%20Power%20Supply)
6. LED Indicators
Two LEDs for status indication (not included in original cost estimate).
### Wiring for MEGA 2560
#### RS485 Module to Arduino MEGA:
1. RO (Receiver Output) to MEGA RX1 (pin 19) - Using Hardware Serial1
2. DI (Driver Input) to MEGA TX1 (pin 18) - Using Hardware Serial1
3. DE (Driver Enable) & RE (Receiver Enable) to MEGA digital pin 4
4. VCC to 5V on MEGA
5. GND to GND on MEGA
6. A & B (RS485 differential pair) to Modbus device
#### SD Card Module to Arduino MEGA:
1. VCC to 5V on MEGA
2. GND to GND on MEGA
3. MOSI to MOSI (pin 51)
4. MISO to MISO (pin 50)
5. SCK to SCK (pin 52)
6. CS (Chip Select) to digital pin 53
#### RTC Module to Arduino MEGA:
1. VCC to 5V on the MEGA
2. GND to GND on the MEGA
3. SDA to SDA (pin 20)
4. SCL to SCL (pin 21)
#### LED Indicators:
1. LED A to digital pin 3
2. 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
### Implementation Details
1. Modbus Configuration:
- Slave ID: 1
- Baud Rate: 9600
- Register map: Defined in separate "register_map.h" file
- Using Hardware Serial1 for improved reliability
2. Data Logging:
- Frequency: Readings taken every second
- File Format: CSV (Comma-Separated Values)
- Filename: "log_YYYYMMDD.csv" (generated daily based on current date)
- Data Structure: Timestamp, followed by register values
- Header Row: Includes register addresses for easy identification
- Larger buffer sizes possible due to MEGA's increased memory
3. Register Types Supported:
- Float (32-bit)
- Integer (32-bit)
- Long (64-bit)
- String (up to 20 characters)
- Multiple register reads supported simultaneously due to larger memory
4. 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 (115200 baud possible due to hardware serial)
5. 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
- Support for larger register maps due to increased memory
- Possibility to implement multiple Modbus device communication using additional hardware serial ports
### Programming Workflow
1. Initialize hardware (RTC, SD card, RS485 module)
2. Set up Modbus communication parameters using Hardware Serial1
3. Enter main loop:
- Read current time from RTC
- Read data from Modbus registers (larger batches possible)
- Write timestamped data to SD card
- Handle any errors and provide status indication via LEDs
- Delay for 1 second before next reading
## MEGA-Specific Advantages
- More memory allows reading more registers simultaneously
- Hardware serial ports provide more reliable communication
- Additional I/O pins available for expansion
- Possibility to monitor multiple Modbus devices using different serial ports
- Larger program space allows for more complex error handling and data processing
- No need to be selective about registers due to memory constraints
- Can implement additional features like local display or network connectivity
## Best Practices
- Use Hardware Serial1 (pins 18/19) for primary Modbus communication
- Additional Modbus devices can use Serial2 (pins 16/17) or Serial3 (pins 14/15)
- Take advantage of the extra memory to implement robust error checking
- Consider using the additional I/O pins for status displays or control interfaces
- You can include all registers from your register map without memory concerns
- Consider implementing a circular buffer for temporary data storage
File renamed without changes.
@@ -0,0 +1,356 @@
#include <Wire.h> // Library for I2C communication (used by RTC)
#include <RTClib.h> // Library for Real Time Clock
#include <ModbusMaster.h> // Library for Modbus communication
#include "util.h" // Custom utility functions
#include "register_map.h" // Map of Modbus registers to read
#include <SPI.h> // Library for SPI communication (used by SD card)
#include <SdFat.h> // Enhanced SD card library
// ==== PIN CONNECTIONS AND SETTINGS ====
/*
Physical Connections Guide:
SD CARD MODULE:
- CS (Chip Select) -> Arduino MEGA pin 53
- MOSI -> Arduino MEGA pin 51
- MISO -> Arduino MEGA pin 50
- SCK -> Arduino MEGA pin 52
- VCC -> 5V
- GND -> GND
RS485 MODULE:
- DI (Data In) -> Arduino MEGA TX1 (Pin 18)
- RO (Receive Out) -> Arduino MEGA RX1 (Pin 19)
- DE & RE (Data/Receive Enable) -> Arduino MEGA Pin 4
- VCC -> 5V
- GND -> GND
- A & B -> To Modbus device (polarity sensitive)
RTC MODULE (DS3231):
- SDA -> Arduino MEGA Pin 20
- SCL -> Arduino MEGA Pin 21
- VCC -> 5V
- GND -> GND
STATUS LEDs:
- LED A (Activity) -> Arduino MEGA Pin 3 (blinks during normal operation)
- LED B (Error) -> Arduino MEGA Pin 5 (blinks during errors)
*/
// ==== CONFIGURATION SETTINGS ====
#define SD_CS_PIN 53 // SD card chip select pin (uses MEGA's default SS pin)
#define DE_RE_PIN 4 // Controls RS485 direction (transmit/receive switching)
#define SLAVE_ID 1 // Modbus device address (change to match your device)
#define SERIAL_BAUDRATE 115200 // Speed for debug messages via USB
#define MODBUS_SERIAL_BAUDRATE 9600 // Speed for Modbus communication
#define LED_A_PIN 3 // Activity LED (blinks during normal operation)
#define LED_B_PIN 5 // Error LED (blinks when problems occur)
#define MAX_RETRIES 1 // Number of times to retry failed readings
#define ERROR_VALUE -999.99 // Value used to indicate reading errors
// ==== SD CARD CONFIGURATION ====
// Sets up the SD card for optimal performance with MEGA
#define SPI_CLOCK SD_SCK_MHZ(16) // //50 (fast) //16 (half) //4 (slow) SD card speed (50MHz)
// Choose the best SD card mode based on hardware capabilities
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO) // Use SDIO if available (faster)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK) // Dedicated SPI bus
#else
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK) // Shared SPI bus
#endif
// ==== GLOBAL OBJECTS ====
RTC_DS3231 rtc; // Real Time Clock object for timekeeping
SdFat32 sd; // SD card object for file operations
File dataFile; // File object for data logging
ModbusMaster node; // Modbus communication object
// ==== GLOBAL VARIABLES ====
unsigned long lastRefreshTime = 0; // Tracks time between readings
bool headerWritten = false; // Tracks if CSV header has been written
bool booted = false; // Tracks if setup completed successfully
// ==== UTILITY FUNCTIONS ====
// Makes an LED blink a specified number of times
// pin: which LED to blink
// times: how many blinks
// speed: how fast to blink (in milliseconds)
void flicker(uint8_t pin, uint8_t times, uint16_t speed) {
while(times--) {
delay(speed);
digitalWrite(pin, HIGH); // Turn LED on
delay(speed);
digitalWrite(pin, LOW); // Turn LED off
}
}
// ==== SETUP FUNCTION ====
// Runs once when the Arduino starts or resets
// Initializes all hardware and prepares for operation
void setup() {
booted = false; // Mark as not ready
// Setup status LEDs
pinMode(LED_A_PIN, OUTPUT);
pinMode(LED_B_PIN, OUTPUT);
digitalWrite(LED_A_PIN, LOW); // Activity LED off
digitalWrite(LED_B_PIN, HIGH); // Error LED on until setup complete
// Start serial communication for debugging via USB
Serial.begin(SERIAL_BAUDRATE);
Serial.println(F("Startup \n"));
// Start serial communication for Modbus (using hardware Serial1)
Serial1.begin(MODBUS_SERIAL_BAUDRATE);
// Initialize Real Time Clock
if (!rtc.begin()) {
Serial.println(F("Couldn't find RTC\n"));
flicker(LED_B_PIN, 4, 1000); // Error pattern: 4 slow blinks
digitalWrite(LED_B_PIN, HIGH);
digitalWrite(LED_A_PIN, HIGH);
return; // Stop if RTC fails
}
// Check if RTC lost power and reset time if needed
if (rtc.lostPower()) {
Serial.println(F("RTC lost power, let's set the time!\n"));
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set to compile time
flicker(LED_B_PIN, 4, 500); // Warning pattern: 4 medium blinks
}
// Initialize SD card
pinMode(SD_CS_PIN, OUTPUT);
// Set pin to high, hopefully fix Mega issue
digitalWrite(SD_CS_PIN, HIGH);
if (!sd.begin(SD_CONFIG)) {
flicker(LED_B_PIN, 2, 1000); // Error pattern: 2 slow blinks
digitalWrite(LED_B_PIN, HIGH);
sd.initErrorHalt(&Serial);
return; // Stop if SD card fails
}
// Setup RS485 communication direction control
pinMode(DE_RE_PIN, OUTPUT);
digitalWrite(DE_RE_PIN, LOW); // Start in receive mode
// Initialize Modbus communication
node.begin(SLAVE_ID, Serial1); // Using Hardware Serial1 for Modbus
node.preTransmission(preTransmission); // Set callbacks for RS485 direction control
node.postTransmission(postTransmission);
flicker(LED_B_PIN, 10, 100); // Success pattern: 10 quick blinks
digitalWrite(LED_B_PIN, LOW); // Turn off error LED
booted = true; // Mark setup as complete
}
// ==== RS485 CONTROL FUNCTIONS ====
// Called before Modbus transmission begins
void preTransmission() {
digitalWrite(DE_RE_PIN, HIGH); // Enable transmitter
digitalWrite(LED_A_PIN, HIGH); // Turn on activity LED
}
// Called after Modbus transmission completes
void postTransmission() {
digitalWrite(DE_RE_PIN, LOW); // Enable receiver
digitalWrite(LED_A_PIN, LOW); // Turn off activity LED
}
// ==== FILE OPERATIONS ====
// Writes the current date and time to the CSV file
void writeDateTime(File &file) {
DateTime now = rtc.now(); // Get current time from RTC
file.print('\n'); // Start new line
// Write date and time in format: YYYY-MM-DD HH:MM:SS,
file.print(now.year(), DEC);
file.print('-');
file.print(now.month(), DEC);
file.print('-');
file.print(now.day(), DEC);
file.print(' ');
file.print(now.hour(), DEC);
file.print(':');
file.print(now.minute(), DEC);
file.print(':');
file.print(now.second(), DEC);
file.print(',');
}
// Generates filename based on current date (format: pm8k_YYYYMMDD.csv)
void getFilename(char* buffer) {
DateTime now = rtc.now();
sprintf(buffer, "log_%d%02d%02d.csv", now.year(), now.month(), now.day());
}
// ==== MODBUS OPERATIONS ====
// Reads a Modbus register with retry capability
// addr: register address to read
// regtype: type of register (1=int, 2=float, 3=long)
// Returns: register value or ERROR_VALUE if failed
float readRegisterWithRetry(uint16_t addr, uint8_t regtype) {
for(uint8_t retry = 0; retry < MAX_RETRIES; retry++) {
delay(5); // Short delay between attempts
uint8_t result = node.readHoldingRegisters(addr - 1, 2); // Read register
if(result == node.ku8MBSuccess) {
// Convert register value based on type
switch(regtype) {
case 1: // Integer
return node.getResponseBuffer(0);
case 2: // Float
return getRegisterFloat(node.getResponseBuffer(0), node.getResponseBuffer(1));
case 3: // Long
return getRegisterInt64(node.getResponseBuffer(0), node.getResponseBuffer(1),
node.getResponseBuffer(2), node.getResponseBuffer(3));
}
}
// Log error if read failed
Serial.print(F("Read error at register "));
Serial.print(addr);
Serial.print(F(", attempt "));
Serial.print(retry + 1);
Serial.print(F(" of "));
Serial.print(MAX_RETRIES);
Serial.print(F(", error code: "));
Serial.println(result);
delay(5 * (retry + 1)); // Increasing delay between retries
flicker(LED_B_PIN, 1, 50); // Quick error blink
}
return ERROR_VALUE; // Return error value if all retries failed
}
// Writes the CSV header row if it hasn't been written yet
void writeHeader() {
if (!headerWritten) {
dataFile.print("\nDate Time,");
// Write register addresses as column headers
const uint16_t totalReg = sizeof(registers) / sizeof(registers[0]);
for (uint16_t i = 0; i < totalReg; i++) {
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
dataFile.print("@");
dataFile.print(regaddr);
dataFile.print(",");
}
headerWritten = true;
flicker(LED_A_PIN, 50, 10); // Success pattern: 50 quick blinks
}
}
// ==== MAIN PROGRAM LOOP ====
void loop() {
// If setup failed, wait and try again
if (!booted) {
delay(10000); // Wait 10 seconds
digitalWrite(LED_A_PIN, LOW);
return;
}
// Check if it's time for next reading (every 1000ms)
if (millis() - lastRefreshTime >= 1000) {
lastRefreshTime += 1000;
// Create new file for today's date
char filename[20];
getFilename(filename);
// Try to open the data file
if (!dataFile.open(filename, FILE_WRITE)) {
flicker(LED_B_PIN, 6, 500); // Error pattern: 6 medium blinks
return;
}
// Write header if needed and timestamp
writeHeader();
writeDateTime(dataFile);
// Initialize variables for reading registers
const uint16_t totalReg = sizeof(registers) / sizeof(registers[0]);
float baseValues[4] = {ERROR_VALUE, ERROR_VALUE, ERROR_VALUE, ERROR_VALUE};
uint8_t errorCount = 0;
// Read and process all registers
for (uint16_t i = 0; i < totalReg; i++) {
// Get register information
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
const uint8_t regtype = pgm_read_word(&registers[i].regtype);
const float scale = pgm_read_float(&registers[i].scale);
float value = ERROR_VALUE;
// Read basic register types
if (regtype <= 3 && regaddr > 0) {
value = readRegisterWithRetry(regaddr, regtype);
if (value == ERROR_VALUE) {
errorCount++;
if (errorCount > 5) { // Too many errors, abort
dataFile.close();
flicker(LED_B_PIN, 10, 100); // Error pattern: 10 quick blinks
return;
}
}
if (i < 4) baseValues[i] = value; // Store first 4 values for calculations
} else {
// Check if we have valid base values for calculations
bool validBase = true;
for(uint8_t j = 0; j < 4; j++) {
if (baseValues[j] == ERROR_VALUE) {
validBase = false;
break;
}
}
// Calculate derived values if base values are valid
if (validBase) {
switch(regtype) {
case 4:
value = calculateStatusWord(baseValues);
break;
case 5:
value = calculateThermal(baseValues);
break;
case 6:
value = calculatePower(baseValues);
break;
case 7:
value = calculateRPM(baseValues);
break;
}
}
}
// Apply scaling factor if value is valid
if (value != ERROR_VALUE) {
value *= scale;
}
// Write value to file
dataFile.print(value);
dataFile.print(',');
}
// Close file after writing
dataFile.close();
// Report status
if (errorCount > 0) {
Serial.print(F("Cycle completed with "));
Serial.print(errorCount);
Serial.println(F(" errors"));
flicker(LED_B_PIN, errorCount, 200); // Error pattern: blink count = error count
} else {
Serial.println(F("Cycle completed successfully"));
flicker(LED_A_PIN, 4, 100); // Success pattern: 4 quick blinks
}
// Abort if too many errors
if (errorCount > 5) {
Serial.println(F("Too many errors, aborting cycle"));
dataFile.close();
return;
}
}
}
@@ -0,0 +1,135 @@
# Modbus Reading for Generic VSD Device - MEGA Implementation
This is a specification and implementation of the Arduino MEGA 2560-based Modbus data logger for a Generic VSD Device.
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 MEGA 2560 to connect to Modbus devices, read information, and log it onto an SD card with timestamps. The MEGA 2560 is particularly well-suited for this project due to its increased memory capacity and multiple hardware serial ports.
### Hardware needed:
1. Arduino Board
Required: Arduino MEGA 2560 (selected for its 256KB flash memory, 8KB SRAM, and multiple hardware serial ports)
- [Arduino MEGA @ R377.20](https://www.robotics.org.za/MEGA-16U2?search=Arduino%20MEGA%202560)
2. RS485 to TTL Module
Allows communication between the Arduino and Modbus devices using the RS485 protocol.
- [RS485 Module (TTL -> RS485) @ R25.30](https://www.robotics.org.za/RS485-MOD)
- [MAX485 Bus Transceiver (4 Pack) @ R16.00](https://www.robotics.org.za/MAX485-DIP?search=MAX485)
3. SD Card Module
Allows the Arduino to read from and write data to an SD card.
- [Micro SD Card Module @ R25.00](https://www.diyelectronics.co.za/store/memory/512-micro-sd-card-module.html?srsltid=AfmBOoptww8c6kx53xbZWiP2_C_qOE3r9xinyoCO-AZHrZkNQiyxU17c)
4. RTC Module
To keep track of the current date and time, even when the Arduino is powered off.
- [DS3231 Real Time Clock Module @ R55.20](https://www.robotics.org.za/DS3231-MOD?search=DS3231)
5. Power Supply
To power the Arduino and connected peripherals.
- [AC Adapter 9V with barrel jack @ R60](https://www.robotics.org.za/AC-9V-2A-2155?search=%20Power%20Supply)
6. LED Indicators
Two LEDs for status indication (not included in original cost estimate).
### Wiring for MEGA 2560
#### RS485 Module to Arduino MEGA:
1. RO (Receiver Output) to MEGA RX1 (pin 19) - Using Hardware Serial1
2. DI (Driver Input) to MEGA TX1 (pin 18) - Using Hardware Serial1
3. DE (Driver Enable) & RE (Receiver Enable) to MEGA digital pin 4
4. VCC to 5V on MEGA
5. GND to GND on MEGA
6. A & B (RS485 differential pair) to Modbus device
#### SD Card Module to Arduino MEGA:
1. VCC to 5V on MEGA
2. GND to GND on MEGA
3. MOSI to MOSI (pin 51)
4. MISO to MISO (pin 50)
5. SCK to SCK (pin 52)
6. CS (Chip Select) to digital pin 53
#### RTC Module to Arduino MEGA:
1. VCC to 5V on the MEGA
2. GND to GND on the MEGA
3. SDA to SDA (pin 20)
4. SCL to SCL (pin 21)
#### LED Indicators:
1. LED A to digital pin 3
2. 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
### Implementation Details
1. Modbus Configuration:
- Slave ID: 1
- Baud Rate: 9600
- Register map: Defined in separate "register_map.h" file
- Using Hardware Serial1 for improved reliability
2. Data Logging:
- Frequency: Readings taken every second
- File Format: CSV (Comma-Separated Values)
- Filename: "log_YYYYMMDD.csv" (generated daily based on current date)
- Data Structure: Timestamp, followed by register values
- Header Row: Includes register addresses for easy identification
- Larger buffer sizes possible due to MEGA's increased memory
3. Register Types Supported:
- Float (32-bit)
- Integer (32-bit)
- Long (64-bit)
- String (up to 20 characters)
- Multiple register reads supported simultaneously due to larger memory
4. 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 (115200 baud possible due to hardware serial)
5. 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
- Support for larger register maps due to increased memory
- Possibility to implement multiple Modbus device communication using additional hardware serial ports
### Programming Workflow
1. Initialize hardware (RTC, SD card, RS485 module)
2. Set up Modbus communication parameters using Hardware Serial1
3. Enter main loop:
- Read current time from RTC
- Read data from Modbus registers (larger batches possible)
- Write timestamped data to SD card
- Handle any errors and provide status indication via LEDs
- Delay for 1 second before next reading
## MEGA-Specific Advantages
- More memory allows reading more registers simultaneously
- Hardware serial ports provide more reliable communication
- Additional I/O pins available for expansion
- Possibility to monitor multiple Modbus devices using different serial ports
- Larger program space allows for more complex error handling and data processing
- No need to be selective about registers due to memory constraints
- Can implement additional features like local display or network connectivity
## Best Practices
- Use Hardware Serial1 (pins 18/19) for primary Modbus communication
- Additional Modbus devices can use Serial2 (pins 16/17) or Serial3 (pins 14/15)
- Take advantage of the extra memory to implement robust error checking
- Consider using the additional I/O pins for status displays or control interfaces
- You can include all registers from your register map without memory concerns
- Consider implementing a circular buffer for temporary data storage
+52
View File
@@ -0,0 +1,52 @@
ARDUINO MEGA PINOUT
==================
DIGITAL PINS (Basic, D0-D13)
---------------------------
D0 - RX0 (Serial)
D1 - TX0 (Serial)
D2 - Digital
D3 - PWM
D4 - Digital
D5 - PWM
D6 - PWM
D7 - Digital
D8 - Digital
D9 - PWM
D10 - PWM
D11 - PWM
D12 - Digital
D13 - Digital/LED
COMMUNICATION PINS
----------------
D14 - TX3 D15 - RX3
D16 - TX2 D17 - RX2
D18 - TX1 D19 - RX1
D20 - SDA (I2C) D21 - SCL (I2C)
ADDITIONAL DIGITAL PINS
---------------------
D22-D53 - Digital I/O
PWM Pins: 2-13, 44-46
ANALOG PINS (A0-A15)
-------------------
A0-A15 - Analog Inputs
(All can be used as digital I/O)
SPI PINS
--------
50 - MISO
51 - MOSI
52 - SCK
53 - SS
POWER
-----
VIN - Input Voltage (7-12V)
GND - Ground (multiple pins)
5V - 5V Output
3.3V - 3.3V Output
AREF - Analog Reference
RST - Reset
@@ -1,306 +0,0 @@
#include <Wire.h>
#include <RTClib.h>
#include <NeoSWSerial.h>
#include <ModbusMaster.h>
#include "util.h"
#include "register_map_vsd.h"
// #include <SD.h>
#include <SPI.h>
#include <SdFat.h>
#define SD_CS_PIN 10 // Chip Select for SD Card
// RS485 pins
#define DE_RE_PIN 4
#define RX_PIN 8 // SoftwareSerial RX pin
#define TX_PIN 7 // SoftwareSerial TX pin
#define SLAVE_ID 1
#define SERIAL_BAUDRATE 9600
#define LED_A_PID 3
#define LED_B_PID 5
// Try to select the best SD card configuration.
#define SPI_CLOCK SD_SCK_MHZ(50)
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
#endif // HAS_SDIO_CLASS
RTC_DS3231 rtc; // Create an RTC object
SdFat32 sd;
// SdExFat sd;
File dataFile;
NeoSWSerial modbusSerial(RX_PIN, TX_PIN); // Create a software serial instance
ModbusMaster node;
unsigned long lastRefreshTime = 0;
bool headerWritten = false;
bool booted = false;
void flicker(uint8_t pin, uint8_t times, uint16_t speed)
{
for (int i = 0; i < times; i++)
{
delay(speed);
digitalWrite(pin, HIGH);
delay(speed);
digitalWrite(pin, LOW);
}
}
void setup()
{
booted = false;
pinMode(LED_A_PID, OUTPUT);
pinMode(LED_B_PID, OUTPUT);
digitalWrite(LED_A_PID, LOW);
digitalWrite(LED_B_PID, HIGH);
Serial.begin(SERIAL_BAUDRATE); // For debugging
Serial.println(F("Startup \n"));
// Initialize RTC
if (!rtc.begin())
{
Serial.println(F("Couldn't find RTC\n"));
flicker(LED_B_PID, 4, 1000); // 4 times on LED b is RTC Error
digitalWrite(LED_B_PID, HIGH);
digitalWrite(LED_A_PID, HIGH);
return;
}
if (rtc.lostPower())
{
Serial.println(F("RTC lost power, let's set the time!\n"));
// Comment out the following line once the time is set to avoid resetting on every start
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
flicker(LED_B_PID, 4, 500); // 6 times fast on LED b is RTC reset
}
Serial.print(F("Time: "));
Serial.print(rtc.now().timestamp());
Serial.println(F("\n"));
// Initialize SD card
Serial.println(F("SD card initializing..."));
pinMode(SD_CS_PIN, OUTPUT);
// if (!SD.begin(SPI_HALF_SPEED, SD_CS_PIN ))
// {
// Serial.println(F("SD card initialization failed!\n"));
// return;
// }
// Initialize the SD.
if (!sd.begin(SD_CONFIG))
{
flicker(LED_B_PID, 2, 1000);
digitalWrite(LED_B_PID, HIGH);
sd.initErrorHalt(&Serial);
// 2 Times slow and stay on, SD Card initilize error
return;
}
Serial.println(F("SD card initialized.\n"));
Serial.println(F("Initialize RS485 module / Modbus \n"));
pinMode(DE_RE_PIN, OUTPUT);
digitalWrite(DE_RE_PIN, LOW); // Set to LOW for receiving mode initially
modbusSerial.begin(SERIAL_BAUDRATE);
node.begin(SLAVE_ID, modbusSerial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
flicker(LED_B_PID, 10, 100);
digitalWrite(LED_B_PID, LOW);
booted = true;
}
void preTransmission()
{
// Serial.println(F("Transmitting Start"));
digitalWrite(DE_RE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(LED_A_PID, HIGH);
}
void postTransmission()
{
digitalWrite(DE_RE_PIN, LOW); // Disable RS485 transmit
digitalWrite(LED_A_PID, LOW);
// Serial.println(F("Transmitting End"));
}
void primeFileDate()
{
if (!dataFile)
{
Serial.println(F("Error opening file"));
return;
}
DateTime now = rtc.now();
// Log the current date and time
dataFile.print("\n");
dataFile.print(now.year(), DEC);
dataFile.print('-');
dataFile.print(now.month(), DEC);
dataFile.print('-');
dataFile.print(now.day(), DEC);
dataFile.print(" ");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(F(","));
}
String getFilename()
{
DateTime now = rtc.now();
String mb = F("pm8k_");
mb += now.year();
mb += now.month();
mb += now.day();
mb += F(".csv");
return mb;
}
// const char[20] filename = "20240523.csv";
void loop()
{
if (!booted)
{
Serial.print(F("\nBoot failed, cycle "));
delay(10000);
digitalWrite(LED_A_PID, LOW);
return;
}
delay(100);
String writebuffer;
if (millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.print(F("\nTime: "));
Serial.print(rtc.now().timestamp());
// Serial.print("\nHeep:");
// Serial.print(ESP.getFreeHeap());
const uint16_t totalReg = sizeof(registers) / sizeof(registers[0]);
// Open File
String filename = getFilename();
Serial.print(F("Open Card "));
Serial.print(filename.c_str());
Serial.print("\n");
if (!dataFile.open(filename.c_str(), FILE_WRITE))
{
flicker(LED_B_PID, 6, 500); // Six quick flickers. SD Card error
Serial.println(F("Failed to Open Card "));
}
if (!headerWritten)
{
dataFile.print("\nDate Time,");
for (int i = 0; i < totalReg; i++)
{
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
dataFile.print("@");
dataFile.print(regaddr);
dataFile.print(",");
}
headerWritten = true;
flicker(LED_A_PID, 50, 10); // 10 flickers, written header
}
primeFileDate();
Serial.print("\n");
Serial.println(totalReg);
// Modbus Data Loop
for (int i = 0; i < totalReg; i++)
{
const uint16_t regaddr = pgm_read_word(&registers[i].regaddr);
const uint8_t regtype = pgm_read_word(&registers[i].regtype);
Serial.print(F("Reg Read: "));
Serial.println(regtype);
Serial.println(regaddr);
if (regaddr > 0)
{
delay(25); // Gives the pending communication a little delay
uint8_t result = node.readHoldingRegisters(regaddr - 1, 2);
delay(25); // Delay the read for a little bit so that the buffer can be read
if (result == node.ku8MBSuccess)
{
if (regtype == 2)
{
dataFile.print(getRegisterFloat(node.getResponseBuffer(0), node.getResponseBuffer(1)));
}
else if (regtype == 1)
{
dataFile.print(node.getResponseBuffer(0));
}
// else if (regtype == 3)
// {
// dataFile.print(getRegisterInt64(node.getResponseBuffer(0), node.getResponseBuffer(1), node.getResponseBuffer(2), node.getResponseBuffer(3)));
// }
else if (regtype == 0)
{
dataFile.print(getRegisterInt32(node.getResponseBuffer(0), node.getResponseBuffer(1)));
}
else if (regtype == 5)
{
for (uint8_t j = 0; j < 20; j++)
{
uint8_t v = node.getResponseBuffer(j);
char a = v;
if (v == 0) {
break;
}
dataFile.print(a);
}
}
else
{
dataFile.print(F("null"));
}
}
else
{
Serial.print(F("Reg Error: "));
Serial.print(result, HEX);
Serial.print("\n");
dataFile.print(F("E"));
dataFile.print(result, HEX);
flicker(LED_B_PID, 2, 250);
}
dataFile.print(",");
}
}
Serial.print(F("\nRead buffer: "));
delay(10);
if (dataFile)
{
dataFile.close(); // Close the file
Serial.print(F("Data written to SD card: "));
Serial.print(filename.c_str());
Serial.print(F("\n"));
}
Serial.print(F("\n\n"));
flicker(LED_A_PID, 4, 100); // Cycle written 4 quick flickers
}
// // Check if the read was successful
}
@@ -1,120 +0,0 @@
# Modbus Reading for Generic VSD Device
This is a specification and implementation of the Arduino-based Modbus data logger for a Generic VSD Device.
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:
1. Arduino Board
Recommended: Arduino MEGA 2560 (for more memory and I/O pins) or Arduino UNO (for simpler projects).
- [Arduino MEGA @ R377.20](https://www.robotics.org.za/MEGA-16U2?search=Arduino%20MEGA%202560)
- [UNO R3 with 16U2 USB Interface @ R151.00](https://www.robotics.org.za/UNOR3-16U2?search=%20Arduino%20UNO)
2. RS485 to TTL Module
Allows communication between the Arduino and Modbus devices using the RS485 protocol.
- [RS485 Module (TTL -> RS485) @ R25.30](https://www.robotics.org.za/RS485-MOD)
- [MAX485 Bus Transceiver (4 Pack) @ R16.00](https://www.robotics.org.za/MAX485-DIP?search=MAX485)
3. SD Card Module
Allows the Arduino to read from and write data to an SD card.
- [Micro SD Card Module @ R25.00](https://www.diyelectronics.co.za/store/memory/512-micro-sd-card-module.html?srsltid=AfmBOoptww8c6kx53xbZWiP2_C_qOE3r9xinyoCO-AZHrZkNQiyxU17c)
4. RTC Module
To keep track of the current date and time, even when the Arduino is powered off.
- [DS3231 Real Time Clock Module @ R55.20](https://www.robotics.org.za/DS3231-MOD?search=DS3231)
5. Power Supply
To power the Arduino and connected peripherals.
- [AC Adapter 9V with barrel jack @ R60](https://www.robotics.org.za/AC-9V-2A-2155?search=%20Power%20Supply)
6. LED Indicators
Two LEDs for status indication (not included in original cost estimate).
### Wiring
#### RS485 Module to Arduino:
1. RO (Receiver Output) to Arduino RX (pin 8)
2. DI (Driver Input) to Arduino TX (pin 7)
3. DE (Driver Enable) & RE (Receiver Enable) to Arduino digital pin 4
4. VCC to 5V on Arduino
5. GND to GND on Arduino
6. A & B (RS485 differential pair) to Modbus device
#### SD Card Module to Arduino:
1. VCC to 5V on Arduino
2. GND to GND on Arduino
3. MOSI to MOSI (pin 51 on MEGA, pin 11 on UNO)
4. MISO to MISO (pin 50 on MEGA, pin 12 on UNO)
5. SCK to SCK (pin 52 on MEGA, pin 13 on UNO)
6. CS (Chip Select) to digital pin 10
#### RTC Module to Arduino:
1. VCC to 5V on the Arduino
2. GND to GND on the Arduino
3. SDA to SDA (pin 20 on MEGA, pin A4 on UNO)
4. SCL to SCL (pin 21 on MEGA, pin A5 on UNO)
#### LED Indicators:
1. LED A to digital pin 3
2. 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
1. Modbus Configuration:
- Slave ID: 101
- Baud Rate: 9600
- Register map: Defined in separate "register_map_pm8000.h" file
2. 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
3. Register Types Supported:
- Float (32-bit)
- Integer (32-bit)
- Long (64-bit)
- String (up to 20 characters)
4. 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)
5. 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
1. Initialize hardware (RTC, SD card, RS485 module)
2. Set up Modbus communication parameters
3. 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
## 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_vsd.h` file, you can customize this Modbus reader to suit your specific requirements while staying within the memory limitations of your Arduino board.
-199
View File
@@ -1,199 +0,0 @@
#include <Wire.h>
#include <RTClib.h>
#include <NeoSWSerial.h>
#include <ModbusMaster.h>
#include "PM8000_Modbus_Map_ad.h"
//#include <SD.h>
#include <SPI.h>
#include <SdFat.h>
#define SD_CS_PIN 10 // Chip Select for SD Card
//RS485 pins
#define DE_RE_PIN 4
#define RX_PIN 8 // SoftwareSerial RX pin
#define TX_PIN 7 // SoftwareSerial TX pin
#define SLAVE_ID 101
#define SERIAL_BAUDRATE 9600
// Try to select the best SD card configuration.
#define SPI_CLOCK SD_SCK_MHZ(50)
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
#endif // HAS_SDIO_CLASS
RTC_DS3231 rtc; // Create an RTC object
SdFat32 sd;
//SdExFat sd;
File dataFile;
NeoSWSerial modbusSerial(RX_PIN, TX_PIN); // Create a software serial instance
ModbusMaster node;
void setup()
{
Serial.begin(SERIAL_BAUDRATE); // For debugging
Serial.println(F("Startup \n"));
// Initialize RTC
if (!rtc.begin())
{
Serial.println(F("Couldn't find RTC\n"));
}
if (rtc.lostPower())
{
Serial.println(F("RTC lost power, let's set the time!\n"));
// Comment out the following line once the time is set to avoid resetting on every start
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
Serial.print(F("Time: "));
Serial.print(rtc.now().timestamp());
Serial.println(F("\n"));
// Initialize SD card
Serial.println(F("SD card initializing..."));
pinMode(SD_CS_PIN, OUTPUT);
// if (!SD.begin(SPI_HALF_SPEED, SD_CS_PIN ))
// {
// Serial.println(F("SD card initialization failed!\n"));
// return;
// }
// Initialize the SD.
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
return;
}
Serial.println(F("SD card initialized.\n"));
Serial.println(F("Initialize RS485 module / Modbus \n"));
pinMode(DE_RE_PIN, OUTPUT);
digitalWrite(DE_RE_PIN, LOW); // Set to LOW for receiving mode initially
modbusSerial.begin(SERIAL_BAUDRATE);
node.begin(SLAVE_ID, modbusSerial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void preTransmission()
{
digitalWrite(DE_RE_PIN, HIGH); // Enable RS485 transmit
}
void postTransmission()
{
digitalWrite(DE_RE_PIN, LOW); // Disable RS485 transmit
}
void writeFile(char *str)
{
if (!dataFile)
{
Serial.println(F("Error opening file"));
return;
}
DateTime now = rtc.now();
// Log the current date and time
dataFile.print(now.year(), DEC);
dataFile.print('-');
dataFile.print(now.month(), DEC);
dataFile.print('-');
dataFile.print(now.day(), DEC);
dataFile.print(" ");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(F(","));
dataFile.print(str);
dataFile.println();
}
String getFilename()
{
DateTime now = rtc.now();
String mb = F("");
mb += now.year();
mb += now.month();
mb += now.day();
mb += F(".csv");
return mb;
}
unsigned long lastRefreshTime = 0;
void loop()
{
delay(100);
if(millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.print(F("\nTime: "));
Serial.print(rtc.now().timestamp());
// Serial.print("\nHeep:");
// Serial.print(ESP.getFreeHeap());
Serial.print("\n");
// Open file for writing
String filename = getFilename();
dataFile.open(filename.c_str(), FILE_WRITE);
Serial.print(F("Open Card "));
Serial.print(filename.c_str());
Serial.print("\n");
String mb = "modbus,";
writeFile(mb.c_str());
if (dataFile)
{
dataFile.close(); // Close the file
Serial.print(F("Data written to SD card: "));
Serial.print(filename.c_str());
Serial.print(F("\n"));
}
Serial.print(F("\n\n"));
}
for (int i = 0; i < 10; i++) {
Serial.print(F("\naddress: "));
Serial.print(registers[i].regaddr);
Serial.print(F("\ntype: "));
Serial.print(registers[i].regtype);
Serial.print(F("\n "));
if (registers[i].regaddr > 0) {
uint8_t result = node.readHoldingRegisters(registers[i].regaddr , 2);
if (result == node.ku8MBSuccess)
{
Serial.print(F("Modbus Read successful:"));
} else {
Serial.print(F("Modbus Read error: "));
Serial.println(result, HEX);
}
}
}
// // Check if the read was successful
delay(100);
}
-99
View File
@@ -1,99 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define the pins for SoftwareSerial communication
#define RX_PIN 7 // RX pin for SoftwareSerial
#define TX_PIN 6 // TX pin for SoftwareSerial
#define TX_ENABLE_PIN 4 // Pin to control RS485 direction
#define DE_ENABLE_PIN 5
// Create a SoftwareSerial object
SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
// Create an instance of the ModbusMaster class
ModbusMaster node;
// Function to control RS485 transmit enable
void preTransmission()
{
digitalWrite(TX_ENABLE_PIN, HIGH); // Enable RS485 transmit
}
void postTransmission()
{
digitalWrite(TX_ENABLE_PIN, LOW); // Disable RS485 transmit
}
void setup()
{
// Initialize the built-in serial port for debugging
Serial.begin(9600);
// Initialize SoftwareSerial for Modbus communication
modbusSerial.begin(9600);
pinMode(DE_ENABLE_PIN, OUTPUT);
digitalWrite(DE_ENABLE_PIN, HIGH);
// Set the pin mode for the RS485 control pin
pinMode(TX_ENABLE_PIN, OUTPUT);
digitalWrite(TX_ENABLE_PIN, LOW);
// Modbus communication setup
node.begin(1, modbusSerial); // Slave ID = 1, use modbusSerial for RS485 communication
// Set callbacks to handle RS485 flow control
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
static uint16_t count = 0;
uint8_t result;
uint16_t data[6];
// Read 6 holding registers starting at address 0x0000
result = node.readHoldingRegisters(0x0000, 6);
// Check if the read was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Read successful: ");
for (uint8_t j = 0; j < 6; j++)
{
data[j] = node.getResponseBuffer(j);
Serial.print(data[j], HEX);
Serial.print(" ");
}
Serial.println();
}
else
{
Serial.print("Read error: ");
Serial.println(result, HEX);
}
// Write the count value to the holding register at address 0x0001
result = node.writeSingleRegister(0x0001, count);
// Check if the write was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Write successful: ");
Serial.println(count);
}
else
{
Serial.print("Write error: ");
Serial.println(result, HEX);
}
// Increment the count value
count++;
// Delay before the next read cycle
delay(1000);
}
-67
View File
@@ -1,67 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define software serial pins (use any digital pins if not using hardware serial)
#define RX_PIN 13
#define TX_PIN 12
#define DE_PIN 3
#define RE_PIN 4
SoftwareSerial s1(RX_PIN, TX_PIN);
void setup() {
// Start the software serial port
s1.begin(9600 );
//pinMode(RX_PIN, INPUT);
//pinMode(TX_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
//node.setTimeout(2000);
// Optionally, start the Serial monitor for debugging
Serial.begin(9600);
while (!s1) {
}
Serial.println("Setup done B");
}
int byteReceived;
static unsigned long lastRefreshTime = 0;
static unsigned long cnt = 0;
void loop() {
cnt++;
if (s1.available()) //Look for data from other Arduino
{
int inByte = s1.read();
Serial.write(inByte);
}
//delay(100); // Wait a second before the next loop
if(millis() - lastRefreshTime >= 1000)
{
digitalWrite(RE_PIN, HIGH);
digitalWrite(DE_PIN, HIGH);
s1.print("Its working.....");
s1.println(cnt);
s1.flush();
//delay(1000);
digitalWrite(RE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
lastRefreshTime += 1000;
Serial.println("Cycle2\n\n");
}
}
-70
View File
@@ -1,70 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define software serial pins (use any digital pins if not using hardware serial)
#define RX_PIN 13
#define TX_PIN 12
#define DE_PIN 3
#define RE_PIN 4
SoftwareSerial s1(RX_PIN, TX_PIN);
void setup() {
// Start the software serial port
s1.begin(9600 );
//pinMode(RX_PIN, INPUT);
//pinMode(TX_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
//node.setTimeout(2000);
// Optionally, start the Serial monitor for debugging
Serial.begin(9600);
while (!s1) {
}
Serial.println("Setup done A");
}
void loop() {
static unsigned long lastRefreshTime = 0;
s1.listen();
while (s1.available() > 0) {
int inByte = s1.read();
Serial.write(inByte);
}
//delay(10); // Wait a second before the next loop
// digitalWrite(RE_PIN, HIGH);
// s1.print("Hello");
// digitalWrite(RE_PIN, LOW);
if(millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.println("Cycle\n\n");
digitalWrite(RE_PIN, HIGH);
digitalWrite(DE_PIN, HIGH);
s1.print("Ping..");
s1.flush();
//delay(1000);
digitalWrite(RE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
}
}
View File
Whitespace-only changes.
@@ -1,108 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define software serial pins (use any digital pins if not using hardware serial)
#define RX_PIN 13
#define TX_PIN 12
#define DE_PIN 3
#define RE_PIN 4
SoftwareSerial s1(RX_PIN, TX_PIN);
ModbusMaster node;
uint16_t holdingRegisters[20];
void setup() {
// Start the software serial port
s1.begin(9600 );
//pinMode(RX_PIN, INPUT);
//pinMode(TX_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
//node.setTimeout(2000);
// Optionally, start the Serial monitor for debugging
Serial.begin(9600);
while (!s1) {
}
node.begin(101, s1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void preTransmission()
{
digitalWrite(DE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(RE_PIN, HIGH);
}
void postTransmission()
{
digitalWrite(DE_PIN, LOW); // Disable RS485 transmit
digitalWrite(RE_PIN, LOW);
}
static unsigned long lastRefreshTime = 0;
#define ReadSize 4
void loop() {
static uint16_t count = 0;
uint8_t result;
int16_t data[ReadSize];
//delay(100); // Wait a second before the next loop
// digitalWrite(RE_PIN, HIGH);
// s1.print("Hello");
// digitalWrite(RE_PIN, LOW);
if(millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.print("Cycle\n\n");
result = node.readHoldingRegisters(1836 , 8);
// Check if the read was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Meter Date Time Read successful: ");
Serial.print("Y : ");
Serial.println(node.getResponseBuffer(0));
Serial.print("M : ");
Serial.println(node.getResponseBuffer(1));
Serial.print("D : ");
Serial.println(node.getResponseBuffer(2));
Serial.print("H : ");
Serial.println(node.getResponseBuffer(3));
Serial.print("M : ");
Serial.println(node.getResponseBuffer(4));
// for (uint8_t j = 0; j < ReadSize; j++)
// {
// int recv = node.getResponseBuffer(j);
// data[j] = recv;
// Serial.print(recv );
// }
// Serial.print("\nHEX:");
// for (uint8_t j = 0; j < ReadSize; j++)
// {
// Serial.print(data[j],"HEX");
// }
// Serial.println();
} else {
Serial.print("Read error: ");
Serial.println(result, HEX);
}
}
}
@@ -1,109 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define software serial pins (use any digital pins if not using hardware serial)
#define RX_PIN 13
#define TX_PIN 12
#define DE_PIN 3
#define RE_PIN 4
SoftwareSerial s1(RX_PIN, TX_PIN);
ModbusMaster node;
uint16_t holdingRegisters[20];
void setup() {
// Start the software serial port
s1.begin(9600 );
//pinMode(RX_PIN, INPUT);
//pinMode(TX_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
//node.setTimeout(2000);
// Optionally, start the Serial monitor for debugging
Serial.begin(9600);
while (!s1) {
}
node.begin(101, s1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void preTransmission()
{
digitalWrite(DE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(RE_PIN, HIGH);
}
void postTransmission()
{
digitalWrite(DE_PIN, LOW); // Disable RS485 transmit
digitalWrite(RE_PIN, LOW);
}
static unsigned long lastRefreshTime = 0;
#define ReadSize 4
void loop() {
static uint16_t count = 0;
uint8_t result;
int16_t data[ReadSize];
//delay(100); // Wait a second before the next loop
// digitalWrite(RE_PIN, HIGH);
// s1.print("Hello");
// digitalWrite(RE_PIN, LOW);
if(millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.print("Cycle\n\n");
result = node.readHoldingRegisters(2705 , 2);
// Check if the read was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Read successful: ");
uint16_t highWord = node.getResponseBuffer(0);
uint16_t lowWord = node.getResponseBuffer(1);
uint32_t floatRaw = ((uint32_t)highWord << 16) | lowWord; // Combine registers
float floatValue;
// Convert raw 32-bit value to float
memcpy(&floatValue, &floatRaw, sizeof(float));
Serial.print("Float value: ");
Serial.println(floatValue);
// for (uint8_t j = 0; j < ReadSize; j++)
// {
// int recv = node.getResponseBuffer(j);
// data[j] = recv;
// Serial.print(recv );
// }
// Serial.print("\nHEX:");
// for (uint8_t j = 0; j < ReadSize; j++)
// {
// Serial.print(data[j],"HEX");
// }
// Serial.println();
} else {
Serial.print("Read error: ");
Serial.println(result, HEX);
}
}
}
@@ -1,99 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define software serial pins (use any digital pins if not using hardware serial)
#define RX_PIN 13
#define TX_PIN 12
#define DE_PIN 3
#define RE_PIN 4
SoftwareSerial s1(RX_PIN, TX_PIN);
ModbusMaster node;
uint16_t holdingRegisters[20];
void setup() {
// Start the software serial port
s1.begin(9600 );
//pinMode(RX_PIN, INPUT);
//pinMode(TX_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
digitalWrite(RE_PIN, LOW);
//node.setTimeout(2000);
// Optionally, start the Serial monitor for debugging
Serial.begin(9600);
while (!s1) {
}
node.begin(101, s1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void preTransmission()
{
digitalWrite(DE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(RE_PIN, HIGH);
}
void postTransmission()
{
digitalWrite(DE_PIN, LOW); // Disable RS485 transmit
digitalWrite(RE_PIN, LOW);
}
static unsigned long lastRefreshTime = 0;
#define ReadSize 4
void loop() {
static uint16_t count = 0;
uint8_t result;
int16_t data[ReadSize];
//delay(100); // Wait a second before the next loop
// digitalWrite(RE_PIN, HIGH);
// s1.print("Hello");
// digitalWrite(RE_PIN, LOW);
if(millis() - lastRefreshTime >= 1000)
{
lastRefreshTime += 1000;
Serial.print("Cycle\n\n");
result = node.readHoldingRegisters(29 , 70);
// Check if the read was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Read successful: ");
for (uint8_t j = 0; j < 70; j++)
{
uint8_t v = node.getResponseBuffer(j);
char a = v;
if (v == 0) {
continue;
}
Serial.print(a);
}
} else {
Serial.print("Read error: ");
Serial.println(result, HEX);
}
}
}
-81
View File
@@ -1,81 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define the pins for SoftwareSerial communication
#define RX_PIN 13 // RX pin for SoftwareSerial
#define TX_PIN 12 // TX pin for SoftwareSerial
#define TX_ENABLE_PIN 4 // Pin to control RS485 direction
#define DE_ENABLE_PIN 5
// Create a SoftwareSerial object
SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
// Create an instance of the ModbusMaster class
ModbusMaster node;
// Function to control RS485 transmit enable
void preTransmission()
{
digitalWrite(TX_ENABLE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(DE_ENABLE_PIN, HIGH);
}
void postTransmission()
{
digitalWrite(TX_ENABLE_PIN, LOW); // Disable RS485 transmit
digitalWrite(DE_ENABLE_PIN, LOW);
}
void setup()
{
// Initialize the built-in serial port for debugging
Serial.begin(9600);
// Initialize SoftwareSerial for Modbus communication
modbusSerial.begin(9600);
pinMode(DE_ENABLE_PIN, OUTPUT);
digitalWrite(DE_ENABLE_PIN, HIGH);
// Set the pin mode for the RS485 control pin
pinMode(TX_ENABLE_PIN, OUTPUT);
digitalWrite(TX_ENABLE_PIN, LOW);
// Modbus communication setup
node.begin(1, modbusSerial); // Slave ID = 1, use modbusSerial for RS485 communication
// Set callbacks to handle RS485 flow control
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
static uint16_t count = 0;
uint8_t result;
uint16_t data[6];
Serial.print("Loop:");
Serial.println(count);
// Write the count value to the holding register at address 0x0001
result = node.writeSingleRegister(0x0001, count);
// Check if the write was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Write successful: ");
Serial.println(count);
}
else
{
Serial.print("Write error: ");
Serial.println(result, HEX);
}
// Increment the count value
count++;
// Delay before the next read cycle
delay(1000);
}
-81
View File
@@ -1,81 +0,0 @@
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
// Define the pins for SoftwareSerial communication
#define RX_PIN 3 // RX pin for SoftwareSerial
#define TX_PIN 4 // TX pin for SoftwareSerial
#define TX_ENABLE_PIN 2 // Pin to control RS485 direction
#define DE_ENABLE_PIN 5
// Create a SoftwareSerial object
SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
// Create an instance of the ModbusMaster class
ModbusMaster node;
// Function to control RS485 transmit enable
void preTransmission()
{
digitalWrite(TX_ENABLE_PIN, HIGH); // Enable RS485 transmit
digitalWrite(DE_ENABLE_PIN, HIGH);
}
void postTransmission()
{
digitalWrite(TX_ENABLE_PIN, LOW); // Disable RS485 transmit
digitalWrite(DE_ENABLE_PIN, LOW);
}
void setup()
{
// Initialize the built-in serial port for debugging
Serial.begin(9600);
// Initialize SoftwareSerial for Modbus communication
modbusSerial.begin(9600);
pinMode(DE_ENABLE_PIN, OUTPUT);
digitalWrite(DE_ENABLE_PIN, HIGH);
// Set the pin mode for the RS485 control pin
pinMode(TX_ENABLE_PIN, OUTPUT);
digitalWrite(TX_ENABLE_PIN, LOW);
// Modbus communication setup
node.begin(1, modbusSerial); // Slave ID = 1, use modbusSerial for RS485 communication
// Set callbacks to handle RS485 flow control
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
static uint16_t count = 0;
uint8_t result;
uint16_t data[6];
Serial.print("Loop:");
Serial.println(count);
// Write the count value to the holding register at address 0x0001
result = node.writeSingleRegister(0x0001, count);
// Check if the write was successful
if (result == node.ku8MBSuccess)
{
Serial.print("Write successful: ");
Serial.println(count);
}
else
{
Serial.print("Write error: ");
Serial.println(result, HEX);
}
// Increment the count value
count++;
// Delay before the next read cycle
delay(1000);
}
-57
View File
@@ -1,57 +0,0 @@
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 13 //Serial Receive pin
#define SSerialTX 12 //Serial Transmit pin
#define SSerialTxControl 4 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 9
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("Remote connector"); // Can be ignored
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(9600); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Copy input data to output
if (RS485Serial.available())
{
byteSend = RS485Serial.read(); // Read the byte
digitalWrite(Pin13LED, HIGH); // Show activity
delay(1);
digitalWrite(Pin13LED, LOW);
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteSend); // Send the byte back
//delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
Serial.println("Bounce");
Serial.println(byteSend);
// delay(100);
}// End If RS485SerialAvailable
}//--(end main loop )---
-72
View File
@@ -1,72 +0,0 @@
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 13 //Serial Receive pin
#define SSerialTX 12 //Serial Transmit pin
#define SSerialTxControl 4 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 9
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("Master connector");
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(9600); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available())
{
byteReceived = Serial.read();
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteReceived); // Send byte to Remote Arduino
digitalWrite(Pin13LED, LOW); // Show activity
//Serial.println("\nRead Local");
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
}
if (RS485Serial.available()) //Look for data from other Arduino
{
digitalWrite(Pin13LED, HIGH); // Show activity
byteReceived = RS485Serial.read(); // Read received byte
Serial.println("Received ");
Serial.write(byteReceived); // Show on Serial Monitor
delay(10);
digitalWrite(Pin13LED, LOW); // Show activity
}
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//NONE
//*********( THE END )***********
File renamed without changes.
File renamed without changes.
Internal Server Error - Warky Devs
500 Internal Server Error

An error occurred:

An error occurred

Gitea Version: 28.1.0