Spark core rc car with camera controlled over wifi

Hello Im interested if it is possible to built something like this. So there will be camera on the car and the video will be streamed to web and i can control car with keyboard through gpio. If it is possible, which camera is the best ? I would like to make it as my first and also cheap project. Thanks for all!

I think you cannot stream video with the Spark Core, it is simply not so powerful. But this sounds like a very good fit for a raspberry pi. You can install mjpeg-streamer on a raspberry pi to stream video. Then for controlling the car, you could easily hook up a bluetooth keyboard that sends keystrokes to an app. The tricky part then still is to take the keystrokes and convert it to signals for the GPIO and drive the motors.

1 Like

The Spark Core is not ideal for streaming high bandwidth data, so streaming of video will not be possible. Raspberry Pi is a good option, or you could simply attach a WiFi camera ! and use the :spark: Core to navigate/control the car.

I made it last week. One can drive my car over the internet on a browser that supports WebRTC. I have no wireless camera right now. Im using a webcam to show driver the car (not wireless, connected to pc).

If you just want to control your car locally, you can use a socket to connect to Spark Core. Im using a socket that is being used in libjingle that is c++ imlementation of WebRTC.

This is a page that show how to use C# socket:

This is Spark firmware I use:

/* Globals -------------------------------------------------------------------*/
    int leftMotor    = A6;
    int rightMotor   = A7;
    int forwardMotor   = D6;
    int backwardMotor  = D7;
   
   
    TCPServer server = TCPServer(80);
       
        char myIpString[24];
        void setup()
        {
            server.begin();
       
            Serial.begin(9600);
       
            delay(1000);
       
    //I expose Ip Address of the core so I can learn it from cloud and connect it with socket on my pc.
            IPAddress myIp = Network.localIP();
            sprintf(myIpString, "%d.%d.%d.%d", myIp[0], myIp[1], myIp[2], myIp[3]);
            Spark.variable("ipAddress", myIpString, STRING);
           
            pinMode(forwardMotor, OUTPUT);
            pinMode(backwardMotor, OUTPUT);
            pinMode(leftMotor, OUTPUT);
            pinMode(rightMotor, OUTPUT);
           
        }
       
       
       
     const byte LEFT = 1;
     const byte RIGHT = 2;
     const byte FORWARD = 4;
     const byte BACKWARD = 8;
     
    void rcCarControl(byte cmd)
    {
       
        if(cmd == 0){
            digitalWrite(forwardMotor,LOW);
            digitalWrite(backwardMotor,LOW);
           
            digitalWrite(leftMotor,LOW);
            digitalWrite(rightMotor,LOW);
           
            return;
        }
       
       
        if((cmd & FORWARD) == FORWARD)
        {
            digitalWrite(backwardMotor,LOW);
            digitalWrite(forwardMotor,HIGH);
        }
        else if((cmd & BACKWARD) == BACKWARD)
        {
            digitalWrite(forwardMotor,LOW);
            digitalWrite(backwardMotor,HIGH);
        }
        else{
            digitalWrite(forwardMotor,LOW);
            digitalWrite(backwardMotor,LOW);
        }
       
        if((cmd & LEFT) == LEFT)
        {
            digitalWrite(rightMotor,LOW);
            digitalWrite(leftMotor,HIGH);
        }
        else if((cmd & RIGHT) == RIGHT)
        {
            digitalWrite(leftMotor,LOW);
            digitalWrite(rightMotor,HIGH);
        }
        else
        {
            digitalWrite(leftMotor,LOW);
            digitalWrite(rightMotor,LOW);
        }
       
    }
   
    TCPClient client;
    char stopByte = 255;
    void loop()
    {
        if (client.connected()) {
            // echo all available bytes back to the client
            while (client.available()) {
               
                delay(50);
               
                for (unsigned int i = 0; i < sizeof(buffer); i++) {
                    byte c = client.read();
                    if (c == stopByte) {
                        break;
                }

                Serial.print(c);
                rcCarControl(c);
            }               
           
            delay(50);
        }
       
    } else {
        // if no client is yet connected, check for a new connection
        client = server.available();
    }
}

You will not be able to reconnect core after closing a socket connection with this code. You may want to change it.

You can also check my earlier post about my project old version.

3 Likes