Using Grove sensors with Scratch on GoPiGo


I recently bought the GoPiGo and have done the basic set up and tinkered around. Example progams are running perfectly.

However, I am a newbie and am at a loss regarding how to use various GrovePi sensors I have (ultrasonic, line follower, light, sound, temperature etc.) to program in Scratch.

I do not know what VALUES I need to put in the Scratch broadcast() function to get this done.

Just like the example programs use LEDL, LEDR, FORWARD, BACKWARD, LEFT, RIGHT etc. within the broadcast() functions, what other strings are understood by Scratch on GoPiGo for some of these other sensors? Is there a compehensive list?

Are these broadcast strings already built into Scratch, or do I need to initialize something using Python as well?

And are there example programs with these other sensors that I can view and quickly get up to speed?

Sorry for the multiple questions, but I feel I am stuck and not getting anywhere given the lack of material online. Would greatly appreciate some quick help!


There are example programs in this directory: GoPiGo/Software/Scratch at master · DexterInd/GoPiGo · GitHub

In fact, if you go to this location (GoPiGo/Software/Scratch at master · DexterInd/GoPiGo · GitHub) you’ll see all the commands broken out in graphical form (scroll to the bottom). There’s a picture of them there as well.

I went ahead and modified the title of your post; all caps comes across as a little hysterical; I read your question as sincere and curious.

All of this look amazingly helpful John! And agree with you on the CAPS :slight_smile:

I think worried_guy also very helpfully responded on a separate post on my questions. So thanks upfront to both of you for the super-quick replies.

2 follow on questions from my side:

  1. What would the example progam for a line sensor look like? I didn’t see a graphical example of that in the link you shared. Also, can I use a GrovePi Line Finder (the blue one) instead of the Dexter line sensor (the red one)? I am asuming even the GrovePi Line Finder has to be connected to the i2c port of the GPG?

  2. I went through the program as well to understand the key boadcast() functions/messages. I got most of it and checked with the link you shared. But curious to know what messages to use when I want to use a new sensor, say a temperatue sensor, or a humidity sensor, or a fire sensor etc. I didn’t see those covered in the python progam. Is thee some kind of addition we need to do in the program itself?

  3. For some reason, my GoPiGo had a total breakdown yesterday and I just can’t get it to work properly any more.
    Just before that, I had successfully witten a simple distance finder program using the ultrasonic sensor, and tested it - the car would travel to a model “parking lot” and stop 1 cm away. However, then I tried to switch the power source - from the high-amperage phone charger I’d been using thus far, to the battery pack in the set. Immediately, a few things happened:

(a) My computer lost the SSH wireless connection I’d set up with the GPG. I could no longer connect to VNC through a browser using http://dex.local, even though I could ping dex.local successfully from my cmd prompt. Basically, the page opens up once in 5 tries, and even then when I click on the ‘VNC’ link on the left side of teh page, instead of opening up to the password prompt at the top middle, it hangs by showing a message like “initiating VNC handshake”. So I went ahead and downloaded VNC Viewer, connected the GPG to the laptop using a LAN cord, and tried again. Here too I couldn’t get 100% success but could connect only 1 in 3 times. The seamless, wireless, bowse-based connection I experienced over the prior 1 week is completely gone!

(b) Scratch has completely stopped working on the GPG. None of the progams, including the pre-installed example programs, work any more. However, I am able to get at least the basic_test_all Python program to work. But the whole point of getting the GPG was to continue my son’s Scatch education by interfacing it with the physical wold, and all the programs we had written and tested so far ae unusable right now. By the way, I disable and e-enable the remote sensors whenever I open a program in Scratch.

© My Ultrasonic sensor (a GrovePi one) started getting SUPER HOT (apologies for the CAPS here) at around the same time. It was not in use because the Scratch programs using it stopped working, as I mentioned above. It started becoming so hot that my son and I almost got scalded whenever we tried to touch it. Is it a problem with the sensor itself or something bigger that is going wong here? (By the way, I have a basic SR-04 ultasonic sensor as well, but they have these 4 protruding pins instead of the neat GrovePi socket, and I do not know wich wire to use to connect these to the GPG A1 port - perhaps you could guide me?)

Sorry for a really long post, but I am completely lost as to why petty much everything went south without warning. Pls help reverse this and if posible help me understand the cause so I can avoid it in the future. I know I asked a whole bunch of questions - would tremednously appreciate if you could spare the time to clarify and educate.

Thanks and cheers! :slight_smile:

Hello Arjun,

Regarding Line Finders: We’re working on code for that in Scratch right now. I still have to test it out a bit, but I am working on it. The blue line finders from Seeed are not very sophisticated and don’t work very well, we aren’t supporting them with the GoPiGo.

  1. Yes, you can add sensors using that python program and possibly, depending on the sensor, a few additional support programs. However, I would suggest that if you’re trying to use exotic sensors that aren’t covered in Scratch, it might be time for an upgrade to Python. In Python you’ll have much more direct control of the code and the sensors than you will in Scratch. We are purposefully keeping our support of sensors in Scratch limited to the basics that most Scratch users would be interested in.

  2. I have a few suggestions:

a). I would remove the Ultrasonic sensor. We have had at least one other report of it getting hot (not hot enough to scald, that’s really concerning!). Can you tell us more about where you purchased the US sensor and when?

b). The problems you describe in connecting sound like you’re having low battery issues. If you’re disconnecting the Pi power source and running on batteries, and suddenly having connection issues, this is often because of low power. Network connections on the Pi are often the first to go. How are you powering it and is it possible to try again with fresh AA batteries?

c). It sounds like you’re running some old software. What version of Raspbian for Robots are you running?

Again, sorry for the setbacks on this!