How to add a throttle to a Carrera Vengeance E Spec

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
is switching the LCD off and on again the only way to clear error 22 without touching the pedals?

what if you wait a few seconds then use the throttle or pedal again after error 22 shows up? would that clear error 22?
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
is switching the LCD off and on again the only way to clear error 22 without touching the pedals?

what if you wait a few seconds then use the throttle or pedal again after error 22 shows up? would that clear error 22?
So far I have been switching the LCD off and on to reset, but let me try and wait for a few seconds and retry throttle / pedal see what happens.
 

Evian1040

Pedelecer
Jul 7, 2020
75
9
As far as i'm aware if any error is presented, the controller ceases all functionality as it thinks its "broken" to protect itself from overvoltage or something else.
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
Spot on Evian, so I waited a couple of minutes before trying anything and it wouldn't function at all until i powered off and on.

So I am trying to debug the code however I can't seem to debug anymore, if I plug the Ardiuno to the USB and to the bike I get error 21 on the LCD.

Either way I was running the multimeter against pin A5 whilst running the throttle and I noticed that when I release the throttle the after a second or 2 the value jumps to 3.86v now I'm wondering if this 'jump' is the cause and if we need to slow it down so its in ratio to the decline.
 
Last edited:

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
can you try this code which simply replicates torque and cadence:

Code:
// Test cadence and torque replication

const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = 13;
const byte TorqueAtRest = 198;

int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25;   // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  pinMode(CadenceOutputPin, OUTPUT);
  pinMode(TorqueInputPin, INPUT);
  pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin
  pinMode(CadenceInputPin, INPUT); //PASCadencePin
  digitalWrite(TorqueOutputPin, LOW);
  startMillis = millis();
  // Serial.begin(9600);
}

void loop() {
    if (millis()>currentMillis) // run once every millisecond
    {
        currentMillis = millis();
        // I'm pedalling
        analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
        if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH);
        else digitalWrite(CadenceOutputPin, LOW);
    }
}
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
can you try this code which simply replicates torque and cadence:

Code:
// Test cadence and torque replication

const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = 13;
const byte TorqueAtRest = 198;

int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25;   // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  pinMode(CadenceOutputPin, OUTPUT);
  pinMode(TorqueInputPin, INPUT);
  pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin
  pinMode(CadenceInputPin, INPUT); //PASCadencePin
  digitalWrite(TorqueOutputPin, LOW);
  startMillis = millis();
  // Serial.begin(9600);
}

void loop() {
    if (millis()>currentMillis) // run once every millisecond
    {
        currentMillis = millis();
        // I'm pedalling
        analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
        if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH);
        else digitalWrite(CadenceOutputPin, LOW);
    }
}
I'll try and test this later today and relay the results.
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
can you try this code which simply replicates torque and cadence:

Code:
// Test cadence and torque replication

const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = 13;
const byte TorqueAtRest = 198;

int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25;   // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  pinMode(CadenceOutputPin, OUTPUT);
  pinMode(TorqueInputPin, INPUT);
  pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin
  pinMode(CadenceInputPin, INPUT); //PASCadencePin
  digitalWrite(TorqueOutputPin, LOW);
  startMillis = millis();
  // Serial.begin(9600);
}

void loop() {
    if (millis()>currentMillis) // run once every millisecond
    {
        currentMillis = millis();
        // I'm pedalling
        analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
        if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH);
        else digitalWrite(CadenceOutputPin, LOW);
    }
}
I’ve tested this now. Results as follows:

1. on startup no errors
2. Pedalling ok then after approximately 5secs received error 22.
 

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
that seems to indicate that the error is caused by the replication routine and not while the bike is on the throttle.
What do you think?

if you can, change this line:

analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);

to:
analogWrite(TorqueOutputPin, 20 + analogRead(TorqueInputPin)/4);

to boost the A5 voltage a bit to see if it has any effect on the outcome.
 
Last edited:

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
that seems to indicate that the error is caused by the replication routine and not while the bike is on the throttle.
What do you think?

if you can, change this line:

analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);

to:
analogWrite(TorqueOutputPin, 20 + analogRead(TorqueInputPin)/4);

to boost the A5 voltage a bit to see if it has any effect on the outcome.
I think your right seems like the replication routine needs tweaking.
I’ll try this code first thing and relay the results.

we have the throttle routine working now we just need to take a step back to the functions of the pedalling. We’re getting there!
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
that seems to indicate that the error is caused by the replication routine and not while the bike is on the throttle.
What do you think?

if you can, change this line:

analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);

to:
analogWrite(TorqueOutputPin, 20 + analogRead(TorqueInputPin)/4);

to boost the A5 voltage a bit to see if it has any effect on the outcome.
Finally got round to testing this.

1. no errors on start up
2. After 3 seconds of pedalling received error 22

so I’m thinking ideally is there no way to exit the code if we are pedalling similar to how an interrupt works?But I guess that means we have to change wiring to pass pedalling straight to controller.
 
Last edited:

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
to test the cadenceInput, connect the A5 wire directly to pin A3 (torqueInput).
Leave the code like it is.
If the code yields error 22 in the same way, we'll know that the replication of the cadence is not good enough.
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
to test the cadenceInput, connect the A5 wire directly to pin A3 (torqueInput).
Leave the code like it is.
If the code yields error 22 in the same way, we'll know that the replication of the cadence is not good enough.
OK I think you're right. I connected A5 to A3 and after approx 3 seconds I received error 22.
 

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
Now let's test the translation of the TorqueInput, re-install the A5 wire and connect this time the D13 wire to A2 pin.
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
Now let's test the translation of the TorqueInput, re-install the A5 wire and connect this time the D13 wire to A2 pin.
OK so as soon as I powered on the bike, the motor kicked in without me doing anything then after 2secs returned error 22.
 

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
I am surprised by the result.
A2 (cadence input) and D13 (cadence ouput) are normally joined before we place them on the arduino.
I would have expected no error on startup.

Can we join A2 (cadence input) and D13 (cadence ouput) but leave the connection unattached to pin A2?
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
I am surprised by the result.
A2 (cadence input) and D13 (cadence ouput) are normally joined before we place them on the arduino.
I would have expected no error on startup.

Can we join A2 (cadence input) and D13 (cadence ouput) but leave the connection unattached to pin A2?
Ok I’ve done this and I had the same results.

so I removed the green wires from A2 and D13 and joined the 2 wires together outside of the Arduino. I powered on the bike and the motor kicked in straightaway then went to error 22 after 3sec
 

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
Can you re-install the D13 wire and leave the A2 wire disconnected (in the air) to see if the motor starts on its own?
 

rajeshtailor

Pedelecer
Jun 5, 2020
170
3
Can you re-install the D13 wire and leave the A2 wire disconnected (in the air) to see if the motor starts on its own?
I tested this and the motor started on its own.
1. Power on - motor kicks in then reports error 22 after 3 secs
 

Woosh

Trade Member
May 19, 2012
20,367
16,870
Southend on Sea
wooshbikes.co.uk
I think one possible cause is D13 being overloaded because the current limit on D13 is only 40mA. 20mA already used by the LED.
The solution is to move the Cadence Output from D13 to A4 and use D13 as LED indicator.


Code:
// Test cadence and torque replication Version 2
// Avoid D13 because of the internal LED
// but duplicate output to keep blinking LED as indicator

const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = A4;
const byte TorqueAtRest = 198;

int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25;   // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  pinMode(CadenceOutputPin, OUTPUT_PULLUP);
  pinMode(TorqueInputPin, INPUT_PULLUP);
  pinMode(TorqueOutputPin, OUTPUT_PULLUP); //ControllerTorquePin
  pinMode(CadenceInputPin, INPUT_PULLUP); //PASCadencePin
 
  startMillis = millis();
  // Serial.begin(9600);
}

void loop() {
    if (millis()>currentMillis) // run once every millisecond
    {
        currentMillis = millis();
        // I'm pedalling
        analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
        if (analogRead(CadenceInputPin) > 512) analogWrite(CadenceOutputPin, 255);
        else analogWrite(CadenceOutputPin, 0);
        // blink LED indicator
        if (analogRead(CadenceInputPin) > 512) digitalWrite(D13, HIGH);
        else digitalWrite(D13, LOW);

    }
}
 
Last edited:

Advertisers