2 3 4 5
GameboyRMH
GameboyRMH MegaDork
4/26/17 10:50 a.m.

Here's a setup that requires more breadboard work but is simpler and well-documented:

https://business.tutsplus.com/tutorials/controlling-dc-motors-using-python-with-a-raspberry-pi--cms-20051

tuna55
tuna55 MegaDork
4/26/17 10:52 a.m.

We discussed this one early on, but we decided the stall current of a motor would kill it.

GameboyRMH
GameboyRMH MegaDork
4/26/17 10:58 a.m.

Ah you're right, forgot about that.

Here's a beefy bastard that looks pretty simple compared to what you're working with now:

http://www.robotshop.com/en/10a-5-30v-dual-channel-dc-motor-driver.html

It's overkill but it would allow you to upsize the robot in the future.

tuna55
tuna55 MegaDork
4/26/17 11:10 a.m.

bought it. Hopefully Tunawife won't mind.

tuna55
tuna55 MegaDork
5/9/17 10:44 a.m.

Got the new controller wired up.

Now I need to get back to programming.

Where is the entire wire numbering chart? Which are pwm out?

This one looks simple. I hope to have the stupid thing moving this week. My kids are done with school now. The schedule could not be better.

GameboyRMH
GameboyRMH MegaDork
5/9/17 11:13 a.m.

Here's the pinout chart:

https://pinout.xyz/

tuna55
tuna55 MegaDork
5/11/17 6:41 a.m.

Got it!

The new motor controller works, and I can make stuff happen. Now for the easy part?

I want to have it do a subroutine when I press a button. So, a "turn left", "Turn right" "go forward" and "go backwards" subroutine and four buttons.

Something like that. I can figure out the tiny subroutines, but I don't know how to put them into a "wait for the button" command, nor how to make them only wait for more buttons once the subroutine is finished.

This is important because it's really hard to hit the 'run' button, unplug the mouse, unplug the keyboard, unplug the monitor, and then let it go.

Thanks for the help so far! I hope to have some fun with the kids tonight showing them how it moves.

GameboyRMH
GameboyRMH MegaDork
5/11/17 8:09 a.m.

Rather than building buttons you can do it with different Python scripts executed remotely over an SSH (or VNC, if you'd like) connection. That means you'd also have remote control.

tuna55
tuna55 MegaDork
5/11/17 8:19 a.m.
GameboyRMH wrote: Rather than building buttons you can do it with different Python scripts executed remotely over an SSH (or VNC, if you'd like) connection. That means you'd also have remote control.

I don't know what either of those acronyms means, but if it means spending money, I'm out.

Buttons!

GameboyRMH
GameboyRMH MegaDork
5/11/17 8:22 a.m.

Hahaha no there's no spending required, all free software, it's cheaper than buttons in fact.

SSH is a remote terminal, VNC is a remote desktop.

tuna55
tuna55 MegaDork
5/11/17 8:45 a.m.
GameboyRMH wrote: Hahaha no there's no spending required, all free software, it's cheaper than buttons in fact. SSH is a remote terminal, VNC is a remote desktop.

ok, show me how to set it up.

So we're talking about hitting buttons on a laptop and making it go from its wifi?

GameboyRMH
GameboyRMH MegaDork
5/11/17 8:51 a.m.

Yep that's basically the idea. More specifically I'm thinking about setting up one python script that waits for arrow key inputs that move the robot. Here's how to set up an SSH connection:

https://www.raspberrypi.org/documentation/remote-access/ssh/

tuna55
tuna55 MegaDork
5/11/17 8:56 a.m.
GameboyRMH wrote: Yep that's basically the idea. More specifically I'm thinking about setting up one python script that waits for arrow key inputs that move the robot. Here's how to set up an SSH connection: https://www.raspberrypi.org/documentation/remote-access/ssh/

How do you code it to look for arrow keys?

GameboyRMH
GameboyRMH MegaDork
5/11/17 9:08 a.m.

There are many ways, but I found some simple example code here:

https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user

If you post the test code you're working with (use PasteBin) I could help you put something together.

tuna55
tuna55 MegaDork
5/11/17 9:29 a.m.
GameboyRMH wrote: There are many ways, but I found some simple example code here: https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user If you post the test code you're working with (use PasteBin) I could help you put something together.

I am having trouble with that, the Pi crashes if I try and open up this website on it. I am not sure why. I'll see if I can get it off with a thumb drive.

tuna55
tuna55 MegaDork
5/11/17 8:41 p.m.

I tried to add some logic in there to allow me to control the direction, but it's incomplete. I am not a programmer:

1: How do I do that? I have two wires, when ground they go one way, when high they go the other way. Not sure how to set that up.

2: How do I place pieces of this inside code which allows me to activate parts of the code under certain conditions and whatnot?

Thanks

tuna55
tuna55 MegaDork
5/11/17 8:46 p.m.

https://pastebin.com/embed/6vUSQeji

GameboyRMH
GameboyRMH MegaDork
5/12/17 8:38 a.m.
  1. From what I can see in the controller's manual, the controller's direction inputs consider >3V to be high and <3V to be low, so you should be able to connect these to digital outputs on the raspi and switch them easily. It has another mode you can use to save on outputs on the RasPi, where the PWM pins are tied high and the PWM signals are sent to the DIR pins, where 50% is stopped and less than that is reverse and more is forward. You can use whichever mode you like.

  2. Many ways to do that, that's what we'll get to now. In general I'd say you'll want to write functions you can call which will easily set direction and speed on the motors with something like setmotor('left','forward',50) . The dirty work code of setting digital output conditions and PWM duty cycles and frequencies would go inside those functions.

So, to be clear, with the test code you have now, you've got the left motor turning for 10 seconds, then the right motor turning for 10 seconds, then both motors turning for ten seconds? That all works?

tuna55
tuna55 MegaDork
5/12/17 8:48 a.m.
GameboyRMH wrote: 1. From what I can see in the controller's manual, the controller's direction inputs consider >3V to be high and <3V to be low, so you should be able to connect these to digital outputs on the raspi and switch them easily. It has another mode you can use to save on outputs on the RasPi, where the PWM pins are tied high and the PWM signals are sent to the DIR pins, where 50% is stopped and less than that is reverse and more is forward. You can use whichever mode you like. 2. Many ways to do that, that's what we'll get to now. In general I'd say you'll want to write functions you can call which will easily set direction and speed on the motors with something like setmotor('left','forward',50) . The dirty work code of setting digital output conditions and PWM duty cycles and frequencies would go inside those functions. So, to be clear, with the test code you have now, you've got the left motor turning for 10 seconds, then the right motor turning for 10 seconds, then both motors turning for ten seconds? That all works?

Yup! It works great!

The kids are excited. I still have not figured out how to add a fully functioning digital output for direction, or digital input, for a button, but we're getting there.

tuna55
tuna55 MegaDork
5/12/17 8:49 a.m.

Oh, and I had not realized that there was a 0-50, 50-100 mode, but for clarity in code, for the kids use (because I hope they will play with the code) I'd say let's just run the direction as a digital output.

GameboyRMH
GameboyRMH MegaDork
5/12/17 11:11 a.m.

I threw this together quickly, I blind-coded it so you'll be the first one testing it, but it should let you use the robot as an RC car:

https://pastebin.com/rXJ3w6r7

GameboyRMH
GameboyRMH MegaDork
5/15/17 9:56 a.m.

So you haven't posted any updates...is it because it's not working or because you're having too much fun with the robot?

tuna55
tuna55 MegaDork
5/18/17 10:58 a.m.

Haven't tried it yet, I'm a terrible person.

We're going to be on vacation for a while, and we're planning and packing and such. I want to try and play with it tonight or tomorrow night with the kids.

Tuesdays are tough because they have Trail Life outings

Wednesdays are tough because we get back from church late

tuna55
tuna55 MegaDork
6/23/17 8:21 a.m.

I finally got to try it.

It didn't work!

It opened up a window, and told me to hit buttons to control it, but when I typed those buttons it just put them in the box.

So it looked like this:

Press A/W/S/D:

aaassswwdddd

But nothing moved.

Your way over my head in terms of programming, so I can't diagnose this without added knowledge.

GameboyRMH
GameboyRMH MegaDork
6/23/17 9:01 a.m.

Looks like the keypress detection isn't working. I can test that on my end so I should be able to get that fixed pretty quick.

2 3 4 5

You'll need to log in to post.

Our Preferred Partners
VC5a8qRivnQcmanRpEfV2ZKFUQbhayv6aFx4JsGhl2Jxi8q3cZjLabUxi4tcFXFF