1 (edited by tazmahv 2021-11-05 17:50:29)

Topic: motorcycle control

hello everyone i am new to the forum i hope to learn as i am a very very newbie
Well, surfing the net I found this app that I see very interesting
the issue is that I want to build this project on an esp8266 which is already programmed
but it is impossible for me to connect to the wifi
  Also comment that I would like to adapt this app to the project
that it is a slider for speed and another slider to control steering wheel direction and a button for led


this is the code I hope you can help me
thank you

2

Re: motorcycle control

// Pin number --> neopixel led 13/ servo 5/ motor 4,15
// Range --> motor 1000~2000 / Servo 60~120 degree

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Servo.h>
#include "Adafruit_NeoPixel.h"
                                                                                                                                                                
#define motor_d1 4
#define motor_d2 15
#define led_lighting 13
#define led_num 1
#define servo_streeing 5

Adafruit_NeoPixel lighting = Adafruit_NeoPixel(led_num, led_lighting, NEO_GRB + NEO_KHZ800);

const char *ssid = "xxxxxxxxxxx";<--------   here is my ssid 
const char *pw = "xxxxxxxxx"; <---------- here is my password   
IPAddress ip(192, 168, 0, xxx);<--------- here is my IP that the router grants 
IPAddress netmask(255, 255, 255, 0);
const int port = 9876;

int led_state;
int motor_speed = 0;
int servo_angle = 0;
int val_motor;

char cmd[100];
int cmdIndex = 0;

WiFiServer server(port);
WiFiClient client;

Servo handle;

void setup() {
    pinMode(motor_d1, OUTPUT);
    pinMode(motor_d2, OUTPUT);
    pinMode(led_lighting, OUTPUT);

    analogWrite(motor_d1, 0);
    analogWrite(motor_d2, 0);

    handle.attach(servo_streeing);
    // handle.write(50);

    lighting.begin(); 
    lighting.setBrightness(100);
    lighting.setPixelColor(0, 0, 0, 0);
    lighting.show(); 

    WiFi.softAPConfig(ip, ip, netmask);
    WiFi.softAP(ssid, pw);

    server.begin();
    Serial.begin(115200);
}

boolean cmdStartsWith(const char *st) {
    for (int i = 0;; i++) {
        if (st[i] == 0) return true;
        if (cmd[i] == 0) return false;
        if (cmd[i] != st[i]) return false;
    }
    return false;
}

void exeCmd() {

    if(cmdStartsWith("th") ) {
    motor_speed = atoi(cmd+3);
    }

    if(motor_speed>1500) {  
       val_motor = map(motor_speed, 1500, 2000, 0, 1023);       
       analogWrite(motor_d2, val_motor);
//       Serial.print("th 1500 > ");
//       Serial.println(val_motor);     
    }
    if(motor_speed<1500) {  
       val_motor = map(motor_speed, 1500, 1000, 0, 1023);       
       analogWrite(motor_d1, val_motor);
//       Serial.print("th 1500 < ");
//       Serial.println(val_motor);  
    }
    if(motor_speed == 1500 ) {
      analogWrite(motor_d1, 0);
      analogWrite(motor_d2, 0);
    }

    if (cmdStartsWith("st") ) {
    servo_angle = atoi(cmd+3);
    handle.write(servo_angle);
//    Serial.println(servo_angle);
    }

    if (cmdStartsWith("w")) {
        led_state = (led_state == LOW) ? HIGH : LOW;
        if(led_state == HIGH) {
          lighting.setPixelColor(0, 255, 255, 255);
          lighting.show(); 
        } else{
          lighting.setPixelColor(0, 0, 0, 0);
          lighting.show(); 
        }
    }
}

void loop() {
    if (!client.connected()) {
        client = server.available();
        return;
    }

    if (client.available()) {
        char c = (char)client.read();

        if (c == '\n') {
            cmd[cmdIndex] = 0;
            exeCmd();
            cmdIndex = 0;
        } else {
            cmd[cmdIndex] = c;
            if (cmdIndex < 99) cmdIndex++;
        }
    }
}

3 (edited by Gunner 2021-11-08 03:40:47)

Re: motorcycle control

tazmahv wrote:

hello everyone i am new to the forum

Welcome smile

tazmahv wrote:

the issue is that I want to build this project on an esp8266 which is already programmed
but it is impossible for me to connect to the wifi

For this you have no option but to plug in with the USB

tazmahv wrote:

I would like to adapt this app to the projec

I recommend you start small and learn how the App works, via the instructions and demos provided. 

And then, assuming you also know a little bit about Arduino programming, you should be able to eventually merge RemoteXY library/control into your existing programs.

"And voila, which is French for.......'and then I found out.'"

4

Re: motorcycle control

Hello, thanks for the answer I will try to understand how the application works and on the programming it will cost me more
Is it possible to give some advice on how it could be merged
sketch with remotexy
Thank you

5 (edited by Gunner 2021-11-08 09:48:57)

Re: motorcycle control

There is no real shortcut to merging an existing program with a totaly new GUI/HMI app, library, and method of control... short of having someone else do all the work for you.  And, no, that is not likely to happen here (or on any other forum I have been on) smile

"And voila, which is French for.......'and then I found out.'"

6

Re: motorcycle control

ok, ok I understand I do not pretend that they do the work for me, I just want to understand the process a little

7

Re: motorcycle control

tazmahv wrote:

I just want to understand the process a little

Unfortunately is seems that if you don't understand that the "process" is not so simple, then you may be trying to understand running before crawling smile

On an overly simplified level, you need the following...

- You need to understand how RemoteXY works, in order to understand how to use the library and the elements and associated commands you want to use.

- You need to understand how the original program works so you know what current commands/functions to replace or work alongside of, if possible.

- Then you need to have enough programming experience to merge the code, if possible, or alternatively rebuild the code to do the new thing.  And troubleshoot any issues along the way.

Again, I recommend you start at the beginning and learn how RemoteXY works...  Feel free to create new topics relating to any questions you have in the process.

Enjoy!

"And voila, which is French for.......'and then I found out.'"

8

Re: motorcycle control

thanks for the advice

9 (edited by tazmahv 2021-11-11 09:47:08)

Re: motorcycle control

well I'm trying to create sketches to learn how remotexy works
but I can't connect by wifi
I understand that it is an IP and ports error
I do not know the motive
upload the image
thanks




https://www.dropbox.com/s/g1ablfweutlri … 6.jpg?dl=0