Feux arriere fonction de la gachette ppm

J’ai décidé de construire un feux arriere qui flash en fonctionnement normal et qui s’éclaire pleinement en cas de freinage (afin d’éviter les collisions avec les copains qui suivent derrière).

Pour résumer le budget est inférieur à 10€, l’encombrement 2*3 cm et le tout alimenté par le vesc (ou pas) car la consommation (en fonction de la lampe stop biensur) est de 200mA - 5V

PART LIST :

CIRCUIT : la conso est de 200mA quand la lampe est allumée, donc c’est assez pour etre alimenté par le VESC


SOFTWARE : Pour l’installation de la librairie digispark ce tutorial est bien:

Installing Drivers and Programming the DigiSpark ATtiny85 dev boards - Tutorial

Pour le logiciel je me suis inspiré :

rcarduino.blogspot.com

How To Read an RC Receiver With A Microcontroller - Part 1

J’ai juste modifié pour faire flasher la lampe quand le skate ne freine pas

Le programme :

#define THROTTLE_SIGNAL_IN 0 // INTERRUPT 0 = DIGITAL PIN 2 - use the interrupt number in attachInterrupt #define THROTTLE_SIGNAL_IN_PIN 2 // INTERRUPT 0 = DIGITAL PIN 2 - use the PIN number in digitalRead #define BRAKE_SIGNAL_OUT 1 #define NEUTRAL_THROTTLE 1500 // this is the duration in microseconds of neutral throttle on an electric RC Car #define PERIOD_BLINK 1000 // #define DURATION_BLINK 200 //

volatile int nThrottleIn = NEUTRAL_THROTTLE; // volatile, we set this in the Interrupt and read it in loop so it must be declared volatile volatile unsigned long ulStartPeriod = 0; // set in the interrupt volatile boolean bNewThrottleSignal = false; // set in the interrupt and read in the loop volatile boolean b_ActivateBlinkBrake = true; // Active blink brake light functionality volatile boolean b_EnableBlinkBrake = false; // Brake light show brake info in priority volatile unsigned long u_Cpt_Interrupt = 0; volatile boolean b_BrakeLightValue = false;

// we could use nThrottleIn = 0 in loop instead of a separate variable, but using bNewThrottleSignal to indicate we have a new signal // is clearer for this first example

void setup() { // tell the Arduino we want the function calcInput to be called whenever INT0 (digital pin 2) changes from HIGH to LOW or LOW to HIGH // catching these changes will allow us to calculate how long the input pulse is attachInterrupt(THROTTLE_SIGNAL_IN,calcInput,CHANGE); pinMode(BRAKE_SIGNAL_OUT, OUTPUT); //Serial.begin(9600); }

void loop() { // if a new throttle signal has been measured, lets print the value to serial, if not our code could carry on with some other processing if(bNewThrottleSignal) { //Serial.println(nThrottleIn);

// set this back to false when we have finished // with nThrottleIn, while true, calcInput will not update // nThrottleIn

u_Cpt_Interrupt++;

if(nThrottleIn <NEUTRAL_THROTTLE) { //Throttle BRAKE //Disable Blink light b_EnableBlinkBrake = false;

// Full light on brake output
b_BrakeLightValue = true;
//digitalWrite(BRAKE_SIGNAL_OUT,HIGH);

} else { b_EnableBlinkBrake = true; //Throttle NOT BRAKE b_BrakeLightValue = false; //digitalWrite(BRAKE_SIGNAL_OUT,LOW); } bNewThrottleSignal = false; }

//Manage blink light if(b_ActivateBlinkBrake && b_EnableBlinkBrake) { //Interrupt normally happen every 20ms if(u_Cpt_Interrupt * 20 > PERIOD_BLINK) { b_BrakeLightValue = false; if(u_Cpt_Interrupt * 20 < PERIOD_BLINK + DURATION_BLINK ) { b_BrakeLightValue = true; } else { //Reset cpt for new cycle u_Cpt_Interrupt = 0; } } } else { //Reset cpt for new cycle u_Cpt_Interrupt = 0; }

//Manage Brake Light output if(b_BrakeLightValue) { digitalWrite(BRAKE_SIGNAL_OUT,HIGH); } else { digitalWrite(BRAKE_SIGNAL_OUT,LOW); }

// other processing … }

void calcInput() { // if the pin is high, its the start of an interrupt if(digitalRead(THROTTLE_SIGNAL_IN_PIN) == HIGH) { // get the time using micros - when our code gets really busy this will become inaccurate, but for the current application its // easy to understand and works very well ulStartPeriod = micros(); } else { // if the pin is low, its the falling edge of the pulse so now we can calculate the pulse duration by subtracting the // start time ulStartPeriod from the current time returned by micros() if(ulStartPeriod && (bNewThrottleSignal == false)) { nThrottleIn = (int)(micros() - ulStartPeriod); ulStartPeriod = 0;

  // tell loop we have a new signal on the throttle channel
  // we will not update nThrottleIn until loop sets
  // bNewThrottleSignal back to false
  bNewThrottleSignal = true;
}

} }

11 « J'aime »

Salut Nenecossais,

merci d’avoir partagé ce post, j’ai qqn questions pour bien tout comprendre,

j’imagine que çà fonctionne avec n’importe qu’elle télécommande?

les 3 cables que tu pontes depuis le vesc sont bien ceux qui viennent du récepteur?

tu as réalisé le montage?

merci pour ton retour.

Salut
Dsl de répondre si tard… Ce montage doit fonctionner avec plusieurs radio commande (j’ai essayé 3 radiocommandes différentes) du moment que le type de signal est PPM (Point neutre à 1.5ms mais cela est un paramètre du soft) .
Je réalise la dérivation électrique entre le vesc et le recepteur radio.
A+

salut, j’ai aussi fait un montage a base de atiny85 et de neo pixel qui marche niquel.
si vous voulez je peut mettre un schéma rapide.

https://www.facebook.com/100024616868216/videos/824534131710475/

salut, j’ai fais la même avec la petite option des clignotants :wink:
mais je passe sur une commande FLIPSKY VX2
https://fr.aliexpress.com/item/4000326062527.html?spm=a2g0s.9042311.0.0.54d36c37ZzUGua
et la comme ne passe plus par du PPM et je voulais savoir si qqun avais une idée de comment faire.
merci la commu :wink:

le rx des vx1 a une sortie ppm. je pense que la vx2 ayant le même rx, cela doit marcher aussi.
par contre pas de clignotant.

Oui je sais pour le clignotant :wink: mais non il y a pas de sortie ppm sur la vx2 :smirk:

pourtant c’est le même rx. ah mais je viens de voir que entre la version 4.2 et 6, effectivement pas la même chose.
donc a moins de faire du sniffing avec un arduino ou utiliser le port de l’autre pour récupérer l’info, tu aura pas trop le choix.

Ouias je pense aussi , mais je m’y connais pas assez en Arduino pour faire le programme la :sob: si tu connais qqun qui a déjà fait ça ?

le soucis c’est que il y a peu de paramètre a lire pour voir le freinage, le seul qui peut être utile est le duty cycle. mais cela, n’informe pas forcement si on freine.
je vais essayer par curieusiter.

1 « J'aime »

merci , tien moi au jus :wink:

après je viens de voir que sur le recepteur du VX 2 il y a un pin PPM non utilisé. je sais pas si je peux l’utiliser , a tester.

si normalement, c’est que je te disait, la grosse différence est surtout les connecteur, mais pour avoir vue les deux rx, il sont identique.
enfin ceux d’il a quelque années.

je vais test ca je te redis :wink:

bon, j’ai des news. j ai branché le ppm sur mon arduino pour voir le signal. mais rien a voir avec un signal ppm , j’ai 0 quand j’accélère ou freine. j 'ai que des valeur quand j’ai de très brève impulsion sur la commande et uniquement en freinant

tu utilise quoi comme librairie pour la capture?

sinon, charge la librairie vesc uart dans ta blibliothèque elle est dispo dans le gestionnaire
et utilise cela:

#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);
Serial.println(UART.data.dutyCycleNow); 

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

delay(50);
}

attention, cela ne peut marcher que si tu as bien regler la vitesse uart a 19200 et que tu est sur le 2eme port uart (pas celui du rx)
tu verras le dutycycle varier, mais je croit qu’il passe en négatif lors du freinage, mais je n’en suis pas sur. il y aussi le courant moteur peut être a voir.
UART.data.avgMotorCurrent
mais pas sur que cela puisse aider.


j’ai ca comme soucis :sweat_smile:

as tu bien suivie la première étapes de charger la librairie? si tu ne l’installe pas cela ne marche pas.

oui oui j’ai installé la librairie VESC UART, celui la GitHub - RollingGecko/VescUartControl: Arduino library to interface with the VESC bldc over UART.