This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-10-05 15:04:52

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Picaxe Robot- Scratch

Could I program a Picaxe robot in Scratch

Picaxe Forum
Picaxe Website


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2010-10-05 17:06:31

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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)

Code:

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...

Code:

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  smile  ). 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.

Code:

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  smile

Last edited by sparks (2010-10-05 17:10:09)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#3 2010-10-06 03:16:56

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

The picaxe website link is in my original post. Could I modify the project summary feature to export as Picaxe Basic?


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2010-10-06 04:42:50

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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

Code:

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  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2010-10-08 12:37:23

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

So how would I make a simple robot then?


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2010-10-08 13:38:47

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#7 2010-10-09 04:25:24

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

I was on about the hard ware, so how do I connect the motor to the chip?


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2010-10-09 12:13:07

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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.

http://dl.dropbox.com/u/6273449/diagram.bmp

^ something like that  smile

Last edited by sparks (2010-10-09 12:17:06)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2010-10-09 16:32:51

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#10 2010-10-09 16:58:26

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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.)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#11 2010-10-09 17:03:58

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

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!


You can now reach me on Twitter @johnnydean1_

Offline

 

#12 2010-10-09 17:05:02

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

Oh and if both chips are the same voltage then could I hook up 1 power supply to them?


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2010-10-10 10:31:57

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

http://img294.imageshack.us/img294/6004/robotq.png

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)


You can now reach me on Twitter @johnnydean1_

Offline

 

#14 2010-10-10 12:18:34

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#15 2010-10-10 12:19:25

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

Can you fix my diagram?


You can now reach me on Twitter @johnnydean1_

Offline

 

#16 2010-10-10 12:34:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

http://dl.dropbox.com/u/6273449/diagram%202.bmp

there, that should be good  smile  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  smile

yes, you can probably make a scratch mod to code the picaxe for you, but trust me, it's easier to learn picaxe basic  smile

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  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#17 2010-10-10 12:35:48

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

Ok  smile  If I make the diagram like the other can you check it?


You can now reach me on Twitter @johnnydean1_

Offline

 

#18 2010-10-10 12:45:06

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

http://img169.imageshack.us/img169/1546/circuity.png


You can now reach me on Twitter @johnnydean1_

Offline

 

#19 2010-10-10 12:51:48

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

looks perfect!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#20 2010-10-10 12:57:59

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

So how would I attach a battery? And a usb transfer thing?


You can now reach me on Twitter @johnnydean1_

Offline

 

#21 2010-10-10 15:09:14

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Picaxe Robot- Scratch

sparks wrote:

That's ok, I taught myself.

So did I. I like electronics. It's logical, like programming.


/* No comment */

Offline

 

#22 2010-10-10 15:59:15

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

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.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#23 2010-10-10 16:05:21

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

ok  smile  can you make a pic of what it should look like?


You can now reach me on Twitter @johnnydean1_

Offline

 

#24 2010-10-10 17:31:02

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Picaxe Robot- Scratch

no, the diagrams are all on the site, you can find it there and I want to go to sleep  tongue

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.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#25 2010-10-11 11:09:45

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Picaxe Robot- Scratch

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer