Skip to content

Commit

Permalink
Merge pull request #1526 from Carla-Guo/docusaurus-version
Browse files Browse the repository at this point in the history
Update raspberry pi support on Grove-Buzzer.md and Grove-I2C_UV_Sensor-VEML6070.md
  • Loading branch information
limengdu authored Aug 12, 2024
2 parents c63c742 + 3eabd47 commit 0917bc5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 77 deletions.
69 changes: 30 additions & 39 deletions docs/Sensor/Grove/Grove_Accessories/Actuator/Grove-Buzzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,72 +151,63 @@ Upload the program to your Arduino/Seeeduino.
If you are using **Raspberry Pi with Raspberrypi OS >= Bullseye**, you have to use this command line **only with Python3**.
:::

- **Step 1**. Follow [Setting Software](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi/#installation) to configure the development environment.
- **Step 2**. Download the source file by cloning the grove.py library.
- **Step 1**. Follow [Setting Software](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi/#installation) to configure the development environment,and install the grove.py to your raspberry pi.

```
cd ~
git clone https://github.com/Seeed-Studio/grove.py
```

- **Step 3**. Excute below command to run the code.
- **Step 2**. Excute below command to run the code.

```
cd grove.py/grove
python3 grove_pwm_buzzer.py
# virutalenv for Python3
virtualenv -p python3 env
source env/bin/activate
# enter commmand
grove_pwm_buzzer
```

Following is the grove_led.py code.
Following is the grove_pwm_buzzer.py code.

```python

from __future__ import print_function

import time
from mraa import getGpioLookup
from upm import pyupm_buzzer as upmBuzzer
import RPi.GPIO as GPIO

def main():
print("Insert Grove-Buzzer to Grove-Base-Hat slot PWM[12 13 VCC GND]")
from grove.helper import helper
# helper.root_check()

print("Insert Grove-Buzzer to Grove-Base-Hat slot PWM[12 13 VCC GND]")
# Grove Base Hat for Raspberry Pi
# PWM JST SLOT - PWM[12 13 VCC GND]
pin = 12
#
# Create the buzzer object using RaspberryPi GPIO12
mraa_pin = getGpioLookup("GPIO%d" % pin)
buzzer = upmBuzzer.Buzzer(mraa_pin)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)

chords = [upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE, upmBuzzer.BUZZER_MI,
upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA,
upmBuzzer.BUZZER_SI];
# create PWM instance
pwm = GPIO.PWM(pin, 10)
pwm.start(0)

# Print sensor name
print(buzzer.name())

# Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes
for chord_ind in range (0,7):
# play each note for a half second
print(buzzer.playSound(chords[chord_ind], 500000))
time.sleep(0.1)

print("exiting application")
chords = [1047, 1175, 1319, 1397, 1568, 1760, 1976]
# Play sound (DO, RE, MI, etc.), pausing for 0.5 seconds between notes
try:
for note in chords:
pwm.ChangeFrequency(note)
pwm.ChangeDutyCycle(95)
time.sleep(0.5)
finally:
pwm.stop()
GPIO.cleanup()

# Delete the buzzer object
del buzzer
print("Exiting application")

if __name__ == '__main__':
main()



```

:::success
If everything goes well, the buzzer will ring a few times and then stop, the program will automatically exit.
:::

You can quit this program by simply press **ctrl+c**.

### Play With Raspberry Pi (with GrovePi_Plus)

#### Hardware
Expand Down
104 changes: 66 additions & 38 deletions docs/Sensor/Grove/Grove_Sensors/Light/Grove-I2C_UV_Sensor-VEML6070.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,59 +258,87 @@ sensor.set_interrupt(INT_102_STEP,ENABLE); // modified

#### Software

- **Step 1**. Follow [Setting Software](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi/#installation) to configure the development environment.
- **Step 2**. Download the source file by cloning the grove.py library.
- **Step 1**. Follow [Setting Software](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi/#installation) to configure the development environment install the grove.py to your raspberry pi.
- **Step 2**. Excute below commands to run the code.

```
cd ~
git clone https://github.com/Seeed-Studio/grove.py
```

- **Step 3**. Excute below commands to run the code.

```
cd grove.py/grove
python grove_uv_sensor.py
# virutalenv for Python3
virtualenv -p python3 env
source env/bin/activate
#enter commmand
grove_uv_sensor
```

Following is the grove_uv_sensor.py code.

```python


from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_veml6070 as veml6070
from grove.i2c import Bus
import time


# I2C address of the device
VEML6070_DEFAULT_ADDRESS = 0x38

# VEML6070 Command Set
VEML6070_CMD_ACK_DISABLE = 0x00 # Acknowledge Disable
VEML6070_CMD_ACK_ENABLE = 0x20 # Acknowledge Enable
VEML6070_CMD_ACK_THD_102 = 0x00 # Acknowledge threshold 102 Steps
VEML6070_CMD_ACK_THD_145 = 0x10 # Acknowledge threshold 145 Steps
VEML6070_CMD_IT_1_2T = 0x00 # Integration time = 1/2T
VEML6070_CMD_IT_1T = 0x04 # Integration time = 1T
VEML6070_CMD_IT_2T = 0x08 # Integration time = 2T
VEML6070_CMD_IT_4T = 0x0C # Integration time = 4T
VEML6070_CMD_RESERVED = 0x02 # Reserved, Set to 1
VEML6070_CMD_SD_DISABLE = 0x00 # Shut-down Disable
VEML6070_CMD_SD_ENABLE = 0x01 # Shut-down Enable
VEML6070_CMD_READ_LSB = 0x38 # Read LSB of the data
VEML6070_CMD_READ_MSB = 0x39 # Read MSB of the data

class VEML6070():
def __init__(self, address = VEML6070_DEFAULT_ADDRESS):
self._addr = address
self._bus = Bus()
self.write_command()

def write_command(self):
"""Select the UV light command from the given provided values"""
COMMAND_CONFIG = (VEML6070_CMD_ACK_DISABLE | VEML6070_CMD_IT_1_2T | VEML6070_CMD_SD_DISABLE | VEML6070_CMD_RESERVED)
self._bus.write_byte(VEML6070_DEFAULT_ADDRESS, COMMAND_CONFIG)

def read_uvlight(self):
"""Read data back VEML6070_CMD_READ_MSB(0x73) and VEML6070_CMD_READ_LSB(0x71), uvlight MSB, uvlight LSB"""
data0 = self._bus.read_byte(VEML6070_CMD_READ_MSB)
data1 = self._bus.read_byte(VEML6070_CMD_READ_LSB)

# Convert the data
uvlight = data0 * 256 + data1

return {'u' : uvlight}

def main():
# Instantiate a Vishay UV Sensor on the I2C bus 0
veml6070_sensor = veml6070.VEML6070(0);

## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
def main():

# This function lets you run code on exit, including functions from abpdrrt005pg2a5
def exitHandler():
print("Exiting")
sys.exit(0)
veml6070 = VEML6070()

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit

# Read the value every second and detect the pressure
while(1):
print("UV Value: {0}".format(veml6070_sensor.getUVIntensity()))
time.sleep(1)
# This function lets you run code on exit, including functions from abpdrrt005pg2a5
def exitHandler():
print("Exiting")
sys.exit(0)

while True:
light = veml6070.read_uvlight()
print("UV Value: {0}".format(light['u']))
print(" *********************************** ")
time.sleep(1)

if __name__ == '__main__':
main()


main()
```

:::tipsuccess
Expand Down

0 comments on commit 0917bc5

Please sign in to comment.