[SOLVED] Joystick, RPI3, Grove and SCRATCH

Hello,

I’m a french teacher and I use Rpi3 with Grove Cards with my students.
I just bought a lot of Joystick like this :

http://wiki.seeed.cc/Grove-Thumb_Joystick/

I don’t find a tutorial to configure them with scratch…

So, like a button, i do :

Broadcast (join(analogread,0))

But I receive juste one value, the X value I think.
But I need Y value too.

On this Website, I see the python code. The two analog Pins A0 and A1 are used for that in the Grove Cards.
But how can I declare and catch this two values on Scratch ?

I tried
Broadcast (join(analogRead,0))
Broadcast (join(analogRead,1))

But the only value is analogRead…

Thanks for the help and excuse me for my bad english :wink:

Bonjour @johan.guillot

I took a bit of time to investigate and it seems I can get it to work with the following:
thumbstick

The thumbstick has to be in port A0 for this code to work. You may also play with the delay. It is needed but maybe it can be shorter.

I hope this helps your project et bon succès!

Cleo

Hi,

Thanks for the very quick response.
I’ll try tomorrow and I’ll tell you if that works.

Have a good day,

Johan

Hi,
It works fine for me. With one Joystick. It’s cool.
The problem is that I need two Joystick. I thought I could plug the second
one on the A2 port, but there will be a conflict with the analogRead
variable.
Is it possible to do that ?

Thanks a lot :wink:

Have a good day.

Johan

Hi @johan.guillot
You should be able to read the second joystick on AnalogRead2 and AnalogRead3.

Cleo

Hi,
The problem is the analogRead sensor value.
If the two joystick are pushed at the same time, there is just one value of
analogRead. So it’s the first which is written…

@johan.guillot
I only have one joystick with me so I cannot test a double joystick setup, but the values should be different.

Then how you handle reacting from those values is up to your Scratch code.

Thanks for the help
.
In fact, when the Grove Card (Port A0 and A1) receive the position of X or
Y of the first Joystick, Scratch put the value in the variable analogRead.
There is just one variable for both X or Y.
You resolve my problem with a little timer.

But if i use a second joystick (port A2 et A3), it will use exactly the
same analogRead variable to write the value of its X or Y.

So if I push up the two joystick in the same time (I do a game so it will
be possible), the analogRead variable will take the first value it will
have…

It’s a problem :slight_smile:

@johan.guillot
it’s the nature of this type of communications. Only one can be accessed at a time, so we have to fake simultaneous reads.

One way is to have a tight forever loop that does just the readings. Reactions to those readings are done outside of the loop. (note the mapping approach I used to match joystick readings to screen position is extremely crude)
joysticks
You can play with the delay value to make the loop as tight as you can. Don’t make it too tight as it will overwhelm the Scratch controller running in the background. 0.1 sec works, but you could try 0.05 sec too

1 Like

Hi,

It works and it works very well.

Un énorme merci for your serious help :wink:

2 Likes

Ya pas de quoi :slight_smile:

Et maintenant que les jeux commencent! :blush: