|
3 | 3 | - Read the BMS cell voltages, pack voltage, and error codes.
|
4 | 4 | */
|
5 | 5 |
|
6 |
| - |
7 |
| -#define BMS_RX_PIN 2 //pin the bms is reciving signals on, where we are sending. |
8 |
| -#define BMS_TX_PIN 3 //pin the BMS is sending signals to, where we are recieving. |
| 6 | +#define BMS_RX_PIN 2 //pin the bms is receiving signals on, where we are sending. |
| 7 | +#define BMS_TX_PIN 3 //pin the BMS is sending signals to, where we are receiving. |
9 | 8 | #define NUM_CELLS 21
|
10 | 9 | #define NUM_TEMP_PROBES 4
|
| 10 | +#define BMS_DEBUG false |
| 11 | +// Debug mode prints the hex of every byte coming in and leaving. |
| 12 | +// You can compare the bytes you receive to what you should be receiving on the google sheet linked at the bottom of the readme. |
11 | 13 |
|
12 | 14 | #include <SoftwareSerial.h>
|
13 | 15 | #include <BMS.h>
|
14 | 16 | SoftwareSerial BMSSerial(BMS_TX_PIN, BMS_RX_PIN);
|
15 | 17 | BMS bms;
|
16 | 18 |
|
17 |
| -void setup() { |
| 19 | +void setup() |
| 20 | +{ |
18 | 21 | Serial.begin(115200);
|
19 |
| - |
| 22 | + |
20 | 23 | BMSSerial.begin(9600);
|
21 | 24 | bms.begin(&BMSSerial);
|
22 |
| - |
| 25 | + |
23 | 26 | Serial.println("Finished setup");
|
24 | 27 | }
|
25 | 28 |
|
26 |
| -void loop() { |
27 |
| - |
28 |
| - bms.update(); |
| 29 | +void loop() |
| 30 | +{ |
29 | 31 |
|
| 32 | + bms.update(); |
30 | 33 | Serial.println("Voltages: (V)");
|
31 |
| - for (byte i = 0; i < NUM_CELLS; i++) { |
| 34 | + for (byte i = 0; i < NUM_CELLS; i++) |
| 35 | + { |
32 | 36 | Serial.print(i + 1);
|
33 | 37 | Serial.print(F(" "));
|
34 |
| - if (i < 9) Serial.print(F(" ")); |
| 38 | + if (i < 9) |
| 39 | + Serial.print(F(" ")); |
35 | 40 | }
|
36 | 41 | Serial.println();
|
37 |
| - float* cells = bms.getCells(); |
38 |
| - for (byte i = 0; i < NUM_CELLS; i++) { |
| 42 | + float *cells = bms.getCells(); |
| 43 | + for (byte i = 0; i < NUM_CELLS; i++) |
| 44 | + { |
39 | 45 | Serial.print(cells[i], 2);
|
40 | 46 | Serial.print(F(" "));
|
41 | 47 | }
|
42 |
| - Serial.print("\nPack voltage: "); Serial.println(bms.getPackVoltage()); |
43 |
| - Serial.print("Min cell voltage: "); Serial.println(bms.getCellMinVoltage()); |
44 |
| - Serial.print("Max cell voltage: "); Serial.println(bms.getCellMaxVoltage()); |
45 |
| - Serial.print("Cell Diff: "); Serial.println(bms.getCellDiff()); |
| 48 | + Serial.println(); |
| 49 | + uint32_t balstate = bms.getBalanceState(); |
| 50 | + for (byte i = 0; i < NUM_CELLS; i++) |
| 51 | + { |
| 52 | + Serial.print(bitRead(balstate, i)); |
| 53 | + Serial.print(F(" ")); |
| 54 | + } |
46 | 55 |
|
47 |
| - Serial.print("Balance State: "); Serial.println(bms.getBalanceState(), BIN); |
48 |
| - Serial.println("Charge: "); Serial.println(bms.getMOSFETStatus().charge ? "Permitted" : "Prohibited"); |
49 |
| - Serial.println("Discharge: "); Serial.println(bms.getMOSFETStatus().discharge ? "Permitted" : "Prohibited"); |
| 56 | + Serial.print("\nPack voltage: "); |
| 57 | + Serial.println(bms.getPackVoltage()); |
| 58 | + Serial.println("\nMax Min Average"); |
| 59 | + Serial.print(bms.getCellMaxVoltage()); |
| 60 | + Serial.print(" "); |
| 61 | + Serial.print(bms.getCellMinVoltage()); |
| 62 | + Serial.print(" "); |
| 63 | + Serial.println(bms.getPackVoltage() / NUM_CELLS); |
| 64 | + Serial.print("Cell Diff: "); |
| 65 | + Serial.println(bms.getCellDiff()); |
| 66 | + |
| 67 | + Serial.print("Charge: "); |
| 68 | + Serial.println(bms.getMOSFETStatus().charge ? "Permitted" : "Prohibited"); |
| 69 | + Serial.print("Discharge: "); |
| 70 | + Serial.println(bms.getMOSFETStatus().discharge ? "Permitted" : "Prohibited"); |
50 | 71 |
|
51 | 72 | Serial.println("Temps: (C)");
|
52 |
| - for (byte i = 0; i < NUM_TEMP_PROBES; i++) { |
| 73 | + for (byte i = 0; i < NUM_TEMP_PROBES; i++) |
| 74 | + { |
53 | 75 | Serial.print(i + 1);
|
54 | 76 | Serial.print(F(" "));
|
55 | 77 | }
|
56 | 78 | Serial.println();
|
57 |
| - float* probes = bms.getProbeData(); |
58 |
| - for (byte i = 0; i < NUM_TEMP_PROBES; i++) { |
| 79 | + float *probes = bms.getProbeData(); |
| 80 | + for (byte i = 0; i < NUM_TEMP_PROBES; i++) |
| 81 | + { |
59 | 82 | Serial.print(probes[i], 2);
|
60 | 83 | Serial.print(F(" "));
|
61 | 84 | }
|
| 85 | + |
| 86 | + delay(2000); |
62 | 87 | }
|
0 commit comments