My First RC Car, Now Spark Enabled!

I started messing around with the Spark Kit, and the first RC car I ever owned, circa 1993. I’d gutted it for other projects, but basically this is what happens out of the box with the Spark Kit, the Spark App, and a half-hour of fiddling.

Before Spark:

Virtually child-proof proof RC car (it’s old enough to drink!)

After Spark:

If you overlook the fact you can’t see the car under all the loose kit and wiring, it can be driven from an iPhone using Tinker, and required no code. I may keep at this project and clean it up, but we’ll see.

Parents, talk to your kids about messy prototyping, and exercise caution when internet enabling things.
Or do what I did, your call.

Cheers,

4 Likes

LOL this is great! Nice job and I hope you do make it smaller because that would be a real work of art if you could get it all into the body. Might need to make a custom PCB for it though.

That is soooooooo awesome. I gotta find a sweet chassis like that for my Spark RC Car adventures that lie ahead!

Reminds me of this chassis :slight_smile: http://www.toysrus.com/buy/preschool/toy-story-andy-s-room-rc-car-64013-3538518

I do have an update on this actually. I’m trying to utilize the Shield Shield, and this Ardumoto shield from Sparkfun: https://www.sparkfun.com/products/9815 as well as dive into the Web Build platform.

I’m basically trying to port some of my arduino code that drives this shield to the SC, by defining alternate pins and with my own digital and analogWrites in the rcCarControl function, based on the Spark Core RC example code. I’m a little unfamiliar with the pin initialization for SC and whether I’m defining the proper pins correctly. The moto shield uses 3, 11, 12, and 13.

My original arduino inits:

const int driveSpeedPin = 3;       //PWM for Forward / Reverse Speed
const int driveDirPin = 12;        //Control Forward / Reverse Direction
const int steerSpeedPin = 11;      //PWM for Steering Speed
const int steerDirPin = 13;        //Direction control for Left / Right

Seem to work here, but the end result is that my car doesn’t move after sending a seemingly correct POST. I noticed in other examples that pins are typically defined similar to:

int pinZero = D0;

I tried to emulate this, but D11,D12, and D13 aren’t recognized by the Web Builder. The app does seem to compile and deploy with the arduino init code. I can post with:

curl -k "https://api.spark.io/v1/devices/<id>/rccar" \ -d "<token>" \ -d args=rc,FORWARD"

and receive:

    {
  "id": "<id>",
  "name": "BlueLou_1",
  "last_app": null,
  "connected": true,
  "return_value": 1
}

So that part seems to be working. There’s a ton of moving parts I’m sure, but so far the only thing not moving is my car!

Any tips, or incredibly obvious things I should try?

Change to:

const int driveSpeedPin = D0;      //PWM for Forward / Reverse Speed
const int driveDirPin = A4;        //Control Forward / Reverse Direction
const int steerSpeedPin = A5;      //PWM for Steering Speed
const int steerDirPin = A3;        //Direction control for Left / Right

Should work!

Shield Shield pin map:

"Shield I/O pin" is the Arduino pinout.

You basically reference the pins as D0 - D7 and A0 - A7. These are constants for 0 - 7 and 10 - 17 in decimal respectively.

1 Like

That did it alright.

I guess I didn’t quite understand that table the first time around. You’ll have to excuse me, I’m less of a developer and more of dabbler.

But now we’re talkin!

Anyone mock up a web ui with a couple buttons yet? I’d love to save myself the trouble.

1 Like

Awexome, looking better already. Try this out… 1 - 4 buttons ready to go, define everything really easy and it sets up the buttons for you :smile:

Just add three more functions in the user app and name them how you want, and edit the index.html with the right names and your ID info.

1 Like

Hello @BDub,
I tried your program and it works but always returns message: Error!
When I turn off SparkCore, then appears ERROR! Timed Out message.
Why command is passed but not getting the message “SUCCESS!”.
Do I need to change the values ​​of the timers or there is an error in the script?

Hi @developer_bt, if you look in the code it is expecting a returned value of 200 from your function, e.g. return 200;. If it doesn’t see it, it will report Error. This is just a little “feel good” way of knowing your button press on the app actually got to your Spark Core. Definitely helpful when you can’t see your Spark Core. Let me know if that works for you, and feel free to customize that anyway you’d like :smile:

1 Like

Thanks for the rapid response :smile:
The application works command is received by SparkCore, but not returns a message "SUCCESS!
In the Chrome console appears next response:

Object {id: "1234567891234567891234", name: "sparkcore", last_app: null, connected: true, return_value: 1…}
connected: true
id: "1234567891234567891234"
last_app: null
name: "sparkcore"
return_value: 1

Why instead value of 200, I get the value 1?
By changing the following line of code I get the appropriate response:

(obj.return_value && obj.return_value == 200) ? onMethodSuccess() : onMethodFailure((obj.error)?obj.error:"");

 (obj.return_value && obj.return_value == 1) ? onMethodSuccess() : onMethodFailure((obj.error)?obj.error:"");// change!

I'm guessing because your application does not return 200; like this:

bool state = HIGH;

void setup() {
    pinMode(D7,OUTPUT);
    digitalWrite(D7,HIGH); // turn on D7 by default
    Spark.function("test", testFunction);
}

void loop() {
	// do nothing
}

int testFunction(String args) {
    state = !state; // toggle the state
    digitalWrite(D7,state); // update the LED so we can see some action
    return 200; // This is checked in the web app controller for validation
}

:slight_smile:

1 Like

I use to test this application [https://github.com/spark/core-firmware/blob/master/src/application.cpp][1]
I thought that the server codes are embedded in the firmware.
Now it is clear :smile:
This is what I needed, great application @BDub!
Thanks!

1 Like

Hey, I know I haven’t followed up in awhile, but i did get back to playing with the SC.

Picked up a much bigger and faster RC Monster truck and was able to strip out it’s internals and wire up a SparkCore in about an hour. It’s got plenty of room for sensors, and I didn’t need to make a single modification to the chassis!

I was able to use the example web UI code via BDub to control it with buttons, and then went a few steps further, adding a couple more buttons and functions. The last thing I did was bind WASD keys to keyup and keydown events, mapping those to my drive functions. The RC car handles ok, but it’s a bit laggy over the internet, which doesn’t surprise me that much. Still a riot to drive around!

As a reference, here’s a snippet of keyup and keydown sample code:

	$(document).keydown( function(event) {
	if (event.which === 87) {
	//console.log("W Key Pressed");
	doMethod(funcKey1, args1);
	}
	}); 
	$(document).keyup( function(event) {
	if (event.which === 87) {
	//console.log("W Key Released");
	doMethod(funcKey4, args4);
	}
	}); 

Should work as long as the web page has focus.

1 Like

Great! Now try converting it to Local TCP or UDP communication to speed things up :smile:
http://docs.spark.io/#/examples/local-communication