Pic to esp32

Thread Starter

geoffers

Joined Oct 25, 2010
491
Hi all,

Not been on here for a while! I've a question/would like some opinions on learning to use esp32.

I've been programming (not professionally) 8bit pic for quite a while now (25years on and off I reckon) and recently been fairly successful (hence lack of visits here)

I code in mpasm relocatable and last few years non blocking code, gave me headaches to start with!

I've a project coming up where I want to read a flowmeter via rs485 (modbus I think but haven't got the meter yet, AliExpress special)
I also want to read the forward speed of a tractor via can bus.
This is to give a drive faster/slower indication for spreading slurry with a pumped umbilical system.

Rs 485 and modbus I have already used on a pic, can bus I haven't.

The esp32 has can and rs485 on it and the options for some nice displays.

How much of a learning curve is involved for a dinosaur like me to go from my current experience to programming esp32 in c (I assume via Arduino ide would be best?)

Can anyone recommend any good books on c for such applications.

As I write this I'm more inclined towards digging out a pic16 and using a simple LCD display and keypad.

Advice appreciated.
Cheers Geoff
 

nsaspook

Joined Aug 27, 2009
16,268

panic mode

Joined Oct 10, 2011
4,919
do you really need CAN bus? just saying there are other ways to get speed.


for example using GPS one can get speed, location and much more... plus it is completely vehicle agnostic so can be tested by walking, riding bike, driving car...

Code:
#include <TinyGPS++.h>
#include <HardwareSerial.h>

TinyGPSPlus gps;
HardwareSerial ss(2); // Use UART2

void setup() {
  Serial.begin(115200);
  ss.begin(9600, SERIAL_8N1, 16, 17); // TX, RX
}

void loop() {
  while (ss.available() > 0) {
    if (gps.encode(ss.read())) {
      if (gps.speed.isValid()) {
        Serial.print("Speed: ");
        Serial.print(gps.speed.kmph());
        Serial.println(" km/h");
      }
    }
  }
}
CAN bus example:
Code:
#include "driver/twai.h"

// Define CAN Pins
#define CAN_RX GPIO_NUM_4
#define CAN_TX GPIO_NUM_5

void setup() {
  Serial.begin(115200);

  // Initialize configuration structures
  twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(CAN_RX, CAN_TX, TWAI_MODE_LISTEN_ONLY);
  twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS(); // Tractor standard
  twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();

  // Install and start CAN driver
  if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
    Serial.println("Driver installed");
  } else {
    Serial.println("Failed to install");
    return;
  }
 
  if (twai_start() == ESP_OK) {
    Serial.println("Driver started");
  } else {
    Serial.println("Failed to start");
  }
}

void loop() {
  twai_message_t message;
  if (twai_receive(&message, pdMS_TO_TICKS(1000)) == ESP_OK) {
    // Check if the message is PGN 65265 (Hex: FF11)
    if (message.identifier == 0x18FEEE00) { // Example for Cruise Control/Vehicle Speed
      // Data byte 1 & 2 contain speed (varies by specific tractor model)
      float speed = ((message.data[1] << 8) | message.data[0]) * 0.00390625; // Example scaling
      Serial.print("Speed (km/h): ");
      Serial.println(speed);
    }
  }
}
 

panic mode

Joined Oct 10, 2011
4,919
for learning, just talk to google AI for example:
"how to display tractor forward speed using esp32 and arm of a servo"
"how to read tractor speed using esp32 and can bus"
"what esp32, display etc i need to do ...xyz?"

get the parts connect them and if you don't have it working in a day or so something is very wrong.
 
Top