Discuss Scratch

SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

I'm looking into the possibility of writing Scratch scripts (ScratchGPIO type ones) and converting them into standalone Arduino scripts.

My basic idea is to use Scratch on a Pi as a robot coding development tool using an Pi robot and then “compile” the Scratch script into standalone code to upload to a cheaper Arduino bot.

And then it can be a transition tool as well between block based and text based coding

But for starters - I though I'd try and save on the .sb/sb2 internal file conversion task

Simon
bobbybee
Scratcher
1000+ posts

Is there a .sb / .sb2 >> Text file convertor around?

Take a look at https://github.com/bobbybee/JITScratch

It generates JavaScript code, but it doesn't pay attention to threading so it's very light weight. You could probably make an Arduino version without changing too much.

“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

Thanks for that

Just battling with npm trying to install it !!!

Simon
nXIII
Scratcher
1000+ posts

Is there a .sb / .sb2 >> Text file convertor around?

If you shift+click the File menu, you can save a project summary (a text-based version of the project). But you'll have a much harder time parsing that than parsing the actual .sb2 file format—it's just a zipped directory with assets and the project data in a JSON file. See the wiki for more documentation on the file format.

EDIT: There's also kurt, which abstracts away the differences between the .sb and .sb2 file formats.

Last edited by nXIII (Jan. 19, 2015 19:13:31)


nXIII · GitHub
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

Thanks At least I know I can experiment without having to decode an .sb file

So I created a simple sb file to blink pin13 on an arduino and uploaded it to Scratch site
and extracting from .json file I got
[["whenGreenFlag"],
["doForever",
[["broadcast:", "Pin13On"], ["wait:elapsed:from:", 1], ["broadcast:", "Pin13Off"], ["wait:elapsed:from:", 1]]]]]],

and using the project summary I can get

when @ clicked
forever
broadcast [Pin13On v]
wait (1) secs
broadcast [Pin13Off v]
wait (1) secs
end
I think to start with (and just as proof of concept) I can easily convert the project summary on a line by line basis to produce the arduino euivalent whic should be
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
MathWizz
Scratcher
100+ posts

Is there a .sb / .sb2 >> Text file convertor around?

The thing about the .json file is that there are already JSON parser written in just about every language ever so it would be really easy to parse. You would have to write your own parser from scratch to be able to parse the summary, however.

running Chromium 42.0.2311.90 with Flash Player 15.0.0.189 on Arch Linux 3.19.5-1-ck
MathWizzJsScratch && sb.js & Amber (coming soon! maybe)
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

I know what you mean but I'm only need to be able to parse a subset/mod of Scratch that is controlling an Arduino and my brain finds it easier to parse English

I've got this far today
https://github.com/cymplecy/ScratchArduinoParser

This is all based around my ScratchGPIO stuff for the Pi and my ScA version for Arduino.

Just want ability to prototype with say and Arduino robot plugged in via USB to a PC - then when satisfied - be able to upload native Arduino code to the robot.

Like Ardublocks but using Scratch as IDE

Simon
bobbybee
Scratcher
1000+ posts

Is there a .sb / .sb2 >> Text file convertor around?

SimpleScratch wrote:

my brain finds it easier to parse English

English is pretty grossly structured.

“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

True- but luckily I've been practising it for 55 years so I'm quite good at it now - can't spull though yet

blob8108
Scratcher
1000+ posts

Is there a .sb / .sb2 >> Text file convertor around?

nXIII wrote:

There's also kurt, which abstracts away the differences between the .sb and .sb2 file formats.
There was a project called ScratchNXC which used Kurt to read .sb files and convert them to C code for the Mindstorms NXT.

tosh · slowly becoming a grown-up adult and very confused about it
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

That ScratchNXC seems to have disappeared

The project summary (or the json) outputs are fine for my proof of concept testing.

If it ever comes close to being useful then that'll be the time to come back and try to directly parse 1.4 to Arduino
SimpleScratch
Scratcher
500+ posts

Is there a .sb / .sb2 >> Text file convertor around?

Well mBlock has basically got it wrapped up for Scratch 2 -> Arduino on PC/Max so no need to spend time on this one any more

http://mblock.cc/

Powered by DjangoBB