Boomer gets hands on Arduino!

Ahem…Boomer detected! You have been warned:face_with_monocle: Old guy here messing with stuff he doesn’t understand but sorely wants to. Been trying to setup up an Arduino uno to work a button controller via ppm in my Vesc mini and Focbox. I can get neither to show any readings when trying to map them. I know the code works because in the serial monitor it is showing the correct outputs for the program. I’m using the new Vesc tool and have updated the firmware on the Focbox. Motor setup OK,Bluetooth OK,just nothing for the input setup. Battery is a 5S2P 10Ah Li ion connecting to a Turnigy Aerodrive SK3 - 6354-260KV Brushless Outrunner Motor with Enertion Focbox (remember them?) Arduino nano and HM-10 BLE. Oh,this is for a FD on a bike.I’m way too old for one them boards. Can anyone point me towards(the door?) what I should be looking at to get the Arduino talking to my Vesc?
I’m set with ppm+Uart and baud 9600.Wired with TX and RX crossed Vcc etc etc.Not that any of that matters with the issue above but it makes it sound like I know stuff,which will be soon become evident,I don’t.
Cheers David

9 Likes

Hey David-

Glad to see you made it over to the busy forum. Let me know if you have any questions. We apologise in advance for @dareno

Welcome!

14 Likes

Thanks for the heads up!

4 Likes

Hiya David :wave:, I’ve made my own rf-nano based remote roughly an Arduino nano and rf module in one. You can use the Servo library and specifically the Servo.writeMicroseconds(1000); on any pwm capable pin (you set the pin when initializing the servo object)

If you share some code or point to a repo can take a look too. There are also ways to do uart communication with the vesc but for simple control of throttle the ppm/pwm signal is good enough.

3 Likes

You are trying to have an arduino control VESC throttle via buttons? or analog input?

Few ways to skin this cat, depending on what you are trying to accomplish.

It sounds like you’re trying to have a pwm output from the Arduino connect into the VESC, and read that as throttle input? You can do that, but ensure that you have the correct PWM output range coming out of the arduino (there are a few servo or PWM output libraries built in), that the correct pin output is connected to the pwm input on the arduino, and that you have the correct pwm/ppm app input selected on the vesc-tool.

It might also just be easier to directly connect the arduino to your ESC via the UART port.

The UART port on VESC-based ESCs will have a tx/rx/gnd/5v line which can be connected to your microcontroller for power & comms. There are some great open source arduino libraries that make controlling VESC-based ESCs that much easier.

Let’s see what code you’ve got so far and we can dig in a bit more.

5 Likes

Cheers wafflejock. I’ve already got a working arduino and button controller, sent over from a grown up, that works.he was also kind enough to send me the code,so I know the code is sound. It plays out fine on the serial monitor so I can’t understand how my nano is not talking to my vesc. His arduino works fine with both my vescs also? So to sum up.Same Vescs,same code ,his arduino works,mine doesn’t? The arduino he used is the one without a micro usb so I can’t plug directly into it as I haven’t a ttl at the moment. If you think it’ll help I can post the Visuino code up ?
Cheers

2 Likes

Bear with me here:
:flushed:button_program.ino (7.0 KB)
Let me know if that works.

1 Like

Welcome David and don’t let these guys fool you.

I am the only sane one here

9 Likes

Stay strong, everyone.

6 Likes

Fucker. You beat me with your double-fingered speed.

9 Likes

I feel a roasting coming on…

2 Likes

Sorry, David. We are first and foremost children here.

4 Likes

Putting here for other reader’s clarity, but we got you. Let me take a look.

//----------------------------------------------
//
//        Sketch Generated by Visuino
//              www.visuino.com
//          Version 7.8.2.261
//
//------------------ Source --------------------
//
// 1 button 2 speed and kill Ver2.visuino
//
//----------------------------------------------

#define VISUINO_ARDUINO_NANO

#include <OpenWire.h>
#include <Mitov.h>
#include <Mitov_FormattedSerial.h>
#include <Mitov_LogicFlipFlops.h>
#include <Mitov_Converters.h>
#include <Mitov_RampToValue.h>
#ifndef VISUINO_ESP32
#include <Servo.h>
#endif // VISUINO_ESP32
#include <Mitov_Servo.h>
#include <Mitov_LogicGates.h>
#include <Mitov_Button.h>
#include <Mitov_Math.h>

// Arduino Board Declarations

namespace BoardDeclarations
{
Mitov::TypedSerialPort<Mitov::SerialPort<SERIAL_TYPE, Serial>, SERIAL_TYPE, Serial> SerialPort0;
Mitov::ArduinoSerialInput<Mitov::TypedSerialPort<Mitov::SerialPort<SERIAL_TYPE, Serial>, SERIAL_TYPE, Serial>, SerialPort0, float> SerialPort0_InputFloat_1;
Mitov::ArduinoDigitalOutputChannel<3> ArduinoDigitalChannel_3( true, false );
Mitov::ArduinoDigitalChannel<5, false> ArduinoDigitalChannel_5( true, false, false, false, false, false, true );
Mitov::ArduinoDigitalChannel<9, false> ArduinoDigitalChannel_9( true, false, false, false, false, false, true );
} // BoardDeclarations

// Declarations

namespace Declarations
{
Mitov::TFlipFlop<Mitov::FlipFlop_Normal> TFlipFlop1;
Mitov::DigitalToTypeParams<float> DigitalToAnalog2 = Mitov::DigitalToTypeParams<float>( 1.0f, 0.0f );
Mitov::RampToValue RampToValue1;
Mitov::MitovServo<9, 820, 1950> Servo1;
Mitov::UnaryOperation<Mitov::BooleanInverter, bool> Inverter3;
Mitov::Button Button1;
Mitov::TFlipFlop<Mitov::FlipFlop_Normal> TFlipFlop4;
Mitov::DigitalToTypeParams<float> DigitalToAnalog4 = Mitov::DigitalToTypeParams<float>( 1.0f, 0.0f );
Mitov::MultiInputMathOperation<Mitov::Add<float>, float, 2> Add2;
Mitov::Button Button2;
Mitov::Button Button3;
} // Declarations

// Type Converters

namespace TypeConverters
{
Mitov::Convert_BinaryToClock Converter0;
Mitov::Convert_BinaryToClock Converter1;
Mitov::Convert_BinaryToClock Converter2;
} // TypeConverters

// Pin Call Declarations

namespace PinCalls
{
void PinCallerReceive1( void *_Data );
void PinCallerReceive2( void *_Data );
void PinCallerReceive3( void *_Data );
void PinCallerReceive4( void *_Data );
void PinCallerReceive5( void *_Data );
void PinCallerReceive6( void *_Data );
void PinCallerReceive7( void *_Data );
void PinCallerReceive8( void *_Data );
void PinCallerReceive9( void *_Data );
void PinCallerReceive10( void *_Data );
void PinCallerReceive11( void *_Data );
void PinCallerReceive12( void *_Data );
void PinCallerReceive13( void *_Data );
void PinCallerReceive14( void *_Data );
} // PinCalls

// Pin Call Implementations

namespace PinCalls
{
void PinCallerReceive1( void *_Data )
{
  Declarations::Inverter3.InputPin_o_Receive( _Data );
}

void PinCallerReceive2( void *_Data )
{
  Declarations::DigitalToAnalog2.InputPin_o_Receive( _Data );
}

void PinCallerReceive3( void *_Data )
{
  Declarations::Add2.InputPins_o_Receive( 0, _Data );
}

void PinCallerReceive4( void *_Data )
{
  BoardDeclarations::SerialPort0_InputFloat_1.InputPin_o_Receive( _Data );
  Declarations::Servo1.InputPin_o_Receive( _Data );
}

void PinCallerReceive5( void *_Data )
{
  Declarations::Button1.InputPin_o_Receive( _Data );
  Declarations::Button2.InputPin_o_Receive( _Data );
  Declarations::Button3.InputPin_o_Receive( _Data );
}

void PinCallerReceive7( void *_Data )
{
  TypeConverters::Converter0.Convert( _Data, PinCallerReceive6 );
}

void PinCallerReceive6( void *_Data )
{
  Declarations::TFlipFlop1.ResetInputPin_o_Receive( _Data );
  Declarations::TFlipFlop4.ResetInputPin_o_Receive( _Data );
}
void PinCallerReceive8( void *_Data )
{
  Declarations::DigitalToAnalog4.InputPin_o_Receive( _Data );
}

void PinCallerReceive9( void *_Data )
{
  Declarations::Add2.InputPins_o_Receive( 1, _Data );
}

void PinCallerReceive10( void *_Data )
{
  Declarations::RampToValue1.InputPin_o_Receive( _Data );
}

void PinCallerReceive12( void *_Data )
{
  TypeConverters::Converter1.Convert( _Data, PinCallerReceive11 );
}

void PinCallerReceive11( void *_Data )
{
  Declarations::TFlipFlop1.SetInputPin_o_Receive( _Data );
}
void PinCallerReceive14( void *_Data )
{
  TypeConverters::Converter2.Convert( _Data, PinCallerReceive13 );
}

void PinCallerReceive13( void *_Data )
{
  Declarations::TFlipFlop4.SetInputPin_o_Receive( _Data );
}
} // PinCalls

namespace ComponentsHardware
{
void SystemUpdateHardware()
{
}
} // ComponentsHardware

//The setup function is called once at startup of the sketch
void setup()
{
  BoardDeclarations::ArduinoDigitalChannel_3.OutputPin().SetCallback( PinCalls::PinCallerReceive1 );
  Declarations::TFlipFlop1.OutputPin().SetCallback( PinCalls::PinCallerReceive2 );
  Declarations::DigitalToAnalog2.OutputPin().SetCallback( PinCalls::PinCallerReceive3 );
  Declarations::DigitalToAnalog2.TrueValue = 0.5;
  Declarations::RampToValue1.Slope = 0.300000011920929;
  Declarations::RampToValue1.OutputPin().SetCallback( PinCalls::PinCallerReceive4 );
  Declarations::Servo1.InitialValue = 0;
  Declarations::Inverter3.OutputPin().SetCallback( PinCalls::PinCallerReceive5 );
  Declarations::Button1.OutputPin().SetCallback( PinCalls::PinCallerReceive7 );
  Declarations::TFlipFlop4.OutputPin().SetCallback( PinCalls::PinCallerReceive8 );
  Declarations::DigitalToAnalog4.OutputPin().SetCallback( PinCalls::PinCallerReceive9 );
  Declarations::DigitalToAnalog4.TrueValue = 0.5;
  Declarations::Add2.OutputPin().SetCallback( PinCalls::PinCallerReceive10 );
  Declarations::Button2.DebounceInterval = 500;
  Declarations::Button2.OutputPin().SetCallback( PinCalls::PinCallerReceive12 );
  Declarations::Button3.DebounceInterval = 1200;
  Declarations::Button3.OutputPin().SetCallback( PinCalls::PinCallerReceive14 );

  BoardDeclarations::SerialPort0.SystemInit();
  BoardDeclarations::ArduinoDigitalChannel_3.SystemInit();

  BoardDeclarations::ArduinoDigitalChannel_3.SystemStart();
  Declarations::TFlipFlop1.SystemStart();
  Declarations::RampToValue1.SystemStart();
  Declarations::Servo1.SystemStart();
  Declarations::Button1.SystemStart();
  Declarations::TFlipFlop4.SystemStart();
  Declarations::Add2.SystemStart();
  Declarations::Button2.SystemStart();
  Declarations::Button3.SystemStart();
}

// The loop function is called in an endless loop
void loop()
{
  unsigned long A_Current_Microseconds = micros();

  BoardDeclarations::SerialPort0.SystemLoopBegin( A_Current_Microseconds );
  BoardDeclarations::ArduinoDigitalChannel_3.SystemLoopBegin( A_Current_Microseconds );
  Declarations::RampToValue1.SystemLoopBegin( A_Current_Microseconds );
  Declarations::Button1.SystemLoopBegin( A_Current_Microseconds );
  Declarations::Button2.SystemLoopBegin( A_Current_Microseconds );
  Declarations::Button3.SystemLoopBegin( A_Current_Microseconds );

  Declarations::Add2.SystemLoopEnd( A_Current_Microseconds );
}

Ahem.

3 Likes

Took me ages to copy and paste that code…kids

5 Likes

Oh we are going to get along just fine…

6 Likes

So here’s the deal with this code that you were given.

This looks like a sketch built around Visuino, which is some visual IDE for arduino ecosystem.

Really digging into this would require downloading/installing that IDE and loading up all associated libraries. Essentially, someone used a pretty convoluted way of delivering you what should only be a few lines of code.

Do you have pictures/info on this ‘switch controller’ you’re using?

This is the kind of thing that would take me 5 minutes to code but probably an hour+ to dig into whatever the hell Visuino is. So knowing more about the hardware would help. Pics, wiring, etc.

4 Likes

Yes we are! I’m very partial to C&H

2 Likes

I’m pretty sure the codes fine, AD . It works fine on the original Ardunio. I’ve programmed my own Arduino with his code and ,although it outputs via the Serial monitor as it should,I’m getting he haw at the Vesc tool.

2 Likes

You are in very good hands with the idiot commenting above. He has that slightly aspergers way of those with large brains but don’t let that put you off.

Love you Andrew :smiling_face_with_three_hearts:

5 Likes

Ask for the help. Accept the help. DR might smell funny, but this is right up his alley.

2 Likes