Three 08M2s and a Pi?

3x08M2.bas (2771Bytes)

Hello! I'm a complete Picaxe n00b, but I have read quite a bit online, so hopefully my ideas here are not entirely inane.

I have been playing around with a Raspberry Pi as the brain for a small two-wheeled differential drive robot. It's very simple, but it more or less works.

One feature that seems near impossible with just the Pi itself is to drive the motors at different rates. I'd need two different PWM signals for that, and the Pi only has one PWM output. I've been looking for workarounds, and there are a few, but they don't seem terribly elegant. It seems there would be a few ways to do this with one or more Picaxe chips as peripherals taking simple instructions from the Pi. Originally, I thought I'd just be able to connect up a Picaxe to the Pi over I2C, but it seems it's not that simple. Many of the Picaxe chips can only be I2C masters, not slaves, so that's not going to work. Then I got quite confused trying to figure out the multiple PWM clocks on the 28X2. This being my first Picaxe project ever, I need to simplify.

Then I saw a few projects that used multiple smaller Picaxes to do discrete functions. I think I can handle that. So here is my plan:

  1. The Pi will still have the high-level logic for the robot.
  2. To control the motors, the Pi will send a simple command over plain serial to a primary 08M2.
  3. That primary 08M2 will in turn have simple serial connections to two more 08M2s -- one for each motor -- and will forward the command to the appropriate secondary 08M2.
  4. The secondary 08M2s will then each drive one half of an L293D. They'll send a high or low to the 1A and 2A (or 3A and 4A) pins, and a PWM signal to the 12EN (or 34EN) pin to control speed.

Questions: Will this work? Have I missed anything obvious?

I even wrote up some code. I have no idea if it will work, but I welcome comments.

Thanks!

And I did see Maxhirez’s post…

…about doing software PWM on the Pi:

https://www.robotshop.com/letsmakerobots/node/34774

Definitely a cool approach, but not quite what I’m looking for.

Whew! Found it!

I knew if I dug around long enough I would find this guy. Its an oldie but a goodie and it should get you started.

https://www.robotshop.com/letsmakerobots/node/3548

Thanks!

Yeah, that definitely helps. Seems like this might actually work, and with parts that cost less than my lunch!

Sounds a bit messy.

Sounds a bit over-complicated.  If you’ve got a 28x2, why not use the I2C (or hardware serial) on that and then use 2 of the 4 PWM channels?  With the PicAxe, you initialise the PWM channel with the PWMOUT command which sets the frequency, then control the duty-cycle with the PWMDUTY command to control the motor speed.  Below is a snippet of one of my programs (using a 28X2) doing this. The full code is here : https://www.robotshop.com/letsmakerobots/node/32434

 

’ Setup


symbol MLPWM = b.0
symbol MRA = b.3
symbol MRB = b.4
symbol MRPWM = b.5
symbol MLB = b.6
symbol MLA = b.7

low mla, mlb, mra, mrb
pwmout mlpwm, 20,0
pwmout mrpwm, 20,0

 

’ Control subroutine.

ContMotors: ’ 40=full ahead : 20=stop : 0=full reverse   

 tmpw1 = 0

 if lspd < 20 then
  low mla : high mlb
  tmpw1 = 20 - lspd * 4 min 20
 end if
 
 if lspd > 20 then
  high mla : low mlb
  tmpw1 = lspd - 20 * 4 min 20
 end if

 pwmduty mlpwm,tmpw1
 
 tmpw1 = 0

 if rspd < 20 then
  low mra : high mrb
  tmpw1 = 20 - rspd * 4 min 20
 end if
 
 if rspd > 20 then
  high mra : low mrb
  tmpw1 = rspd - 20 * 4 min 20
 end if

 pwmduty mrpwm,tmpw1

return

Hmm

Thanks, Andy. I don’t yet have the 28X2, so that was part of the problem figuring it out. Seems like you managed to get it to work pretty nicely that way, though. Great project!