Could I program a Picaxe robot in Scratch
Picaxe Forum
Picaxe Website
Offline
No. I assume you're talking about a robot run by a picaxe microcontroller from revolution educations ltd.
Picaxe basic (the langauge you program the chips in) is really easy to learn anyway.
here are some examples I've thrown together for you.
you'll need this command so your robot can detect changes in it's environment (such as a contact switch closing)
if pin0 = 1 then goto contact_script
this states that if the contact switch at input 1 of your chip is high (connected) the script will jump to the header "contact_script:) Remember to couple the switch with a resistor like this:
+ _________________________________________
| _______
| | |
s1 | chip |
|_________| |
| |______|
r1
|
- ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
you'll also want a pause command to stop it reading connection bounces (where the contacts of the switch bounce a few times, connecting and reconnecting the switch a few times) (if you want to count the collisions) or for waiting between movements. so...
iftouching: (header name) if pin0 = 1 then goto touching goto iftouching touching: pause 100
the number after pause is in milliseconds, to use seconds, use the "wait" command instead (I think that is limited to 50 something seconds though that may have changed now)
then you'r going to need a way of moving the motors. You can use a H bridge driver and 4 outputs to get forwards and backwards rotation for two motors, though I think some chips come with a "forward" and "backward" command you can use instead of buying a H driver chip (I also recommend having smoothing capacators over the legs of both your motors, this reduces electrical noise and gives smoother starting and stopping
). Assuming you've just (for simplicity) got two outputs connected to two motors, you're needing the high command and low command to stop and start your robot's wheels.
waiting: high 0 high 1 if pin0 = 1 then goto triggered goto waiting triggered: pause 100 low 0 low 1 if pin0 = 0 then goto waiting goto triggered
that code will move your robot forward until it hits something, then it will wait until that thing has moved before continuing. (with multi-directional motors you could now add directions to get it to reverse and turn from the offending object.
so you've got a simple sensor and some wheels. those commands are all you should need for a simple bumper switch robot. If you want to use i2C, utrasonics or infra-red collision detection it gets a little more complicated. There's a full guide with the programming software which you can get free at the picaxe website (just google picaxe)
hope that helps
Last edited by sparks (2010-10-05 17:10:09)
Offline
The picaxe website link is in my original post. Could I modify the project summary feature to export as Picaxe Basic?
Offline
I really doubt it, they're so different. I've used Panther to write picaxe code though. You just need to make blocks to write the correct lines to a .bas file.
example:
the "high $Number$" block
writeText: 'high ', t1 asString, ' ' toFile: output.bas
(I think)
basically, this way you can use the file writing feature to get blocks to write their contents to the file. you can still have reporters, but you need them to report their entirety, not the result of a calcuation. E.g, 4 + 5 in a block shouldn't report 9, it should report 4 + 5 so that it is written to the bas file properly
Offline
So how would I make a simple robot then?
Offline
the hardware or software?
Hardware:
you can buy self-assembly kits from picaxe that will do the trick. If you want to make one yourself, you'll want to get an experiment board to hold your pic chip, also sold at picaxe, then you're looking at a lightweight base such as acrylic or a lightweight wood such as balser wood.(the wood will be cheaper). Get yourself some geared motors with 3-5V or so running voltage, and fixture holes so that you can drill and screw to the chassis. Wheels as well. You can find all these parts in stores (if you're in america, radioshack is good, if you're in england, try maplins or do an online search and buy it online. Some leaf switches mounted to the front will give you good bumper sensors for your robot to detect collisions.
Offline
I was on about the hard ware, so how do I connect the motor to the chip?
Offline
Motors will usually require more electricity than the output pin of a picaxe supplies, so it's conventional to use a transistor to switch the motor on and off. However, as you want your motors to be able to turn in both directions, you want an H-bridge, which is a special combination of transistors. You can ususally get those packed into a chip, much more reliable than all those components, it costs around £3 and lets you choose the direction of two motors. The chip is called "L293 D" (I THINK) and you find it all over the place, again, maplins sells this.
^ something like that
Last edited by sparks (2010-10-09 12:17:06)
Offline
Ok, but where would you put the power, directly to Picaxe or to the motors?
Sorry I'm sort of a electricity n00b, they dont teach us anything like this at school.
Offline
That's ok, I taught myself. You need power to the picaxe AND the the other chip, the other chip then diverts power to the motors. Both chips should have positive and negative pins on them, just attatch those to the power (remember to use a resistor if your power supply is greater then the spec voltage.)
Offline
ok, I may get started in the next few weeks! I am intrested as I was wondering if I could make a mod of Scratch to control a robot? Would this work, if not I dont care I will still make it!
Offline
Oh and if both chips are the same voltage then could I hook up 1 power supply to them?
Offline

Is that correct?
(I am in the UK)
Will this picaxe do?
Will this L293D do?
Can I use this and this together?
Is there anything else I need?
Last edited by johnnydean1 (2010-10-10 11:21:14)
Offline
You've put the two chips in series, not parallel, (have them connected seperately to the same battery without the electricity's path going through both chips to complete a loop like you have there) otherwise yes, that block diagram is good
Offline

there, that should be good
I need to check that the other chip is indeed the one you need, I might have got it mixed up, so I will tell you as soon as I find out
yes, you can probably make a scratch mod to code the picaxe for you, but trust me, it's easier to learn picaxe basic
The chip you linked to above is the 08M, and for some reason, you've got a 6 pack there... I think you might run out of pins there, you need four for the motors and that leaves you with only one for sensing. My fave chip for robots has to be the Picaxe 18X which gives you 5 inputs and 9 outputs. It's also got more memory (lines of code) some 2000 I think
Offline
Ok
If I make the diagram like the other can you check it?
Offline
So how would I attach a battery? And a usb transfer thing?
Offline
sparks wrote:
That's ok, I taught myself.
So did I. I like electronics. It's logical, like programming.
Offline
The battery, you just directly attatch is as shown, use a battery box. (unless the voltage is too high for the specification of either chip, then put a resistor between that chip and it's positive or negative connector. USB transfer "thing" is a USB to 3.5mm jack plug. You simply need to connect the jack socket and three resistors to the "serout" and "serin" pins of the picaxe. There's a diagram in the datasheet that's on the page with the chip I linked earlier.
Offline
ok
can you make a pic of what it should look like?
Offline
no, the diagrams are all on the site, you can find it there and I want to go to sleep
I don't want to do the whole project for you, post up what you think it should look like and I'll help you from there.
Offline
Ok. I can do most myself I just want to see how it would be. Can you link me to the site with the diagrams.
Offline