PWM on S2P ?

Hello
I have been having a look at the scratch S2P programming.
Can anyone tell me whether or not it is possible to create a PWM output using this?
Also I was using a 40X2 pic and in the scratch IDE port pins D were not available in the list, anyone know why this might be ?
Thanks
 

edmunds

Senior Member
Hello
I have been having a look at the scratch S2P programming.
Can anyone tell me whether or not it is possible to create a PWM output using this?
Also I was using a 40X2 pic and in the scratch IDE port pins D were not available in the list, anyone know why this might be ?
Thanks
What does S2P stand for?
Do you mean Picaxe 40X2 or the same chip but bare pic? As in Microchip part PIC18(L)F2x/4xK22.
What do you mean by word "scratch"?


Edmunds
 

inglewoodpete

Senior Member
I had never heard of Scratch and S2P before. However, I noticed on this Rev-Ed page, there are a couple more unanswered questions.

Perhaps Technical can help here but we may have to wait until Monday morning in the UK.
 

grim_reaper

Senior Member
More like Tuesday morning, national holiday on Monday.
Probably Monday the 11th... I haven't seen a single person I recognise at work today because everyone takes this week off!!


Steve,

I've had a quick look at the version of S2P I've currently got installed, and all you seem to be able to do is switch outputs on/off, configure I2C and start/stop motors. As IWP said, I think this is one only Technical can answer.
It's been a while since I even looked at S2P, and my daughter (9) has lost interest in Scratch already (probably found something pink instead), so we didn't get as far as actually connecting hardware!
Note that the Scratch software seems to refer to all 'PICAXE extensions' as "experimental" ?!
 

hippy

Technical Support
Staff member
We will have to check on the 40X2 port D pins issue; what is there and whether anything has been accidentally left off or is not otherwise included for some reason.

As to PWM there is currently no support as such beyond using HIGH and LOW to toggle the output at slower speeds.
 
Thank you for all the replies
Hippy do you think that pwm may be availiable in the future?
I like the block method of programming as I dont have to worry too much about syntax errors and I can get done what I need to do quickly and easily.
I also use another similar block programmer for Arduino, called Ardublock , http://blog.ardublock.com/?s=scoop
It has all the functionality you could need, it can run multiple sketches at the same time, do serial coms, spi & i2c, pwm, interrupts ..... etc etc.
It would be nice if picaxe could do something similar :)
 

Technoman

Senior Member
Hi,

With other teachers, we gave a try to s2p and 12blocks (see Picaxe software), both based on Scratch. It was not successful in trying to run a simple program on an AXE 401. We faced some configuration and communication problems.
We tried also the very similar mBlock in an Arduino environment : it worked. Someone said that mBlock could be later (?) available for Picaxe.

The concept is interesting for education as it offers :
- two modes : in line and off line. You can get a program to move sprites on the pc's screen and communicate with a piece of hardware.
- similar blocks, whatever the hardware behind (Picaxe, Arduino, ...)
- easy to understand for kids (Scratch)
- a closer approach of real code structure (basic, C) than flowchart
 

Technical

Technical Support
Staff member
Thank you for all the replies
Hippy do you think that pwm may be availiable in the future?
The main aim within Scratch/S2P is that, because you have two separate modes of operation (real time connected to the computer and also remote run), any PICAXE commands that we 'officially' support in S2P must also be capable of fully working within both modes. This is because Scratch is generally used with younger students and inexperienced teachers who have very little electronics knowledge. Feedback to S2P has generally been extremely positive from the teachers who have been using it.

However it is not really designed for higher end complex projects, Scratch is an introductory programming system and the vast majority of the target audience will not be trying to use SPI etc..
For people who want to use 'block style' programming but with these more complex PICAXE commands a Blockly type environment is a far better fit than Scratch.

But for those users who want to do a few more complex things within Scratch they can also use the 'BASIC' block to type in any PICAXE command they choose. This will then be merged within the downloaded program (but ignored in real time connected mode).
 
Last edited:

stevesmythe

Senior Member
But for those users who want to do a few more complex things within Scratch they can also use the 'BASIC' block to type in any PICAXE command they choose. This will then be merged within the downloaded program (but ignored in real time connected mode).
How do you get the BASIC block in S2P? I've never seen it.
 

Technical

Technical Support
Staff member
You need the special .sb2 template that includes the 'BASIC' block. We'll upload it with the next S2P release which is due this week.
 

stevesmythe

Senior Member
Ooh,er! Just downloaded S2P v0.09. It looks good.

I don't see any documentation for the using new/revised blocks though. Do I enter each line of Basic in its own Basic block separately? I was expecting a multi-line dialogue box like in Logicator.
 

Technical

Technical Support
Staff member
Scratch itself does not have a multi-line box available to use.
So you can separate commands with a : on one line, or use multiple blocks.
 

stevesmythe

Senior Member
Another question or two for Technical (or anyone else who has used S2P)...

I have connected an SRF005 sensor to input C.2 on a CHI030 project board using single-pin mode with the three-pin header. This works fine using Picaxe Basic and gives me reasonably accurate distance readings in centimeters from 0 to about 300cm.

Now, instead of Picaxe Basic (and using the exact same setup), I run S2P and Scratch and choose "setup sensor C.2 as ultrasonic" in Scratch. This gives C.2 readings from around 10 up to a max of 255. The distances displayed in C.2 are around 5 times the correct distance in centimeters. I'm almost tempted to suggest that somebody forgot to divide by 5.8....

My questions are:
1. Why doesn't the C.2 value go below about 10 as I move an object right up close to the SRF005?
2. How can I convert the C.2 readings to a meaningful distance measurement?

Thanks
 
Last edited:

Technical

Technical Support
Staff member
Yes this is a setfreq bug in the connect file.

Open up this file
C:\Program Files (x86)\Revolution Education\S2P\connect\picaxe_connect.bas

and change the ultra section to read like this:

Code:
UltraCommand:


  SetFreq FREQ_DEFAULT
  Ultra w1, w2
  SetFreq FREQ
    
  SerTxd( "ULTRA" )
  Goto ShowPinPlusResult
If you then use S2P to redownload the connect program to the 18M2 it should work better.
 

stevesmythe

Senior Member
OK, so now I have another problem. My Scratch program runs fine in connected mode. I'm using SRF005 sensor on input C.2 When I try and run it in Remote mode, I get the error "Pin C.2 cannot be used for ultrasonic Output during PICAXE.setupSensor".

If I remove all the other blocks except the Green Flag block and the block "setup sensor C.2 as ultrasonic" I get this error. Doesn't seem to matter what pin I use either.
 

Technical

Technical Support
Staff member
Are you using the generic 18M2 template (or the CHI030 template (which only allows portC to be inputs))?
 

stevesmythe

Senior Member
I'm using the CHI035A template actually (I swapped boards since yesterday). I wasn't aware of that restriction, as it works OK in connected mode. I'm using two motors connected to a L293D motor driver. I'm going to add an IR receiver for remote control (not tested yet). Will it work if I just use the generic 18M2 template? What's the reason for the CHI035A template then?
 

Technical

Technical Support
Staff member
We'll look into this issue for you. The various templates only expose the pin numbers that are generally used for in / out on that particular board e.g. on a CHI035 portB would only generally be used as outputs so the B.X pins don't appear on the input commands within that template. The generic template allows everything.
 

stevesmythe

Senior Member
Sorry to be a pain but I'm in full testing mode!

I'm now using S2P with the AXE001 (or AXE020 - not sure what the difference is) 28 pin project board with a 28X2 processor and L293D motor driver inserted. Motors are connected to the extra pads next to the L293D socket. I'm using 2 power supplies. Using Program Editor I can turn motors A and B on. However in S2P connected mode, nothing happens if I use the green hat block and "turn motor A on" blocks.
 

Technical

Technical Support
Staff member
In S2P motors A and B correspond to output 0,1 2,3.
So C and D are outputs 4-7 as on the AXE020, so use motor C and D labels in S2P here.
 

stevesmythe

Senior Member
Thanks Technical. It makes sense now you've explained it, but I would never have thought of that! While I'm talking about it, what is the little two-pin pad at the far bottom right of the 28 pin project board (just below V2) that is marked "R"? It's not mentioned on the data sheet.
 

stevesmythe

Senior Member
Another little issue...

Having moved my S2P project from the 18M2 boards to the 28X2 project board, it ran fine in connected mode. When I tried to download the Scratch program to the Picaxe for Remote run mode, I got an error saying that the Scratch program was written for the 18M2 processor and it refused to download it (can't remember the exact wording). Even though the blocks I used were the same for both processors, I ended up having to re-write an identical program for the 28X2 so that it would download. It would be useful to be able to change the target processor somewhere (or override the error). I understand that S2P is trying to avoid downloading erroneous commands, but in this case there weren't any.
 

Technical

Technical Support
Staff member
The AXE020 R is for an external reset if you want it.

Because the blocks are predefined within Scratch files it is not possible to change the template after it has been defined and the file has been worked on. Therefore always select the correct template right at the start.
 
Top