Skip to content

Commit

Permalink
Rewritten to support multiple buses at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
morcibacsi committed Dec 17, 2022
1 parent 20bb350 commit ace06d8
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 1,141 deletions.
53 changes: 34 additions & 19 deletions examples/esp32_arduino_van_monitor/esp32_arduino_van_monitor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* CONDITIONS OF ANY KIND, either express or implied.
*/
#include <esp32_arduino_rmt_van_rx.h>
#include <esp32_rmt_van_rx.h>

ESP32_RMT_VAN_RX VAN_RX;
TaskHandle_t VANReadDataTask;

ESP32_RMT_VAN_RX *VAN_RX;

const uint8_t VAN_DATA_RX_RMT_CHANNEL = 0;
const uint8_t VAN_DATA_RX_PIN = 21;
Expand All @@ -21,25 +22,22 @@ uint8_t vanMessage[34];

uint32_t lastMillis = 0;

void setup()
void VANReadDataTaskFunction(void * parameter)
{
Serial.begin(500000);
printf("ESP32 Arduino VAN bus monitor\n");

VAN_RX.Init(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_COMFORT);
//VAN_RX.Init(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_BODY);
}
VAN_RX = new ESP32_RMT_VAN_RX(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_COMFORT);
//VAN_RX = new ESP32_RMT_VAN_RX(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_BODY);
VAN_RX->Start();

void loop()
{
if (millis() - lastMillis > 5)
for (;;)
{
lastMillis = millis();
VAN_RX.Receive(&vanMessageLength, vanMessage);
VAN_RX->ReceiveData(&vanMessageLength, vanMessage);

if (vanMessageLength > 0)
{
if(VAN_RX.IsCrcOk(vanMessage, vanMessageLength))
if(!VAN_RX->IsCrcOk(vanMessage, vanMessageLength))
{
printf("CRC ERROR: ");
}
{
for (size_t i = 0; i < vanMessageLength; i++)
{
Expand All @@ -54,10 +52,27 @@ void loop()
}
printf("\n");
}
else
{
printf("CRC ERROR!\n");
}
}
vTaskDelay(5 / portTICK_PERIOD_MS);
}
}

void setup()
{
Serial.begin(500000);
printf("ESP32 Arduino VAN bus monitor\n");

xTaskCreatePinnedToCore(
VANReadDataTaskFunction, // Function to implement the task
"VANReadDataTask", // Name of the task
20000, // Stack size in words
NULL, // Task input parameter
1, // Priority of the task (higher the number, higher the priority)
&VANReadDataTask, // Task handle.
0); // Core where the task should run
}

void loop()
{
vTaskDelay(50 / portTICK_PERIOD_MS);
}
5 changes: 3 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ ESP32_RMT_VAN_RX KEYWORD1
# Methods and Functions (KEYWORD2)
#######################################

Init KEYWORD2
Receive KEYWORD2
Start KEYWORD2
ReceiveData KEYWORD2
Stop KEYWORD2
IsCrcOk KEYWORD2
Crc15 KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP32 RMT Peripheral VAN bus reader library
version=1.0.1
version=2.0.0
author=Peter Pinter <pinterpeti@gmail.com>
maintainer=Peter Pinter <pinterpeti@gmail.com>
sentence=ESP32 RMT Peripheral VAN bus reader library
Expand Down
4 changes: 0 additions & 4 deletions main/component.mk

This file was deleted.

65 changes: 0 additions & 65 deletions main/main.c

This file was deleted.

11 changes: 0 additions & 11 deletions makefile

This file was deleted.

32 changes: 24 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@

# ESP32 RMT peripheral Vehicle Area Network (VAN bus) reader

Arduino friendly [VAN bus][van_network] reader library utilizing ESP32 RMT peripheral.
Arduino [VAN bus][van_network] reader library utilizing ESP32 RMT peripheral.

VAN bus is pretty similar to CAN bus. It was used in many cars (Peugeot, Citroen) made by PSA.

### ESP8266 support
This library is built around the [RMT (Remote control) peripheral][rmt_peripheral] of the ESP32. Therefore **ESP8266 is NOT supported** by this library as it does not have the peripheral built in. However on these boards you can use this nice library: [PSA VAN bus reader for Arduino-ESP8266][van_reader_for_esp8266]
This library is built around the [RMT (Remote control) peripheral][rmt_peripheral] of the ESP32. Therefore **ESP8266 is NOT supported** by this library as it does not have the peripheral built in. However on these boards you can use this library: [PSA VAN bus reader for Arduino-ESP8266][van_reader_for_esp8266]

### Schematics

![schema](https://github.com/morcibacsi/esp32_rmt_van_rx/raw/master/extras/schema/esp32-sn65hvd230-iso-a.png)

### Arduino
Copy the following files to your **documents\Arduino\libraries\esp32_arduino_rmt_van_rx** folder
- esp32_rmt_van_rx.c
- esp32_arduino_rmt_van_rx.cpp
- esp32_arduino_rmt_van_rx.h
- esp32_rmt_van_rx.h
- Esp32RmtReader.cpp
- Esp32RmtReader.h
- keywords.txt
- library.properties

Check the **esp32_arduino_van_monitor** folder for an example

### ESP-IDF
### Breaking change

Check the **main** folder for an example
In version 2.0.0 the library was rewritten and ESP-IDF support was dropped in favor of simpler code in Arduino framework. The change also makes it possible to monitor the VAN_COMFORT and VAN_BODY bus simultaneously by creating two separate instances of the ```ESP32_RMT_VAN_RX``` class. The example was updated to reflect the change, so you can check that as well.

#### Example code
```cpp
// Instead of calling the Init function with the following parameters:
VAN_RX.Init(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_COMFORT);
//Receive() method was renamed to ReceiveData()
VAN_RX.Receive(&vanMessageLength, vanMessage)

// You need to pass the same parameters to the constructor like this:
VAN_RX = new ESP32_RMT_VAN_RX(VAN_DATA_RX_RMT_CHANNEL, VAN_DATA_RX_PIN, VAN_DATA_RX_LED_INDICATOR_PIN, VAN_LINE_LEVEL_HIGH, VAN_NETWORK_TYPE_COMFORT);
// And call the Start() method:
VAN_RX->Start();
// Receive data from the bus
VAN_RX->ReceiveData(&vanMessageLength, vanMessage);
```
## See also
Check my [VAN Analyzer for Saleae Logic Analyzer][van_analyzer] also
[VAN Analyzer for Saleae Logic Analyzer][van_analyzer]
[TSS463/461 library for reading and also safely writing the VAN bus][tss_46x library]
[VAN bus reader for STM32F103 (Blue Pill)][stm32_van_bus]
[van_network]: https://en.wikipedia.org/wiki/Vehicle_Area_Network
[van_analyzer]: https://github.com/morcibacsi/VanAnalyzer/
[rmt_peripheral]: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/rmt.html
[van_reader_for_esp8266]: https://github.com/0xCAFEDECAF/VanBus
[tss_46x library]: https://github.com/morcibacsi/arduino_tss463_van
[stm32_van_bus]: https://github.com/morcibacsi/stm32_arduino_van_bus
Loading

0 comments on commit ace06d8

Please sign in to comment.