Compare commits

...
4 Commits
Author SHA1 Message Date
smayzy 43ca350f21 add current and simplify calculations 2026-05-01 23:21:18 +02:00
smayzy efeefc27b9 small fixes 2026-03-23 13:17:22 +01:00
smayzy b1a742d777 add lora 2026-03-18 12:13:18 +01:00
smayzy 22b36fbc01 add timing for amp 2026-03-12 17:35:40 +01:00
+50 -3
View File
@@ -2,7 +2,9 @@
#include <mcp_can.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
SoftwareSerial lora(8, 9); // RX, TX
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define CAN_CS 10
@@ -10,16 +12,29 @@ MCP_CAN CAN(CAN_CS);
const byte NODE_ID = 0x01; // Change to your Sevcon node ID
const unsigned long timing = 500;
const unsigned long timing_c = 10;
unsigned long previous_time = 0;
unsigned long current_time = 0;
unsigned long previous_time_c = 0;
int16_t rpm = 0;
int16_t ubat = 0;
int v = 0;
int u_shunt = 0;
int ubatr = 0;
int current = 0;
int c_max = 0;
char buffer[50];
int n = 0;
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
lora.begin(9600);
lcd.init();
lcd.backlight();
@@ -50,14 +65,14 @@ void loop() {
if (len >= 2) {
rpm = buf[0] | (buf[1] << 8);
v = rpm * 0.017;
};
}
break;
}
case 0x209 : {
if (len >= 2) {
ubat = buf[0] | (buf[1] << 8);
ubatr = ubat / 16;
};
}
break;
}
}
@@ -77,8 +92,40 @@ void loop() {
lcd.setCursor(0, 1);
lcd.print("ubat = ");
lcd.print(ubatr);
lcd.print("/");
lcd.print(u_shunt);
lcd.print(" V ");
Serial.print("Tension = ");
Serial.println(ubatr);
Serial.print(ubatr);
Serial.print("/");
Serial.println(u_shunt);
lcd.setCursor(0, 2);
lcd.print("current = ");
lcd.print(current);
lcd.print(" A ");
Serial.print("Current = ");
Serial.println(current);
lcd.setCursor(0, 3);
lcd.print("current_max = ");
lcd.print(c_max);
lcd.print(" A ");
Serial.print("current max = ");
Serial.println(c_max);
snprintf(buffer, sizeof(buffer), "%d,%d,%d,%d", n, v, ubatr, current);
n = n + 1;
lora.println(buffer);
}
if (current_time - previous_time_c >= timing_c) {
previous_time_c = current_time;
current = ((analogRead(A0) * 5 * 27.322) / 1023);
if (current > c_max) {
c_max = current;
};
u_shunt = ((analogRead(A1) * 5 * 15.701) / 1023);
}
}