GCV
Posts: 2
Joined: Thu Jan 04, 2018 5:13 pm

Scratch2 Motor Control

Thu Jan 04, 2018 5:24 pm

I have Raspi3 with Scratch 2. I have setup motor control with L293D IC and it works through Python.
http://www.instructables.com/id/DC-Moto ... and-L293D/

Trying to get the same working through scratch using either of the following
1.Using new GPIO Blocks
set gpio X to {output highh/low/input} works

The motor spins forward and backward but I am not able to setup pulse width modulation

2. Using old style

broadcast gpioserveron
broadcast config2out
broadcast config3out
broadcast config4outputpwm
bradcastt gpio2on gpio3off gpio4pwm50

This is not working. Running command gpioserveron on command prompt gives command not found

Looking to create some kind of reusable blocks of code in scratch so that my 8 and 10 Yr old kids can safely experiment and play with this

saltydog
Posts: 35
Joined: Mon Dec 24, 2012 10:40 am

Re: Scratch2 Motor Control

Fri Jan 05, 2018 9:34 am

GPIO PWM is not included with scratch2.

See for adding: s2-pi Creating Scratch 2 Extensions On Your Raspberry Pi

Chris

GCV
Posts: 2
Joined: Thu Jan 04, 2018 5:13 pm

Re: Scratch2 Motor Control

Sun Jan 07, 2018 7:46 am

Thanks You Chris
I am not able to run s2pi


[email protected]:~ $ s2pi
Traceback (most recent call last):
File "/usr/local/bin/s2pi", line 7, in <module>
from s2_pi.s2_pi import run_server
File "/usr/local/lib/python3.5/dist-packages/s2_pi/s2_pi.py", line 29, in <module>
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
ImportError: No module named 'SimpleWebSocketServer

What libraries am I missing?

Alternatively is there a way to call python functions from scratch? So that I can mask the complexity of GPIO and have kids just play with scratch

ghp
Posts: 1170
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Scratch2 Motor Control

Sun Jan 07, 2018 10:36 am

Hello,
scratchClient is supporting scratch2 and allows to use prebuild python adapters for GPIO, PWM, Servo, ADC chips and a lot more.
See http://heppg.de/ikg/wordpress/?p=984 for some details.
Regards,
Gerhard

There is an adapter "adapter.gpio.GpioMotorPWM"; sample config is config/config_hbridge_motor.xml.
Last edited by ghp on Sun Jan 07, 2018 12:50 pm, edited 1 time in total.

saltydog
Posts: 35
Joined: Mon Dec 24, 2012 10:40 am

Re: Scratch2 Motor Control

Sun Jan 07, 2018 12:06 pm

Did you use pip or zip to install?
I just tried installing it and pip created issues with python paths that caused library errors.
Using the zip method worked without issues.

Just had a quick play and PWM worked OK.
Alternatively is there a way to call python functions from scratch
Never tried in scrartch2. Can't help sorry.

Chris

Return to “Scratch”

Who is online

Users browsing this forum: No registered users and 2 guests