From 49e852a0740ab5e008a5a9f8df00ac1febc131c3 Mon Sep 17 00:00:00 2001 From: cure123123 <72863081+cure123123@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:08:05 +0800 Subject: [PATCH 1/3] Update Grove_Base_Hat_for_Raspberry_Pi.md --- .../Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md | 174 +++++++++++++++--- 1 file changed, 153 insertions(+), 21 deletions(-) diff --git a/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md b/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md index 1eaf299fd7fd..15e19943a935 100644 --- a/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md +++ b/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md @@ -115,7 +115,7 @@ We use SWD port to burn the firmware to this hat. In addition, you can see 3 GPI |-----------------------------|-------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| | Working Voltage | 3.3V | 5V | | MCU | STM32F030F4P6 | ATMEGA328P | -| Grove Ports | 6 Digital(3.3V) 4 Analog(3.3V) 3 I2C(3.3V) 1 PWM(3.3V) 1 RPISER(UART) connect to Raspberry Pi(3.3V) 1 SWD | 7 Digital(5V) 3 Analog(5V) 3 I2C(5V) 1 SERIAL: Connect to ATMEGA328P D0/1(5V) 1 RPISER: Connect to Raspberry Pi(3.3V) 1 ISP | +| Grove Ports | 6 x Digital(3.3V); 4 x Analog(3.3V) ; 3 x I2C(3.3V); 1 x PWM(3.3V) ; 1 x RPISER(UART) connect to Raspberry Pi(3.3V) ; 1 x SWD | 7 x Digital(5V); 3 x Analog(5V) ;3 x I2C(5V) ;1 x SERIAL: Connect to ATMEGA328P D0/1(5V) ; 1 x RPISER: Connect to Raspberry Pi(3.3V) ;1 x ISP | | Grove-Digital | Connect to Raspberry Pi directly | Connect to ATMEGA328P digital pins and transfer to I2C signal, then through level converter to Raspberry Pi | | Grove-Analog | Connect to STM32F030F4P6(12bit ADC) and then transfer to I2C signal,route to Raspberry Pi directly | Connect to ATMEGA328P analog pins(10bit ADC) and then transfer to I2C signal, then through level converter to Raspberry Pi | | Grove-I2C | Connect to Raspberry Pi directly | Connect through level converter to Raspberry Pi | @@ -168,34 +168,167 @@ To operate grove sensors, the grove.py depends many hardware interface libraries **Step by step installation** -Besides the one-click installation, you can also install all the dependencies and latest grove.py step by step. +Besides the one-click installation, you can also install all the dependencies and latest grove.py step by step. Please refer to [grove.py github repository](https://github.com/Seeed-Studio/grove.py). :::caution -If you are using **Raspberry Pi with Raspberrypi OS >= Bullseye**, you have to use this command line **only with Python3**. +If you are using **Raspberry Pi with Raspberrypi OS >= Bullseye**, you have to use this command line **only with Python3**. The following instruction is working on Bookworm OS. ::: -```python -git clone https://github.com/Seeed-Studio/grove.py -cd grove.py -# Python3 -sudo pip3 install . --break-system-packages +For beginner or library user only, please install with online method. +For developer or advanced user, please install [dependencies](https://github.com/Seeed-Studio/grove.py/blob/master/doc/INSTALL.md#install-dependencies) and then install grove.py with [source code](https://github.com/Seeed-Studio/grove.py?tab=readme-ov-file#install-grovepy). +##### Install Dependencies +Add repository +```linux +# RPi +echo "deb https://seeed-studio.github.io/pi_repo/ stretch main" | sudo tee /etc/apt/sources.list.d/seeed.list ``` +Add public GPG key -#### Usage +```shell +curl https://seeed-studio.github.io/pi_repo/public.key | sudo apt-key add - +# or +# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BB8F40F3 +``` +Enable I2C interface +```linux +sudo raspi-config +``` + +- Select interfacingg Options>I2C>Yes>Ok>Finish +- Enable I2C interface + +In the lastest version of Python3, it is recommended to use *virtualenv* for isolated package management. +```linux +sudo apt install python3-virtualenv +virtualenv -p python3 env +source env/bin/activate +``` + +Install library raspberry-gpio-python for RPi +```linux +sudo apt update +# python3 +sudo apt install python3-rpi.gpio +``` +Install library rpi_ws281x for RPi +```linux +# python3 +sudo pip3 install rpi_ws281x +# env +pip install rpi_ws281x +``` -Now you can use the Grove Base Hat for Raspberry Pi with dozens Grove modules, tap the command **grove_** and press the ++tab++ key to check the supported Grove list. +##### Online install +To install into a virtual environment, first active your virtualenv and type the following command: +```linux +curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | bash -s -- --user-local --bypass-gui-installation +``` +If you want to install into the system, you can type the following command: +```linux +curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s - ``` -pi@raspberrypi:~$ grove_ -grove_i2c_color_sensor_v2 grove_mini_pir_motion_sensor grove_rotary_angle_sensor grove_temperature_sensor -grove_4_digit_display grove_i2c_motor_driver grove_moisture_sensor grove_ryb_led_button grove_thumb_joystick -grove_air_quality_sensor_v1_3 grove_lcd_1.2inches grove_oled_display_128x64 grove_servo grove_tilt_switch -grove_button grove_led grove_piezo_vibration_sensor grove_slide_potentiometer grove_touch_sensor -grove_collision_sensor grove_light_sensor_v1_2 grove_sound_sensor grove_ultrasonic_ranger -grove_gesture_sensor grove_loudness_sensor grove_recorder_v3_0 grove_switch grove_water_sensor -grove_high_accuracy_temperature grove_mech_keycap grove_relay grove_temperature_humidity_sensor -pi@raspberrypi:~$ grove_ +##### Install grove.py locally + +```linux +git clone https://github.com/Seeed-Studio/grove.py +cd grove.py +# Python3 +sudo pip3 install . +``` +```linux +# virutalenv for Python3 (If the installation fails when using pip3) +sudo apt install python3-virtualenv +virtualenv -p python3 env +source env/bin/activate +pip3 install . +``` + +#### Usage + +Now you can use the Grove Base Hat for Raspberry Pi with dozens Grove modules, tap the command **grove_** and press the ++tab++ key to check [the supported Grove list](https://github.com/Seeed-Studio/grove.py/tree/master/doc). + +```linux +(env) pi@raspberrypi:~ $ grove_ +grove_12_key_cap_i2c_touch_mpr121 +grove_16x2_lcd +grove_1wire_thermocouple_amplifier_max31850 +grove_3_axis_accelerometer_adxl372 +grove_3_axis_compass_bmm150 +grove_3_axis_digital_accelerometer +grove_4_digit_display +grove_6_axis_accel_gyro_bmi088 +grove_air_quality_sensor_v1_3 +grove_button +grove_cap_touch_slider_cy8c +grove_collision_sensor +grove_current_sensor +grove_gesture_sensor +grove_gpio +grove_high_accuracy_temperature +grove_i2c_color_sensor_v2 +grove_i2c_motor_driver +grove_i2c_thermocouple_amplifier_mcp9600 +grove_imu_9dof_icm20600_ak09918 +grove_lcd_1.2inches +grove_led +grove_light_sensor_v1_2 +(env) pi@raspberrypi:~ $ grove_ +grove_12_key_cap_i2c_touch_mpr121 +grove_16x2_lcd +grove_1wire_thermocouple_amplifier_max31850 +grove_3_axis_accelerometer_adxl372 +grove_3_axis_compass_bmm150 +grove_3_axis_digital_accelerometer +grove_4_digit_display +grove_6_axis_accel_gyro_bmi088 +grove_air_quality_sensor_v1_3 +grove_button +grove_cap_touch_slider_cy8c +grove_collision_sensor +grove_current_sensor +grove_gesture_sensor +grove_gpio +grove_high_accuracy_temperature +grove_i2c_color_sensor_v2 +grove_i2c_motor_driver +grove_i2c_thermocouple_amplifier_mcp9600 +grove_imu_9dof_icm20600_ak09918 +grove_lcd_1.2inches +grove_led +grove_light_sensor_v1_2 +grove_loudness_sensor +grove_mech_keycap +grove_mini_pir_motion_sensor +grove_moisture_sensor +grove_multi_switch +grove_multi_switch_poll +grove_oled_display_128x64 +grove_optical_rotary_encoder +grove_piezo_vibration_sensor +grove_pwm_buzzer +grove_recorder_v3_0 +grove_relay +grove_rotary_angle_sensor +grove_round_force_sensor +grove_ryb_led_button +grove_servo +grove_slide_potentiometer +grove_sound_sensor +grove_step_counter_bma456 +grove_switch +grove_temperature_humidity_bme680 +grove_temperature_humidity_sht31 +grove_temperature_sensor +grove_thumb_joystick +grove_tilt_switch +grove_time_of_flight_distance +grove_touch_sensor +grove_ultrasonic_ranger +grove_uv_sensor +grove_water_sensor +grove_ws2813_rgb_led_strip ``` Then we will show you how to use them according to port type. @@ -305,8 +438,7 @@ We will take the [Grove - OLED Display 128x64](https://www.seeedstudio.com/Grove Tap the following command `grove_oled_display_128x64` in the command line interface. ``` -pi@raspberrypi:~$ python3 grove_oled_display_128x64 -pi@raspberrypi:~$ +(env)pi@raspberrypi:~$ grove_oled_display_128x64 ``` It seems nothing happened, however you can find the most famous sentence in the cyber world if you check your oled.😄 From 90c4eab4a350c3a70c08c3b0f9367169fbdd3fbe Mon Sep 17 00:00:00 2001 From: cure123123 <72863081+cure123123@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:38:48 +0800 Subject: [PATCH 2/3] Update Grove_Base_Hat_for_Raspberry_Pi.md --- .../Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md b/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md index 15e19943a935..357c985d464a 100644 --- a/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md +++ b/docs/Top_Brand/Raspberry_Pi/Pi_HAT/Grove_Base_Hat_for_Raspberry_Pi.md @@ -206,9 +206,7 @@ source env/bin/activate Install library raspberry-gpio-python for RPi ```linux -sudo apt update -# python3 -sudo apt install python3-rpi.gpio +pip install rpi-gpio ``` Install library rpi_ws281x for RPi ```linux @@ -349,7 +347,7 @@ We will take the [Grove - Ultrasonic Ranger](https://www.seeedstudio.com/Grove-U Tap the following command `grove_ultrasonic_ranger 5 6` in the command line interface. ```python -pi@raspberrypi:~$ python3 grove_ultrasonic_ranger 5 6 +pi@raspberrypi:~$ grove_ultrasonic_ranger 5 6 Detecting distance... 6.979909436456088 cm 7.966469074117726 cm @@ -392,7 +390,7 @@ We will take the [Grove - Air quality sensor v1.3](https://www.seeedstudio.com/G Tap the following command `grove_air_quality_sensor_v1_3 0 1` in the command line interface. ```python -pi@raspberrypi:~$ python3 grove_air_quality_sensor_v1_3 0 1 +pi@raspberrypi:~$ grove_air_quality_sensor_v1_3 0 1 Detecting ... 62, Air Quality OK. 63, Air Quality OK. From ca98e4b221c1eb8474af72caffb110ef7f13bae5 Mon Sep 17 00:00:00 2001 From: cure123123 <72863081+cure123123@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:32:34 +0800 Subject: [PATCH 3/3] Update Grove-3-Axis_Digitial_Compass_v2.0.md --- .../Grove-3-Axis_Digitial_Compass_v2.0.md | 86 ++++--------------- 1 file changed, 19 insertions(+), 67 deletions(-) diff --git a/docs/Sensor/Grove/Grove_Sensors/Accelerometer/Grove-3-Axis_Digitial_Compass_v2.0.md b/docs/Sensor/Grove/Grove_Sensors/Accelerometer/Grove-3-Axis_Digitial_Compass_v2.0.md index 15b558442bdc..7f8293d4c48a 100644 --- a/docs/Sensor/Grove/Grove_Sensors/Accelerometer/Grove-3-Axis_Digitial_Compass_v2.0.md +++ b/docs/Sensor/Grove/Grove_Sensors/Accelerometer/Grove-3-Axis_Digitial_Compass_v2.0.md @@ -229,94 +229,46 @@ Enjoy your compass! #### 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 and install the grove.py to your raspberry pi. -:::note - If you are using **Raspberry Pi with Raspberrypi OS >= Bullseye**, you have to use this command line **only with Python3**. -::: -:::note - You are required to install python-mraa and python-upm, see the instruction here https://github.com/Seeed-Studio/pi_repo#mraa--upm-package-repository-for-raspberry-pi for more information. -::: -``` -cd ~ -git clone https://github.com/Seeed-Studio/grove.py +- **Step 2**. Excute below commands to run the code. ``` - -- **Step 3**. Excute below commands to run the code. - -``` -cd grove.py/grove -python3 grove_3_axis_compass_bmm150.py - +virtualenv -p python3 env +source env/bin/activate +#enter commmand +grove_3_axis_compass_bmm150 ``` Following is the grove_3_axis_compass_bmm150.py code. ```python - from __future__ import print_function -import time, sys, signal, atexit, math -try: - from upm import pyupm_bmm150 as sensorObj -except ImportError: - print('Error: Please install python-mraa python-upm module.\r\n' - 'See instruction here https://github.com/Seeed-Studio/pi_repo#mraa--upm-package-repository-for-raspberry-pi ') +import time +import bmm150 +import math def main(): - # Instantiate a BMP250E instance using default i2c bus and address - sensor = sensorObj.BMM150(0, 0x13) - - # For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS: - # BMM150(0, -1, 10); - - ## Exit handlers ## - # This function stops python from printing a stacktrace when you hit control-C - def SIGINTHandler(signum, frame): - raise SystemExit - - # This function lets you run code on exit - def exitHandler(): - print("Exiting") - sys.exit(0) - - # Register exit handlers - atexit.register(exitHandler) - signal.signal(signal.SIGINT, SIGINTHandler) - - # now output data every 250 milliseconds + device = bmm150.BMM150() # Bus number will default to 1 while (1): - sensor.update() + x, y, z = device.read_mag_data() - data = sensor.getMagnetometer() - print("Magnetometer x: {0:.2f}".format(data[0]), end=' ') - print(" y: {0:.2f}".format(data[1]), end=' ') - print(" z: {0:.2f}".format(data[2]), end=' ') - print(" uT") + heading_rads = math.atan2(x, y) - xyHeading = math.atan2(data[0], data[1]) - zxHeading = math.atan2(data[2], data[0]) - heading = xyHeading + heading_degrees = math.degrees(heading_rads) - if heading < 0: - heading += 2*math.pi - if heading > 2*math.pi: - heading -= 2*math.pi - - headingDegrees = heading * 180/(math.pi); - xyHeadingDegrees = xyHeading * 180 / (math.pi) - zxHeadingDegrees = zxHeading * 180 / (math.pi) + print("Magnetometer x: {0:.2f}".format(x), end=' ') + print(" y: {0:.2f}".format(y), end=' ') + print(" z: {0:.2f}".format(z), end=' ') + print(" uT") - print('heading(axis_Y point to): {0:.2f} degree'.format(headingDegrees)) + print('heading(axis_Y point to): {0:.2f} degree'.format(heading_degrees)) time.sleep(.250) if __name__ == '__main__': main() - - ``` :::success @@ -324,7 +276,7 @@ if __name__ == '__main__': ::: ```python -pi@raspberrypi:~/grove.py/grove $ python3 grove_3_axis_compass_bmm150.py +pi@raspberrypi:~/grove.py/grove $ grove_3_axis_compass_bmm150 Magnetometer x: -34.12 y: 36.71 z: -21.25 uT heading(axis_Y point to): 317.10 degree Magnetometer x: -34.49 y: 38.20 z: -16.32 uT