Compare commits
6
Commits
eb9a43984f
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43ca350f21 | ||
|
|
efeefc27b9 | ||
|
|
b1a742d777 | ||
|
|
22b36fbc01 | ||
|
|
e8e5e2728d | ||
|
|
5fd8fa2b61 |
+55
-17
@@ -2,7 +2,9 @@
|
|||||||
#include <mcp_can.h>
|
#include <mcp_can.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
SoftwareSerial lora(8, 9); // RX, TX
|
||||||
LiquidCrystal_I2C lcd(0x27, 20, 4);
|
LiquidCrystal_I2C lcd(0x27, 20, 4);
|
||||||
|
|
||||||
#define CAN_CS 10
|
#define CAN_CS 10
|
||||||
@@ -10,29 +12,32 @@ MCP_CAN CAN(CAN_CS);
|
|||||||
|
|
||||||
const byte NODE_ID = 0x01; // Change to your Sevcon node ID
|
const byte NODE_ID = 0x01; // Change to your Sevcon node ID
|
||||||
const unsigned long timing = 500;
|
const unsigned long timing = 500;
|
||||||
|
const unsigned long timing_c = 10;
|
||||||
|
|
||||||
unsigned long previous_time = 0;
|
unsigned long previous_time = 0;
|
||||||
unsigned long current_time = 0;
|
unsigned long current_time = 0;
|
||||||
|
unsigned long previous_time_c = 0;
|
||||||
|
|
||||||
int16_t rpm = 0;
|
int16_t rpm = 0;
|
||||||
int16_t ubat = 0;
|
int16_t ubat = 0;
|
||||||
int v = 0;
|
int v = 0;
|
||||||
|
int u_shunt = 0;
|
||||||
int ubatr = 0;
|
int ubatr = 0;
|
||||||
|
int current = 0;
|
||||||
|
int c_max = 0;
|
||||||
|
char buffer[50];
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
pinMode(5, OUTPUT);
|
||||||
|
pinMode(6, OUTPUT);
|
||||||
|
digitalWrite(5, LOW);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
lora.begin(9600);
|
||||||
|
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print("vitesse = ");
|
|
||||||
lcd.print(" ");
|
|
||||||
lcd.print(" km/h ");
|
|
||||||
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
lcd.print("ubat = ");
|
|
||||||
lcd.print(" ");
|
|
||||||
lcd.print(" V ");
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
while (CAN_OK != CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)) {
|
while (CAN_OK != CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)) {
|
||||||
@@ -60,34 +65,67 @@ void loop() {
|
|||||||
if (len >= 2) {
|
if (len >= 2) {
|
||||||
rpm = buf[0] | (buf[1] << 8);
|
rpm = buf[0] | (buf[1] << 8);
|
||||||
v = rpm * 0.017;
|
v = rpm * 0.017;
|
||||||
Serial.print("Vitesse = ");
|
}
|
||||||
Serial.println(v);
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x209 : {
|
case 0x209 : {
|
||||||
if (len >= 2) {
|
if (len >= 2) {
|
||||||
ubat = buf[0] | (buf[1] << 8);
|
ubat = buf[0] | (buf[1] << 8);
|
||||||
ubatr = ubat / 16;
|
ubatr = ubat / 16;
|
||||||
Serial.print("Tension = ");
|
}
|
||||||
Serial.println(ubatr);
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_time = millis();
|
current_time = millis();
|
||||||
if( current_time - previous_time >= timing){
|
if (current_time - previous_time >= timing) {
|
||||||
previous_time = current_time;
|
previous_time = current_time;
|
||||||
|
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print("Vitesse = ");
|
lcd.print("Vitesse = ");
|
||||||
lcd.print(v);
|
lcd.print(v);
|
||||||
lcd.print(" km/h ");
|
lcd.print(" km/h ");
|
||||||
|
Serial.print("Vitesse = ");
|
||||||
|
Serial.println(v);
|
||||||
|
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
lcd.print("ubat = ");
|
lcd.print("ubat = ");
|
||||||
lcd.print(ubatr);
|
lcd.print(ubatr);
|
||||||
|
lcd.print("/");
|
||||||
|
lcd.print(u_shunt);
|
||||||
lcd.print(" V ");
|
lcd.print(" V ");
|
||||||
|
Serial.print("Tension = ");
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user