senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

pi2go Use Sonar or Led

Mon May 29, 2017 7:38 pm

Hi everyone, and thanks for being there.
I'm relatively new to this community, and I'm putting my hands on a pi2Go (not lite) from 4tronix.
I've been able to program it with Python.

We (as teachers) have, as a project, to encourage the use of computer science and robots in primary schools in france (French west indies indeed).
That's why I'd like to use scratch on the pi2go and I've done a few things for now :
1. installed nuscratch.
2. make the bot advance using a few broadcast on the motors pins.
3. read the values of the IR sensors (it seems to be 0 or 1, as in python if my memory is correct)

So, a lot of good things for a beginning.
Now, the questions :

1. it seems that if you broadcast let's say "pin7on", the pin goes on but goes off just after (you have to repeat the message if you want it to stay high... Did I missed something ?)

2. I'd like to change the led colors and use the sonar on the pi2go.
it seems that the messages are broadcasted to a python daemon that does interact with the GPIO...
If it is the case, I'd have to modify the daemon.
2.1 Did anyone tried something like this ?
2.2 Does anyone know where this program is ?
2.3 Would anyone be interested in grouping our efforts to do that kind of stuff ?

Thanks in advance.
Dabix.

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Tue May 30, 2017 3:51 pm

Ok, I've been searching for a while, and understoods a few things for now. I'll put them here for any interested reader, and also as a proof of my efforts :D


1. Once upon a time was ScratchGPIO developped by Simon Walters (Thank you M. Walters). based on a python script that interacted with scratch... This is no longer the case...

2. When you install nuscratch, you have access to the GPIO. All the work is done by scratch. So where do you control all the pins configuration ? well. I now know that you can access to such things using the "System Browser".
What I'm looking for stands in the ScratchGPIO-Devices section.
So, as soon as I figure out how I can add some stuff in it, I might be able to add the LED controller in Scratch

Does it seems correct to you ? are there more easy ways to go ?

Sincerely,
Dabix

timrowledge
Posts: 1076
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: pi2go Use Sonar or Led

Tue May 30, 2017 9:30 pm

Simon's ScratchGPIO server is still out there and still useful. Some time ago I added 'native' support for a lot of gpio functionality to NuScratch and it is all there with no extra work needed by you.

There are number of examples of how to use the gpioserver provided. Open a new project and load one of the projects in the 'sensors and motors' folder. The simplest one is named something like ' gpio-basicDemo.sb' but there is also an example for using a typical ultrasonic sensor.

Generally when you turn on a gpio pin it will stay on unless perhaps there is some other program that alters it. The gpioserver most definitely does not randomly alter pins.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Wed May 31, 2017 12:58 pm

Thanks for the answer (and the work already done)

I've seen the examples and got my (humble) knowledge from there !

My troubles come from the fact that I don't control which pins are used by the pi2go robot.

For example :
1. Sonar : on the Pi2go, pin 8 is used for both trigger and echo. The python code change the pin from output to input
on the fly between the trigger and the reading of the echo. I think that I cannot do that in scratch with the code that is currently available.

2. RGB Leds : on the Pi2go, they are controlled by a pca9685. I cannot find any example of using it with nuscracth.

I'm perhaps misguided, but I think I need to develop a few things to make it work on the pi2go robot.
- I like the idea of nuscracth working out of the box but I have to find some documentation to add stuff to nuscratch and make it last for every robot I put in schools.
- ScratchGPIO server is probably the easy way to go for me since I'm not that bad with python and the pi2go is fully fonctionnal using python commands.
- I've also seen scratch client as an alternative (as I think it does also use a python script)

But my main problem is to define which of these alternative is the good one (in the long term).

Any help, link or advice is welcome.

timrowledge wrote:Simon's ScratchGPIO server is still out there and still useful. Some time ago I added 'native' support for a lot of gpio functionality to NuScratch and it is all there with no extra work needed by you.

There are number of examples of how to use the gpioserver provided. Open a new project and load one of the projects in the 'sensors and motors' folder. The simplest one is named something like ' gpio-basicDemo.sb' but there is also an example for using a typical ultrasonic sensor.

Generally when you turn on a gpio pin it will stay on unless perhaps there is some other program that alters it. The gpioserver most definitely does not randomly alter pins.

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

Re: pi2go Use Sonar or Led

Wed May 31, 2017 5:00 pm

Hello,
for scratchClient, there is no ready to use configuration available. Although I have adapters for some of the chips in pi2go there are still some missing. I ordered a copy of this vehicle and hopefully after next weekend there will be some progress.
One of the advantages of scratchClient is its flexibility to implement adapters and to combine them to solutions.
Regards,
Gerhard

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Wed May 31, 2017 5:21 pm

ghp wrote:Hello,
for scratchClient, there is no ready to use configuration available. Although I have adapters for some of the chips in pi2go there are still some missing. I ordered a copy of this vehicle and hopefully after next weekend there will be some progress.
One of the advantages of scratchClient is its flexibility to implement adapters and to combine them to solutions.
Regards,
Gerhard
Thanks. If I can help in anyway, please ask. I have some background in programming (not that much when it comes to hardware but I guess I can adapt...)

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

Re: pi2go Use Sonar or Led

Wed May 31, 2017 5:42 pm

In the schema for pi2go, there is a STM8S003F3P6 controller, do you know what his thing is doing ?

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Wed May 31, 2017 10:19 pm

ghp wrote:In the schema for pi2go, there is a STM8S003F3P6 controller, do you know what his thing is doing ?
No. I felt asleep looking at this schema trying to get the idea (now my wife refuse to believe me when I say I was working...)
I've only been able to guess it has something to do with the line following module.

The pi2go.py says that the physical pins 12 and 13 are used to get the line detectors input.
Those 2 pins are BCM 22 27 and from the pi2go schema they are linked to the SDA/SCL pins on your mysterious controller.
(These seems to be related to I2C protocol. Did I mentionned that I'm no hardware specialist ? :D)

Then TR1 and TR2 are linked to this component and to "TCRT5000" that are the "mirror detectors" used for line following.
This component is also linked to the leds close to these "TCRT5000" stuff via PB0 PB1.

I'd say that this component is used as a delegate for the Line detection and led control to avoid using to much pins on the Rpi,
but I cannot see why (2 pins are used at the end...)
BTW, I've not been able to find the other IR detectors on the schema (probably TR3 TR4 TR5) that are also linked to your mysterious controller.

Don't know if this is of any use.

Bix.

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

Re: pi2go Use Sonar or Led

Sat Jun 10, 2017 5:02 pm

Hello,
received a copy of pi2go today and have done some first coding today. Hope to have some results the nextdays.
Regards,
Gerhard

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 181
Joined: Fri Jan 06, 2012 7:46 pm

Re: pi2go Use Sonar or Led

Sun Jun 11, 2017 6:04 am

Simon is still actively developing ScratchGPIO, with new features being added all the time.

You can install the current version here: http://simplesi.net/scratchgpio/scratch ... rypi-gpio/

Simon is also very active on Twitter if you have any issues.

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

Re: pi2go Use Sonar or Led

Sun Jun 11, 2017 6:41 am

Hello,
had a busy time since yesterday and there is pi2go integration into scratchClient available.
The config file is config_pi2go.xml in the distribution.
One of the problems was to get i2c to run. The chips on the board have not been found by "i2cdetect -y 1". Had to disassemble the pi from the board and reassembled and then the contacts worked.
The LED work in pairs only; the pwm chip adapter was already available. For the light sensors there is a new adapter for the PCF8591. For the sonar sensor the python code is consuming much cpu, but did not have the time to develop a better solution. Here the combined pins ECHO and TRIGGER are making things difficult. The advantage of this solution is that it uses rpi.gpio and thus no other dependencies are needed.
When you start scratchClient with the config file, there is a browser page available localhost:8080 which displays the adapters and allows to low level monitor and simulate the board.
Regards,
Gerhard

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Mon Jun 12, 2017 1:26 pm

ghp wrote:Hello,
had a busy time since yesterday and there is pi2go integration into scratchClient available.
Gerhard
Great ! I'll try to look at your solution in the following days.
...one day after... (well, I'm updating it now...)

This is my config and this is where I am right now

- scratch and scratchClient are on the same raspberry pi (raspbian jessy lite with server X)
- scratch is 1.4 from the repository.
- I control scratch and scratchClient from a pc (ubuntu) using a terminal and ssh -X

I successfully installed ScratchClient on the pi, following this :

http://www.heppg.de/ikg/administration/ ... tion.steps
and after a few trials and errors, it seems to be close to work... I can :

Code: Select all

sudo python3 src/scratchClient.py -config config/config_pi2go.xml
I had this error :
WARNING - There was an error connecting to Scratch!
It took me a while to realise that I needed to "Enable remote sensor connections".
This can be done following https://wiki.scratch.mit.edu/wiki/Remot ... onnections

Now :
  1. I can act on the RGB led using the web app http://localhost:8080
  2. I can read in scratch the value of the distance sensor if I set it in the web app
This is fun, since 1 means that ScratchClient interact with the GPIO and 2. means that Scratch interact with scratchClient,
but the whole stuff does not work the way I would like it to...

oddly, but I must be doing some mistakes :
  1. I cannot act on the RGB led in scratch (for example, I set a variable called channel_0 and it doesn't change anything. I'm not sure that I'm broadcasting anything when I do that...)
  2. I cannot act on the motors (nor using scratch or the web app)
If you have any scratch samples using scratchClient or some documentation, I'll take them with pleasure,
since I've been reading many things but with a limited success.

senorBix

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Wed Jun 14, 2017 10:05 pm

senorBix wrote: If you have any scratch samples using scratchClient or some documentation, I'll take them with pleasure,
since I've been reading many things but with a limited success.

senorBix
I've seen an example using scratch2 and I'll try it tomorrow.
Scratch2 using flash would not be my first choice but any working solution will fit.

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

Re: pi2go Use Sonar or Led

Wed Jun 14, 2017 11:11 pm

Hello, the interaction between scratch and scratchClient is done by using variables and events. If you have a look to the pi2go-adapter in localhost:8080
Image then you control the leftmost variables,( there are no events for this adapters). So do not use "channel_0" but the corresponding scratch name "D11_D14_blue". Same for the motor, control 'speed_A' or 'speed_B'. Values for the PWM LED is [0..100], the motor uses [-100..100].
You control these by creating variables in scratch with exactly this name (upper, lower, underscore, no blanks), scope 'for all sprites'. My kids in school usually struggle with '-' or '_', upper and lowercase, blanks at the beginning or at the end, so simplest procedure is to copy paste the names from the adapter web page or the config file directly. When you change the variables in scratch, you should see them arriving in the web page. Start scratchClient with -guiRemote in addition to the other parameters, and you have the possiility to remotely connect a browser to your Pi.

You can change the scratch names in the adapter file. So if you do not like the "D11_D14_blue" which is just the chip names on the board, then change this in the config file to 'left_side_blue_led' or whatever you need. Do not change the adapter name 'channel_0' or the others on the middle row close to the boxes, as this is needed to route the signals to the python code.

For the sensor values (on the right of the adapter view), look for the '[ ] sensor value' block in the sensor palette. When a value is sent, then the names should be available there. The events, e.g. 'SEN1_HIGH' are arriving as broadcast events. Click them in the web view (short red flash should indicate the signal sent) and in scratch the 'when I receive[ ]'-hat will have the names in the pulldown. Of course same thing when the IR sensors toggle (they have LED associated when active, inactive driven by this processor on the board).
If you do not like broadcast events for the IR sensors, this can be changed to level signals 0,1 by using different adapters.
Hope this helps,
Gerhard

I have a beta for a scratch2 connection to scratchClient, but I would not recommend to use now as internal thread management is not yet completed.

For scratchClient, there is documentation in the scratchClient/doc folder or on my web page. For the pi2go, I do not yethave a scratch sample available.
The motors are disabled on the pi2go board if battery is low. There is a flashing LED D2 or D3 indicating this situation. I use a power supply here to work around bad batteries. This could be one reason for motor not working. Or one of the jumpers on the board are missing.

senorBix
Posts: 8
Joined: Mon May 29, 2017 7:14 pm

Re: pi2go Use Sonar or Led

Thu Jun 15, 2017 2:53 pm

ghp wrote:Do not use "channel_0" but the corresponding scratch name "D11_D14_blue".
I tried yesterday but it failed (don't know why).
Good news are : It now works.

Today,
  1. I downloaded again your scratchClient http://heppg.de/ikg/administration/pi/s ... ent.tar.gz (cause I was probably confused by the scratch2 version....)
  2. put brand new batteries in the pi2go
  3. redesigned the scratch program (see below)
And it works (RGB leds, motors and sonar)

I am able to use scratch on the pi2go or on a pc and both works ( which is a pretty nice feature)

If anyone has the same things to do, here is the scratch program, I'll update it from time to time.
http://calamar.univ-ag.fr/uag/ufrsen/co ... lientVP.sb

However, I now have this message from scratchClient :
adapter.gpio - WARNING - HCSR04: error code 2 (linked to the sonar, from what I read)
but the distance read is ok.

Thank you very much.
BTW, your architecture (xml adapters) is very nice to work with.

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

Re: pi2go Use Sonar or Led

Thu Jun 15, 2017 3:59 pm

adapter.gpio - WARNING - HCSR04: error code 2 (linked to the sonar, from what I read)
This is from the sonar adapter. The implementation is polling the input signals from the sonar, but from time to time the response time exceeds the 25ms range. Reason is most probably thread scheduling during a measuring cycle. These measurings are ignored.

EyJayDee
Posts: 1
Joined: Sun Jul 23, 2017 12:17 pm

Re: pi2go Use Sonar or Led

Sun Jul 23, 2017 2:17 pm

senorBix wrote:...Once upon a time was ScratchGPIO developped by Simon Walters (Thank you M. Walters). based on a python script that interacted with scratch... This is no longer the case...
Sincerely,
Dabix
How sad i am to read this. Ok, the next post does correct this, but at the end a new scratch interface for the pi2go is written, instead of using the existing one. And Simons interface works with several robots, not only with the pi2go! :)

You can get it here : http://simplesi.net/pi2go/

Featured are all sensors, servos and the pi-camera-module. So for example i use the servos to adjust the camera to take photos of the obstacles, the sensors recognize. So if the ultra sonic sensor recognises an obstacle, the servos turn the camera to the front, a photo is taken and the evasion process is started...

If you send me a pn i will send you the scrach example files with comments. On Simons Blog there are only pictures of his examples. My comments help to understand how Simons Interface works and where to look at.

We got little problems with the newest version of simons interface. On Simons pi2go everything works fine, on mine not. If you send me the pn, i will tell you exactly what is my problem. Beta testers needed!

KyysmaWen
Posts: 6
Joined: Mon May 15, 2017 12:57 pm
Location: Россия

pi2go Use Sonar or Led

Mon Aug 07, 2017 3:51 pm

I have a Lowel tungsten kit, and two cheap Chinese LED panels. Id like to get a better quality LED, perhaps bi-color. This would be for general use, interviews, narrative film. Id like to be able to dim with no change in color temperature, and a high CRI. Also, I need them to be bi-powered, both 120 v and battery. At least 500 leds per panel.

Recommendations? I have stands etc.

Return to “Scratch”

Who is online

Users browsing this forum: No registered users and 2 guests