Dust Sensor & Barometer Examples

Hi, I just received a GrovePi with a Dust Sensor and a High Accuracy Barometer from Seeed Studio. There don’t seem to be any Python examples for using these.

Could someone give me some tips on how to start using these? Would it be possible to modify one of the existing examples to use these sensors?


We do not have any library for these sensors and have not tested both these sensors with the Grove Pi but they are compatible with the GrovePi.

To make these sensors work with the GrovePi you will have to write your own library.

The Pressure sensor is an I2C sensor so you can write a small library in Python to use it. You can look at the Compass library on how to use an I2C sensor https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_compass_lib.py .

For using the dust sensor, you’ll have to update the firmware for the GrovePi. Please have a look at the Guide to adding custom sensors here:http://www.dexterindustries.com/GrovePi/engineering/grovepi-protocol-adding-custom-sensors/ .

Please let me know if you need any more help.


Hi, thanks! I already looked at the Compass library over the weekend, and was able to re-write the Arduino C++ example for the Barometer on the Seeed site into Python.

Here is the code, in case anyone else wants to try this.

import smbus
import time
import RPi.GPIO as GPIO
import sys

if rev == 2:
bus = smbus.SMBus(1)
bus = smbus.SMBus(0)

HP20X_I2C_DEV_ID = 0x76 # Barometer device address
HP20X_SOFT_RST = 0x06 # Soft reset the device
REG_PARA = 0X0F # Status register

HP20X_RD_REG_MODE = 0x80

HP20X_READ_P = 0x30
HP20X_READ_A = 0x31
HP20X_READ_T = 0x32

HP20X_CONVERT_OSR1024 = 2<<2

OK_HP20X_DEV = 0X80

OSR_ConvertTime = 25.0;

def isAvailable():
bus.write_byte(HP20X_I2C_DEV_ID, REG_PARA|HP20X_RD_REG_MODE)
ret = bus.read_byte(HP20X_I2C_DEV_ID)

if ret == OK_HP20X_DEV:
    print "reset ok"
    return True
    print "reset failed"
    return False

def readSensor(sensor):

bus.write_byte(HP20X_I2C_DEV_ID, HP20X_WR_CONVERT_CMD|OSR_CFG)
bus.write_byte(HP20X_I2C_DEV_ID, sensor)
value = data[0]&lt;&lt;16 | data[1]&lt;&lt;8 | data[2]
return value

bus.write_byte(HP20X_I2C_DEV_ID, HP20X_SOFT_RST)

if isAvailable():
print "Barometer Available"
print "Barometer Not Available"

while (isAvailable()):
temp = readSensor(HP20X_READ_T) / 100.0
print "Temperature: " + str(temp)
baro = readSensor(HP20X_READ_P) / 100.0
print "Barometer: " + str(baro)
alti = readSensor(HP20X_READ_A) / 100.0
print "altitude: " + str(alti)


Sorry, the forums won’t allow you to upload Python files. Try renaming and uploading it as .txt file instead of a .py file. Something even better would be if you could send us a pull request on the Github Repository https://github.com/DexterInd/GrovePi .

We’ll love to integrate it with our existing codebase. Let me know if you are able to get the Dust sensor to work.


  . . . so . . . if I understand this correctly . . . which I probably don't . . . I'll have to create a unique ID for the Dust Sensor.  Then, I will need to add an "if(cmd[0]== unique ID)" section to grove_pi_v1_1.ino.  In that section, I will need to add code like the example here: http://www.seeedstudio.com/wiki/Grove_-_Dust_sensor
 Now, this is the step that scares me, because I have never programmed an Arduino before, I will need to build the firmware, and update that on the Arduino.  I did find a partial description of how to do this here: http://www.dexterindustries.com/forum/?topic=firmware-modification
 Unfortunately, this isn't quite detailed enough for an Arduino n00bie like me.  For example, when I look at the source that I cloned from the Git repository, I see this in the firmware part:

root@HymasGrove:~/hymas/GrovePi/Firmware/Source/v1.1# find .
So I see the .ino file, but the dependent library directories are empty. Will the build process find them somehow . . . ? And how to I need to invoke the Arduino IDE? Start a VNC session on the Pi, and then just click on the .ino file? Or do I need to invoke the IDE from somewhere specific in the tree?
Thanks for any help you can give me!

You are in going in the right direction.
The missing libraries were a problem from our side. Thanks for letting us know. We have updated the repository and they should be there.

To upload the code to the grove pi, you first connect the reset jumpers and the solderpads the same was as you would do for a firmware update http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/.

You can compile and upload the code using the Arduino IDE. It’s already installed on the Dexter Industries Image or SD card. You’ll need to make some changes if you are not using the Dexter Industries Image. Run this script if you are not using our image: https://github.com/DexterInd/GrovePi/blob/master/Script/install.sh .

You can access the Arduino IDE from the Start button on the LXDE on the Raspberry Pi . The Arduino IDE is in the Electronics section.

Now to create a custom sensor, you’ll first have to send a command with a unique ID to the Grove Pi from Python. You’ll have to create a function similar to this https://github.com/DexterInd/GrovePi/blob/ea810b77d8ff14ec1a5a7e0e226d0b76400ebadf/Software/Python/grovepi.py#L106-L111 . Just remember to give appropriate delay after sending the command and before reading the data. (Right now it is 20ms).

Now in the Arduino code, you’ll have to write a block to do whatever you want to do after getting that command, something similar to this: https://github.com/DexterInd/GrovePi/blob/master/Firmware/Source/v1.1/grove_pi_v1_1/grove_pi_v1_1.ino#L64-L80 .

To send data back you’ll have to load it into the buffer b[]. If the data is more than a byte then you’ll have to break it: https://github.com/DexterInd/GrovePi/blob/ea810b77d8ff14ec1a5a7e0e226d0b76400ebadf/Firmware/Source/v1.1/grove_pi_v1_1/grove_pi_v1_1.ino#L76-L77 .

You’ll also have to condition so that the proper data is sent for the read command: https://github.com/DexterInd/GrovePi/blob/ea810b77d8ff14ec1a5a7e0e226d0b76400ebadf/Firmware/Source/v1.1/grove_pi_v1_1/grove_pi_v1_1.ino#L157-L167 .
You send 1 extra byte back. So if you want to send 2 bytes back, you write 3 in the Wire.Write().

So show sending back data works is that, you send a command for GrovePi to do something and the GrovePi executes it and stores some data in the buffer . Then you send a command to read data back if you want, so the GrovePi sends you back the data that is in the buffer from the last command.

Hope that this helps.
Let me know if you need any more help.


 Hi!  Well, I can talk from my Python host code to the Arduino code now.  So I am starting on talking to the sensor.  Is it possible in the Arduino to read the Serial.println() messages?
 It seems to want to read them from COM1:, but I don't see where I can set it to something else.

The Serial on the GrovePi is not connected to the Serial on the Raspberry Pi. If you want to connect the Serial between the Raspberry Pi and the GrovePi, then you’ll have to connect the two portsRPISER and SERIAL using a Grove cable.

You’ll also have to modify the cable before connecting. The normal grove cable comes with the following color code: BRWY <-> BRWY. You’ll have to invert the white and yellow wires at one end so you’ll have the cable as BRWY <->BRYW . You can do it by just pulling up the small platic above the metal contact on the connector and pulling the wire out. Do this for both the yellow and white cable and push them back in the new position.

Try out a basic Serial print example in both the wire configurations and if it works then only move forward.

COM0 won’t work on the serial port of the Raspberry Pi. To use the serial port, run: ln -sf /dev/ttyAMA0 /dev/ttyS0 in the Terminal and a new serial port will appear in the Arduino IDE.

This setting goes away on restart and if you want to load it automatically on boot then do this.
Open crontab:
crontab -e
Add this entry at the end of the file:
@reboot ln -sf /dev/ttyAMA0 /dev/ttyS0
and It’ll load the Serial port up at boot.

There is one more thing that you have to be cautious when using the Serial Port on the Raspberry Pi. If you open the Serial Port and the Arduberry is sending a lot of serial data continuously then the Raspberry Pi processor usage will shoot to 100% and it can easily hang. Limiting the data being sent and received helps a lot to run the Raspberry Pi smoothly.


1 Like

I just finished my Python scripts for the Grove Digital Barometic Sensor and the GrovePi. I based it on the Adafruit_BMP085.py, but made some alterations on the calculation of the altitude (using a better formula for the barometic hight formula).

You can find the scripts (one with the functions and another with a usage example on Github: https://github.com/JohanVandewalle/Grove_Digital_Barometic_Sensor.

Hi Johan,
It would be great if you could send a pull request in the Dexter Industries repository too. We’ll be happy to integrate them with out current supported sensors.



I just pulled one request in the Dexter Industries repository for the python scripts for both the grove digital light sensor and the grove barometic sensor. I’ve changed the files names so they have the same structure as the other files in that repository:

  • grove_i2c_digital_light_sensor.py
  • readme_grove_i2c_digital_light_sensor.MD
  • grove_i2c_barometic_sensor.py
  • grove_i2c_barometic_sensor_example.py
  • grove_i2c_barometic_sensor.pyx
  • readme_grove_i2c_barometic_sensor.MD

We just merged this! Thanks so much for the contribution!!

I have run the grove_i2c_barometic_sensor_example.py example and I get 4 error messages “Error accessing 0x076: Check your I2C address” and the readings displayed look like defaults (-3.20 C, 999.77 hPa, 143.76 m). I’m using this sensor https://www.epictinker.com/ProductDetails.asp?ProductCode=SS-811027001. Any help would be appreciated.

We do not support this sensor right now. This is a pretty new sensor and is compatible with the GrovePi but we don;t have the library or example for it right now but we might develop one for it in the near future. If you like, you can start developing the library for it and contribute back. We’ll be more than happy to help you out.


Karan, that is very disappointing news. What ‘help’ can you provide? It’s been a long time since I was a developer. If you can point me in the right direction, perhaps I can make a go of it.

Hi tfeeney,
Sorry for the frustration. This is a pretty new sensor and we have not received it yet to try it out and get the driver code working. We might get a new sensor in the coming weeks but no ETA on this yet.

If you look at this post: http://www.dexterindustries.com/topic/dust-sensor-barometer-examples/#post-22850 someone else on the forums did try to write the driver code for this sensor. You can try that out to start with and let us know if that helps.



I am using the following sensor,


and when I run the example for grove_i2c_barometic_sensor_example.py, I am getting “Error accessing 0x076: Check your I2C address” and I am getting some default reading. It will be helpful if you kindly provide a sample example of using this sensor.

Hi @lokeshpakal,

It looks like you are trying an example which would work with Barometer sensor BMP180.
The link you have posted points to a High accuracy HP206C barometer sensor. If this is the sensor that you are using then you must try the high_accuracy_barometer_example.py from here.

Please let us know if this helps,

Thanks for letting me know. Can you please provide a link to the example for using High Accuracy HP206C barometer sensor? I do not have BMP180 sensor.
It will be helpful.