Skip to content

Commit

Permalink
Added ability to use SoftwareSerial library for communication with VESC
Browse files Browse the repository at this point in the history
  • Loading branch information
pibaj committed Mar 6, 2019
1 parent ff8f6f9 commit cc5eb7b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Name: getVescValuesSoftwareSerial.ino
Created: 06-03-2019
Author: SkewPL
Description: This example shows ability to use SoftwareSerial port to communicate with VESC. Confirmed to be working on ESP8266.
Remember to change the baud rate to a correct value, you can find which baud rate does your VESC use in VESCTool -> UART section.
*/

#include <VescUart.h>
#include <SoftwareSerial.h>

/** Initiate VescUart class */
VescUart vesc;

/** Initiate SoftwareSerial class */
SoftwareSerial vescSerial(13, 15);

void setup() {

/** Setup Serial port to display data */
Serial.begin(9600);

/** Setup SoftwareSerial port */
vescSerial.begin(19200);

/** Define which ports to use as UART */
vesc.setSerialPort(&vescSerial);
}

void loop() {

/** Call the function getVescValues() to acquire data from VESC */
if ( vesc.getVescValues() ) {

Serial.println(vesc.data.rpm);
Serial.println(vesc.data.inpVoltage);
Serial.println(vesc.data.ampHours);
Serial.println(vesc.data.tachometerAbs);

}
else
{
Serial.println("Failed to get data!");
}

delay(50);
}
3 changes: 1 addition & 2 deletions src/VescUart.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "VescUart.h"
#include <HardwareSerial.h>

VescUart::VescUart(void){
nunchuck.valueX = 127;
Expand All @@ -8,7 +7,7 @@ VescUart::VescUart(void){
nunchuck.upperButton = false;
}

void VescUart::setSerialPort(HardwareSerial* port)
void VescUart::setSerialPort(Stream* port)
{
serialPort = port;
}
Expand Down
4 changes: 2 additions & 2 deletions src/VescUart.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VescUart
* @brief Set the serial port for uart communication
* @param port - Reference to Serial port (pointer)
*/
void setSerialPort(HardwareSerial* port);
void setSerialPort(Stream* port);

/**
* @brief Set the serial port for debugging
Expand Down Expand Up @@ -101,7 +101,7 @@ class VescUart
private:

/** Variabel to hold the reference to the Serial object to use for UART */
HardwareSerial* serialPort = NULL;
Stream* serialPort = NULL;

/** Variabel to hold the reference to the Serial object to use for debugging.
* Uses the class Stream instead of HarwareSerial */
Expand Down

0 comments on commit cc5eb7b

Please sign in to comment.