DukeOfTarporley
Posts: 18
Joined: Tue Aug 30, 2011 4:15 pm

Running Headless

Thu Nov 01, 2012 11:21 pm

Simon or Anyone else,

I am using Simon's Scratch GPIO bits and pieces for a project (They are much appreciated)
I wanted to use my Pi to set off fireworks at a display.

I have a relay board connected to the Pi that controls the current to fire some Talon Ignitors (google them to see them in action, thay are pretty cool but need a big current to set them off)

The code is very simple When input pin7 is set high start a firing sequence
Set pin11 high
wait 3 seconds
set pin12 high etc


I have built the circuit and it works with a head or with VNC were the program is kick started by clicking on the green flag and listening for pin7 to go hi by

when gren flag clicked
wait until pin7 > sensor value is > 0.9


does anyone now how to get around the green flag click start?

Ideally i want the PI to boot straight into x and launch my project an automatically listen. ( I have solved how to get the PI to launch Scratch GPIO at atart up).

also how can i see what messages Python GPIO is broadcasting?

thanks in advance

Ed
ps i know using a match would be easier!

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Running Headless

Fri Nov 02, 2012 1:08 am

Don't know how to auto click green flag on scratch start - I've asked over in the Scratch forums to see if anyone knows if its possible.

To run the handler manually you need to have the killsgh.sh script

Code: Select all

#!/bin/bash
sudo ps aux | grep 'python.*scratch_gpio_handler.py' | grep -v grep | awk '{print $2}' | xargs sudo kill -9
Save it somewhere and chmod +x it
Then you can open a ternainal seesion and run it to kill any scratch_handler running.

Then run normal Scratch (not the ScratchGPIO shortcut)
open a terminal session and do

Code: Select all

sudo python /home/pi/simplesi_scratch_handler/scratch_gpio_handler.py
and that will start running the handler and you should see some messages appearing about not being able to find a Scratch session
Then in Scratch, in the Sensing section, right click on the last block and enable remote sensing connections.
The handler should now connect and provide you with some info as to what is happening.
You can ctrl-c out of the handler and edit it and un-comment some of the print statements to get more info

regards
Simon
its late so prob lots of mistakes in the above :(
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

DukeOfTarporley
Posts: 18
Joined: Tue Aug 30, 2011 4:15 pm

Re: Running Headless

Fri Nov 02, 2012 4:27 pm

Thanks Simon,

I will have a play with the info you have provided.
The auto start info so it will listen for a input would be really useful.

DoT

tommitytom
Posts: 10
Joined: Thu Aug 23, 2012 6:06 pm

Re: Running Headless

Wed Nov 07, 2012 12:20 pm

Hey DukeOfTarporley, out of curiosity, which relay board are you using?

DukeOfTarporley
Posts: 18
Joined: Tue Aug 30, 2011 4:15 pm

Re: Running Headless

Wed Nov 07, 2012 2:09 pm

I bought this board from ebay

IACS 4 Channel Mini Relay Board 3V Arduino Shield IO

works fine. if you are relaying large loads check that it is rated correctly.

DoT

Ps project report coming soon!

tommitytom
Posts: 10
Joined: Thu Aug 23, 2012 6:06 pm

Re: Running Headless

Wed Nov 07, 2012 4:15 pm

Sweet! We're having a fireworks display at the weekend and I was thinking of triggering them with my Pi, nice to see someone else had the same idea :)

DukeOfTarporley
Posts: 18
Joined: Tue Aug 30, 2011 4:15 pm

Re: Running Headless

Thu Nov 08, 2012 1:31 am

Guys,

a quick report on this.

I manged to get the PI act as firing system to launch fireworks.
The PI ran headless with 5 push buttons connectted to the GPIO pins. 1 button was used to "arm" the system and 4 buttons to "fire" 4 relays. These turn ignited the Talon fuses clipped onto the fireworks.

In the field the Pi was powered by a 12V tractor battery using a car lighter phone charger.

THe key to running was getting scratch to launch at the start (Intructions can be found elsewhere on how to boot straight in Xwindow and launch an application on start up in this case the Scratch project.

HERE comes the interesting party for SCRATCH users

My Scratch GPIO setup is SimpleSi Scratch set up (thanks Simon)

My main problem was getting Scratch to auto start, running with a head I would click on the green flag but in this project all I had was a push button droping the voltage on Pin7 to 0V

The auto start is resolved by using the "When I recieve " block . In my case it was "When I recieve 'ARM' " this would when look to see if the firing signal pins voltages were zero or 1. IF the were zero the firing relay pin was set high.

The "when I recieve" block listened for BROADCASTed Messages, which can be generated by Scratch internally or SimpleSi python script. However in its original form SimpleSi python program presently only uses one type of message and for this purpose it is the wrong type

Message types are dealt with in the 4th post of this topic http://scratch.mit.edu/forums/viewtopic.php?id=9458

SimpleSi code concentrates on sending and recieving messages of this type
sensor-update <var-name_1> <new-value_1> ...


I hacked SimpleSi code to add

broadcast ARMED

when the armed push button was pushed and
broadcast unARMED

when it was released

On pushing pin7 ARMED was broadcast and Scratched recieved the ARMED message

I had issues with getting scratch to recieve certain <sting>s. Inthe end i opted for a string of a single word with no white space or quote marks. (I would of original like to have broadcast messges like PIN07 low or High but i could get no reaction from Scratch in this format but a single word worked)

My hack was very simple as time was limited. if you look at SimpleSi Python code and find the point that it prints the <Broadcast String>:
sensor-update <var-name_1> <new-value_1>

I add if the string is"sensor update" pin7 low then also broadcast the message ARMED.

Using this method you could truely run the PI headless and independently but responding to GPIO input to activate a program. No need to wireless or PuTTY in. starting a Pi robot navigating through a maze?

If you want to see the Pi at work
http://www.youtube.com/watch?v=O-YNkN-6usk
(Joke) This was not me!

last tip for now if you are running headless, tidy up the program before running it.. In developement I had a lot of variable dispayed on the stage. MAke sure to remove these beofer going headless else scratch runs slow.

Ed

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Running Headless

Thu Nov 08, 2012 3:25 pm

Great stuff!!!!
I'll look into adding in sending broadcasts to my code. :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

Return to “Scratch”