Tutorial: Grove Connector Project Examples for Raspberry Pi / Arduino

At SwitchDoc Labs, we have been building prototypes for engineering projects for many years. Sometimes they move to being a product, sometimes not. We have been on the lookout for a good pluggable prototyping system that allows swap outs of parts and yet has a good mechanical interface. We have looked at a variety of systems over the years. What did we want? We wanted something that is supported by a number of manufacturers, no licensing fees involved, easy for beginners and younger folks to use, straight forward enough so we can build boards without much problem and flexible enough for use with all three of the Raspberry Pi, Arduino and the ESP8266. We have now found such a system that has some significant support in the industry.

Figure-1-1

All of the parts in this tutorial are available from www.seeedstudio.com or www.robotmesh.com.

This is Part 2 of this series. Part 1 describes the whole Grove connector system.

Part 3 will describe a more complex Grove application using the new Dual Grove/Pin Headers I2C 4 Channel Mux.

What is the Grove System?

FullSizeRender-10-1

Grove is a modular, standardized connecter prototyping system. Grove takes a building block approach to assembling electronics. Compared to the jumper or solder based system, it is easier to connect, experiment and build and simplifies the learning system, but not to the point where it becomes dumbed down. Some of the other prototype systems out there takes the level down to building blocks. Good stuff to be learned that way, but the Grove system allows you to build real systems. It requires some learning and expertise to hook things up.

The Grove system consists of a base unit and various modules with standardized connectors.

The Base unit, generally a microprocessor, allows for easy connection of any input or output from the Grove modules. and every Grove module typically addresses a single function, such as a simple button or a more complex heart rate sensor.

You don’t need a Base unit to connect up to Grove modules. You an use a cable (Grove to Pin Header Converter) to run from the pins on the Raspberry Pi or Arduino to the Grove connectors. That is what We do in the SunRover project and in the examples below.

So what is a Grove Connector?

Figure-2

Figure 2A Grove connector is a four pin standardized size connector used to plug into base units and Grove modules. Figure 1 shows the male Grove Connector. The male connectors come in flat 90 degree versions and vertical versions as in Figure 2. Seeedstudio has the exact dimensions in this specification [ http://www.seeedstudio.com/wiki/images/6/69/3470130P1.pdf]. These standardized connectors (common to all types of Grove Connectors) are the key to making this system work. They are keyed to prevent plugging them in backwards, and the four types of connectors (see below) are all designed so that if you plug the wrong type of device into the wrong type of base unit, there is no problem. They just won’t work. This is a good thing.

The one exception would be if you plugged in a 3.3V I2C Grove module that is non-5V tolerant into a 5V I2C Grove connector you could fry the device.

In this post we discuss four simple grove projects.

Project 1: Connection a Grove Fan to the Raspberry Pi

We chose three simple, yet visually interesting Grove projects. The first module is the Grove Fan module. It is a Digital Grove module. The wiring was simple. I connected GPIO17 to D0 and 5V and GNDFigure 6 using a jumper to Grove To Pin Header Converter connector cable (always have these handy!). The software was very simple.

Figure-6

#
#
# Test the Grove Fan
#
# Digital Grove Connector
#
# Gnd, 5V, GPIO4, GPIO17
# Grove
# Gnd VCC D1 D0
#

import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

try:
while (1):

GPIO.output(17, GPIO.HIGH)
time.sleep(2.0)
GPIO.output(17, GPIO.LOW)
time.sleep(2.0)
except KeyboardInterrupt:
# here you put any code you want to run before the program
# exits when you press CTRL+C
print “keyboard Interrupt”

except:

print “other error”

finally:
GPIO.cleanup() # this ensures a clean exit

<a href=”http://www.switchdoc.com/wp-content/uploads/2016/02/Figure-11.jpg” rel=”attachment wp-att-3352″><img class=”aligncenter size-large wp-image-3352″ src=”http://www.switchdoc.com/wp-content/uploads/2016/02/Figure-11-1024×768.jpg” alt=”Figure 11″ width=”930″ height=”698″ /></a>

 

The only tricky part of this is that we use the Try / Except block to make sure that the GPIOs are tuned off (actually floating) when our program exits. Otherwise a bug in your code could leave the fan running.

Of course, here is the video:

Project 2: Connecting an Grove Electroluminescent cable to the Raspberry Pi

Figure-12-1

The second example is powering an EL (Electro Luminescent) cable using the Grove Digital EL Control. This is a Digital Grove Module. We wanted to use the software PWM (Pulse Width Modulation) toFigure 12 brighten and darken the EL to illustrate a point about the Raspberry Pi. The Raspberry Pi is running a complex multitasking operating system (called Linux) and because of that the software timing for each of the pulses may be delayed by other important things happening inside the operating system. Therefore, you will see it flicker a bit, and differently each time. Using an Arduino or the Hardware PWM would produce a much smoother signal. When you are operating servo motors with software PWM, you will see the same thing in a shaking, almost a jitter, of the servo motor.

#
#
# Test the Grove EL Interface
# Digital Grove Connector
#
# Gnd, 5V, GPIO4, GPIO17
# Grove
# Gnd VCC A4 A5
#
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

try:
while (1):
# now do PWM on the line
p = GPIO.PWM(17, 50) # 50 Hz
p.start(0.0);
for dc in range(0, 101, 5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, -5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
p.stop()

except KeyboardInterrupt:
# here you put any code you want to run before the program
# exits when you press CTRL+C
print “keyboard Interrupt”

except:

print “other error”

finally:
GPIO.cleanup() # this ensures a clean exit

 

And a video:

Project 3: Connecting an Grove O2 Sensor to the Arduino Mega2560

IMG_7512

For our third sample project, we decided to connect up a Grove O2 Sensor to the Arduino Mega2560. This is an Analog Grove module. It will work with other Arduino products but the Arduino Mega2560 is IMG_7512the one we had sitting on the bench. Hookup? We used male to male breadboard jumpers to turn the female connectors on the Grove to Pin Header Converter into male headers. A0 (see the Grove Connector Article) went to A0 not the Arduino. Red is connected to 5V and the Black line on the Grove connector goes to GND on the Arduino.

The software is straightforward.
// test Grove – Gas Sensor(O2)
//
// Analog Grove Connector
// Yellow Connected to A0
// Red to 3.3V or 5V
// Black to GND
//
#include

#define Version 11 // version, 1.0 or 1.1, which depands on your board you use as it is
const int pinO2 = A0; // Connect Grove – Gas Sensor(O2) to A0

#if Version==11
const int AMP = 121;
#elif Version==10
const int AMP = 201;
#endif

const float K_O2 = 7.43;

void setup()
{
Serial.begin(115200); //Start the Serial connection
}

void loop()
{
float sensorValue;
float sensorVoltage;
float Value_O2;

sensorValue = analogRead(A0);
sensorVoltage =(sensorValue/1024.0)*3.3;
sensorVoltage = sensorVoltage/(float)AMP*10000.0;
Value_O2 = sensorVoltage/K_O2;

Serial.print(“Concentration of O2 is “);
Serial.print(Value_O2,1);
Serial.println(“%”);
delay(1000);
}

600px-O2_figure

Results (after just turning it on). Note that it takes 48 hours of warmup before the sensor will be accurate. You can see where we breathed on the sensor to see that it is working.

Concentration of O2 is 19.0%
Concentration of O2 is 19.0%
Concentration of O2 is 19.0%
Concentration of O2 is 19.0%
Concentration of O2 is 18.8%
Concentration of O2 is 18.8%
Concentration of O2 is 18.9%
Concentration of O2 is 19.0%
Concentration of O2 is 19.0%

Next Up? An I2C Grove Example

 

This post is originally from switchdoc.

 

Tutorial part 1:Intro to Grove connectors for Arduino/Raspberry Pi projects

raspberrypi

Raspberry Pi 2 Model B is 9% off, click the banner to product page

About Author

Calendar

March 2016
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031