footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Explorer HAT and Scratch

Wed Jul 05, 2017 9:08 pm

I am trying to develop some plans for my primary school code club to use the Explorer HAT Pro with Scratch. At this point I am using the Scratch 1.4 as installed with Raspbian Jessie, as this has support for this HAT ( https://www.raspberrypi.org/documentati ... /README.md ).

I can get all the LEDs, motors and outputs working with broadcast messages (once I turn on the GPIO server). However using the alternative method setting variables, I can only get the LEDs & motors working, plus I can read the digital inputs (I have not tried the analogue inputs yet). I cannot get the outputs to work using variables. I have tried defining variables output1, output2, output3, output4 and setting them to 1, on, & high. None of these turns on the output (they work fine when I broadcast 'output1on' or if I broadcast 'join output1 on', but I cannot get the output1 variable to work. I wanted to use variables as it leads on to other coding principles where as broadcast messages is a bit more cryptic.

I have searched online for examples, but apart from the link above I cannot find any trace of anyone using the Raspbian Scratch distribution with variables to set the Explorer HAT Pro outputs. In fact I cannot find anyone using the Explorer HAT Pro with scratch who has posted anything at all, apart from the information about Scratch GPIO ( http://simplesi.net/scratchgpio/scratch ... rypi-gpio/ ), but I was trying to see if I could get a vanilla install of Scratch working before I install that.

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

Re: Explorer HAT and Scratch

Sun Jul 09, 2017 1:30 pm

Hello,
tried to reproduce this and using variables to control the outputs on explorer hat doesn't work here too.

I maintain scratchClient and so far there was no full support for explorer hat pro. I added support for the capacitive pads, adjusted the ADC code and there is a sample config file now included for explorerhat_pro.
Till now, there is only event support for setting outputs. You can change the event names to the names you need.
Regards,
Gerhard

footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Re: Explorer HAT and Scratch

Mon Jul 10, 2017 10:34 am

Hi Gerhard,

How do I find this updated code? Is it in the Raspbian distrib if I do an apt-get update?

Regards,
Paul

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

Re: Explorer HAT and Scratch

Mon Jul 10, 2017 4:12 pm

Hello,
scratchClient can be downloaded from http://heppg.de/ikg/wordpress/?page_id=6
Be sure you have enabled I2C in raspi-config.

Follow the install instructions from the web page (should take less than 5 mins) and then
cd ~/scratchClient
python3 src/scratchClient.py -c explorerhat_pro

For instructions on how to configure scratch, see http://localhost:8080/usage14

Regards,
Gerhard


scratchClient is a python framework which communicates with scratch1.4 by the 'remote sensor protocol'. Scratch2 connection is available with 'extensions'. The framework provides adapters for GPIO, adc, sensors, os-system commands and a few more. There are xml configuration files defining which adapters to be used. The tool was originally designed for a school class where predefined configurations have been needed.

footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Re: Explorer HAT and Scratch

Tue Jul 11, 2017 1:26 pm

What a great project Gerhard. Thank you for the links. I have added it to my growing collection of information on ways to use Scratch with the Explorer HAT Pro, that I have published on my blog https://adventures-with-pi.blogspot.co. ... -with.html

I have a lot of reading to do now to get up to speed on how to use ScratchClient with Scratch 2 so I can improve my code club template for children ages 9-12 for my code club. I'll update that blog article as I learn. But I welcome feedback now or any time if the information there is incomplete or anything is not correct.

footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Re: Explorer HAT and Scratch

Sun Jul 16, 2017 8:54 pm

Hi Gerhard,

Tonight I was playing with the HCSR04 distance measuring device and scratchClient. I could not get Scratch2 to pick up a time value, but the python3 output was showing times. A load of debugging later I realised that the measure method was not triggering a callback to calculate the time until the trigger pin was set low again. So it always raised an exception and then python displayed the time but did not return it to Scratch. The line which cause python to run the callback function and determine the time was:
self.pi.write ( self.trigger, 0)
But this was not called until the condition where the exception was raised as cnt == 5. By calling this line when cnt == 5 but only raising the exception if it reached a higher value of cnt (I used 25, but it never got above 5 actually), I could get Scratch to be sent the value.

I hope that makes sense. I can send you my updated pigpiod.py file if that helps.

Footleg

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

Re: Explorer HAT and Scratch

Mon Jul 17, 2017 8:37 am

Hello,
fixed this HC-SR04 problem.
Some other changes are:
- For consistency reasons, there is also a change in adapter naming.
- As I focus on thread handling since the changes for the scratch2 connections, an issue with thread stopping in the pigpiod connection is also corrected.

In the config file, change adapter.pigpiod.HC_SR04_Adapter to adapter.pigpiodAdapter.HC_SR04_Adapter.
If you use the default file from the distribution: there it is already changed.

When you download new version, check with -version
scratchClient 2017-07-17

Regards,
Gerhard

footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Re: Explorer HAT and Scratch

Mon Jul 17, 2017 1:03 pm

Thank you, I see the updated code in the pigpiod adapter, which makes sense based on my experiments last night.

I am planning on creating a config which combines this adapter with those in the Explorer HAT Pro config as I managed to get the HC-SR04 working plugged in the Explorer HAT Pro yesterday. (I just need to disable Input1 in the config as it is used by the HC-SR04 echo and it works fine). I'll share my project for building an obstacle sensing robot using this combination when I have written it up for my code club.

My next task is to try and write an adapter for scratchClient to read inputs from a 6-axis PS3 bluetooth gaming controller (so let me know if this is something you already have done work on).

Footleg

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

Re: Explorer HAT and Scratch

Mon Jul 17, 2017 7:04 pm

I am planning on creating a config which combines this adapter with those in the Explorer HAT Pro config as I managed to get the HC-SR04 working plugged in the Explorer HAT Pro yesterday. (I just need to disable Input1 in the config as it is used by the HC-SR04 echo and it works fine)
It is one of the basic ideas in scratchClient to combine adapters as needed, without the need to re-program python code.

footleg
Posts: 8
Joined: Sun Nov 27, 2016 5:05 pm

Re: Explorer HAT and Scratch

Tue Jul 18, 2017 2:31 pm

Yes, I put together a config which combined the adapters I needed and removed the Input1 block from Scratch in around 5 minutes last night, and got the ExplorerHAT working with the HC-SR04 sensor attached. https://twitter.com/drfootleg/status/88 ... 57504?s=04

Next I was going to look into the Python to implement an adapter for the 6-Axis PS3 controller.

Return to “Scratch”

Who is online

Users browsing this forum: No registered users and 4 guests