CONTENTS 1 Component List and Assembly Instructions 2 Hardware Introduction ........... . Shovel Bucket .
Page 5
Piarm, Release 1.0 Thank you for choosing our PiArm. PiArm is a three-degree-of-freedom robotic arm for Raspberry Pi. It has 3 interchangeable parts - bucket, hanging clip and solenoid - to help you perform different tasks. In addition, PiArm offers both remote control and built-in dual joystick module control.
2. Robot HAT cannot charge the battery, so you need to buy a battery charger at the same time. • PiArm Assembly Instructions (.pdf) Warning: If the kit you received includes a clear Robot HAT Case, please do not mount it so as not to affect the PiArm left and right rotation range.
Page 8
Piarm, Release 1.0 Chapter 1. Component List and Assembly Instructions...
CHAPTER HARDWARE INTRODUCTION 2.1 Arm PiArm’s arm can be controlled in two ways: Angle Mode Coordinate Mode. • Angle Mode: Writes a certain angle to the three servos on the arm, thus rotating the arm to a specific position. •...
Page 10
2.1.2 Coordinate Mode PiArm has a spatial rectangular coordinate system with its origin located at the center of the output axis of the servos on both sides. The Control Point is located at the top of the arm and is scaled in millimeters. In the initial state, the coordinates of the Control Point are (0, 80, 80).
Page 11
Piarm, Release 1.0 It is important to note that the arm length of PiArm is finite, and if the coordinate values are set beyond the limits of its mechanical motion, PiArm will rotate to an unpredictable position. In other words, the total arm length of PiArm is 160 mm, which means that the limit value of the control points moving along the Y-axis should be between (0,0,0) and (0,160,0).
Piarm, Release 1.0 2.2 Shovel Bucket Assembling the Shovel Bucket Assemble the Shovel Bucket as shown below. Note: In step 2 you need to insert the servo into P11 for zeroing before inserting the D3 plate into the servo shaft in a vertical orientation.
Page 13
Piarm, Release 1.0 Assemble the Shovel Bucket to the end of the PiArm with M2x4 screws. 2.2. Shovel Bucket...
Page 14
Piarm, Release 1.0 The Shovel Bucket has a rotation range of -90 ~ 60. Chapter 2. Hardware Introduction...
Page 15
Piarm, Release 1.0 Use range Can’t dig water, can be used to dig sand and gravel. 2.2. Shovel Bucket...
Piarm, Release 1.0 2.3 Hanging Clip Assembly Assemble the Hanging Clip as shown below. Note: Note that in step 3 you need to insert the servo into the P11 for zeroing before inserting the D1 plate into the servo shaft in a vertical orientation.
Page 17
Piarm, Release 1.0 Attach the Hanging Clip to the end of the PiArm with the M2x4 screw. 2.3. Hanging Clip...
Page 18
Piarm, Release 1.0 The angle range of the Hanging Clip is 0-90°. Chapter 2. Hardware Introduction...
Page 19
Piarm, Release 1.0 Using range • The weight of the clamped object should be less than 150g. • The recommended height of the object to be clamped should be less than 4cm, width less than 8.5cm. • Slender objects need to find the right angle to clip up.
Piarm, Release 1.0 Range of use • Can only be used to suck ferrous products. • The larger the surface area of the iron product, the stronger the adsorption. • It is recommended that the weight of iron objects is less than 150g.
Page 23
Piarm, Release 1.0 Before you can use the dual joystick module, you need to connect its 8 wires to the corresponding pins of the Robot HAT as shown in the picture below. The joystick reads in a plane coordinate system from 0 to 4095, with the origin (0,0) in the lower left corner.
Page 24
Piarm, Release 1.0 pushing down (or left). Note: In the Python library, these values have been processed into directional indications as follows. The Z-axis button outputs a low level (0) when pressed and a high level (1) when released. Chapter 2. Hardware Introduction...
Piarm, Release 1.0 2.6 About Robot HAT RST Button • A short-press of the RST Button will cause any running programs to reset. • A long-press of the RST Button until the LED lights up, and then releasing will disconnect the Robot HAT’s Bluetooth chip.
Page 26
Piarm, Release 1.0 Bluetooth Indicator • The Bluetooth indicator LED will stay on with a solid Bluetooth connection, and blink rapidly during a signal transmission. The LED will blink at 1-second intervals if the Bluetooth is disconnected. Note: You can see more details in the Robot HAT Documentation.
THREE PLAY WITH EZBLOCK Ezblock is a development platform developed by SunFounder designed for beginners to lower the barriers to getting started with Raspberry Pi. It has two programming languages: Graphical and Python, and available on almost all different types of devices. With Bluetooth and Wi-Fi support, you can download code, remote control a Raspberry Pi, on Ezblock Studio.
Page 28
Piarm, Release 1.0 3. Follow the instructions on the assembly foldout, insert the battery holder cable and turn the power switch to the ON. Wait for 1-2 minutes, there will be a sound to indicate that the Raspberry Pi boots successfully.
Projects Here, we show you the projects of playing Piarm on Ezblock Studio. If you are new to these, you can refer to the code images inside each project to program, and can learn the use of blocks according to TIPS.
Page 30
[Forever] block is, as the name suggests, a continuous loop that allows your program to change and respond. • This block is used to set an interval time in milliseconds. 3.2.2 Tips on PiArm blocks Here you can find some blocks needed to make PiArm work. Chapter 3. Play with Ezblock...
Page 31
Piarm, Release 1.0 3.2.3 Shovel Bucket Step 1 to the end of PiArm. Assemble the Shovel Bucket Step 2 Now start writing the code to make Shovel Bucket work. Put [set bucket pin as ()] in the [Start] block to initialize the bucket pin as P3.
Page 32
Step 4 Once the code is written, click the Download button in the bottom right corner to download it to the PiArm. Now you will see the Shovel Bucket moving back and forth, and you can click the Run button to stop the code from running.
Page 33
Note: Because in the assembly diagram above, it is connected to the Transfer Module, which is already connected to P3 during the PiArm assembly. Of course you can also connect it to other spare pins. 3.2. Assemble and Test 3 EoATs...
Page 34
Step 4 Once the code is written, click the Download button in the bottom right corner to download it to the PiArm. Now you will see the Hanging Clip repeatedly open/close, and you can click the Run button to stop the code from running.
Page 35
Note: Because in the assembly diagram above, it is connected to the Transfer Module, which is already connected to P3 during the PiArm assembly. Of course you can also connect it to other spare pins. 3.2. Assemble and Test 3 EoATs...
Page 36
Step 4 Once the code is written, click the Download button in the bottom right corner to download it to the PiArm. Now you will find that the Electromagnet is energized every second (the LED (D2) on the electromagnet lights up, indicating that it is energized, at which time it can be used to adsorb some materials with iron.).
• This block is a separate thread and can play some built-in background music. • This block can play some built-in sound effects. • You can write some text in this block and let PiArm speak them. 3.3. Sound Effects...
Page 38
Piarm, Release 1.0 3.3.2 Programming Step 1 You may want to simplify the program with Functions, especially when you perform the same operation multiple times. Putting these operations into a newly declared function can greatly facilitate your use. Click on the Functions category and select the appropriate function block, the function you created will also appear here.
Page 39
Step 3 Create a function named [sound] to make PiArm play a specific sound effect at a certain volume. • [play sound effects () with volume to () %]: This block can be used to play built-in sound effects with a volume range of 0%-100%.
Page 40
Once the code is written, click the Download button in the bottom right corner to download it to the PiArm. Now you will find that piarm first plays the sound effect in the sound function, and then plays the background music in the [music] function.
Piarm, Release 1.0 Edit directly to see the results. 3.4 Dual Joystick Module We can control PiArm in 2 parts, Arm and EoAT. In the first project, you have learned how to Assemble and Test 3 EoATs of PiArm’s separately.
Page 42
Piarm, Release 1.0 • Hanging Clip - Joystick Control • Electromagnet - Joystick Control 3.4.1 Arm - Joystick Control PiArm’s arm can be controlled in two ways: Angle Mode Coordinate Mode. • Angle Mode: Writes a certain angle to the three servos on the arm, thus rotating the arm to a specific position.
Page 43
Piarm, Release 1.0 Step 2 Set the initial values for these variables and set the servo rotation speed to 70%. Note: For the reason of the values of the HIGH and LOW variables, please refer to Dual Joystick Module. Step 3 Use [if else] block to do some conditional judgment cases (drag 5 [else if] blocks from the left to below the [if] block).
Page 44
• The X of the right joystick is connected to A2, and the Y is connected to A3. Assume that the X and Y of the left joystick and the Y of the right joystick are used to control the 3 servos of PiArm respectively, now first set the judgment condition to determine whether the left and right joysticks are toggled or not.
Page 45
• If A3 (RY) is less than LOW (1024), it means the right joystick is toggled backward. Step 4 Now set the rotation effect of PiArm according to the toggle of the left and right joysticks. • If the left joystick is toggled to the right, the Arm will turn right.
Page 46
• If the right joystick is toggled forward, the Arm will lower down. • If the right joystick is toggled backward, the Arm will raise up. Note: • , and represent the 3 servo rotation ranges on PiArm, refer to: Angle Mode.
Page 47
Piarm, Release 1.0 Store the obtained , and angle values into the [ () () ()] block, and then use the [set positon] block to make PiArm rotate this position. Step 7 Once you click the download button, you can use the Dual Joystick Module to control PiArm.
Page 48
Piarm, Release 1.0 Chapter 3. Play with Ezblock...
Page 49
Note: You can also find the code with the same name on the Examples page of Ezblock Studio and click Run or Edit directly to view the code. Once the code is run, you can control both the PiArm’s arm and Shovel Bucket with the dual joystick module. But you need to install Shovel Bucket to the PiArm first.
Page 50
Piarm, Release 1.0 • Push the left joystick to the left or right, the arm will turn to the left or right. • Push the left joystick forward or backward, the arm will extend or retract. • Push the right joystick forward or backward, the arm will be raised or lowered.
Page 51
Piarm, Release 1.0 After the code is run, you can use the dual joystick module to control PiArm’s arms and vertical clips at the same time. But you need to install Hanging Clip to PiArm first. • Push the left Joystick to the left or right, the arm will turn to the left or right.
Page 52
Note: You can also find the code with the same name on the Examples page of Ezblock Studio and click Run or Edit directly to view the block. After the code is run, you can use the dual joystick module to control both PiArm’s arm and the Electromagnet. But you need to install Electromagnet to PiArm first.
• Hanging Clip - Remote Control • Electromagnet - Remote Control 3.5.1 Arm - Remote Control PiArm’s arm can be controlled in two ways: Angle Mode Coordinate Mode. • Mode: Writes a certain angle to the three servos on the arm, thus rotating the arm to a specific position.
Page 54
Piarm, Release 1.0 To use the remote control function, you need to enter the Remote Control page from the left side of main page, and then drag one D-pad and 3 buttons to the central area. Back in the programming page, you will see an additional Remote category, and the D-pad and Button block appear in it.
Page 55
Piarm, Release 1.0 Step 2 Create 3 variables (, and ) and set the initial values, and set the rotation speed of PiArm to 70%. Step 3 Create a function called [arm_control] to set the rotation direction of the PiArm based on the arrow keys and button values.
Page 56
Piarm, Release 1.0 and dragging [else] or [else if] to the right below the [if]. • If the UP button () of D-pad is pressed, the Arm will extend forward. • If the Down button () of D-pad is pressed, the Arm will retract backward.
Page 57
Piarm, Release 1.0 Put the function [arm_control] into [Forever] for loop execution, and finally click the Download button to run the code. After that you can use the D-pad and Button A/B on the Remote Control page to control the movement of the Arm.
Page 58
Piarm, Release 1.0 Step 2 Select the function, there is only one function here, so arm_control is selected by default. Step 3 Name the library and fill in the description so that it can be better distinguished later. Chapter 3. Play with Ezblock...
Page 59
Piarm, Release 1.0 Step 4 Wait for the prompt to save successfully and the library will be saved in My Library on your personal page. You can also see it when you click Import Library. 3.5.3 Shovel Bucket - Remote Control...
Page 60
Piarm, Release 1.0 In the Mylib page, select the library you created and click Import. After importing, this library is in a collapsed style. You can right-click on it and click Expand Block, so that you can see its internal code.
Page 61
Piarm, Release 1.0 Step 3 Create the variables (, , and angle) and set the initial values to 0, then initialize the PiArm rotation speed and the pin of Shovel Bucket. Step 4 Create a new function [shovel], and write the code as follows to control Shovel Bucket with two buttons.
Page 62
Piarm, Release 1.0 button D is pressed, the variable angle is subtracted by 1. • Constrain the value of variable angle to -90 ~ 60 with [constrain () low() high ()] block. • Set the angle of according to the variable angle.
Page 63
Piarm, Release 1.0 3.5.4 Hanging Clip - Remote Control Create a new project and write code for it so that we can control the Hanging Clip while controlling the arm. Step 1 Import [arm_control] library, if you have not created this library before, please refer to: Create a Library.
Page 64
Piarm, Release 1.0 Step 3 Create the variables (, , and angle) and set the initial values to 0, then initialize the PiArm rotation speed and the pin of Hanging Clip. Step 4 Create a new function [clip], and write the code as follows to control Hanging Clip with two buttons.
Page 65
Piarm, Release 1.0 • Constrain the value of variable angle to 0 ~ 90 with [constrain () low() high ()] block. • Set the angle of Hanging Clip according to the variable angle. Step 5 Drag the [arm_control] and [clip] functions from the Functions category to the [Forever] block respectively.
Page 66
Piarm, Release 1.0 3.5.5 Electromagnet - Remote Control Create a new project and write code for it so that we can control the Electromagnet while controlling the arm. Step 1 Import [arm_control] library, if you have not created this library before, please refer to: Create a Library.
Page 67
Piarm, Release 1.0 Step 3 Create the variables (, , and ) and set the initial values to 0, then initialize the PiArm rotation speed and the pin of Electromaget. Step 4 Create a new function [electromagnet], and write code for it as the following steps, so that you can control...
Page 68
Piarm, Release 1.0 Step 5 Drag the [arm_control] and [electromaget] functions from the Functions category to the [Forever] block respectively. After clicking the download button, when the switch toggles to on, the electromagnet turns on (it is magnetic at this time, you can use iron adsorption material);...
This project sets 2 coordinate points by coordinate mode, and let the PiArm clip the rubber duck on the left to the bowl on the right. But you need to mount Hanging Clip to the PiArm first.
Page 70
Piarm, Release 1.0 3.6.1 Programming Step 1 Initialize the pin of the Hanging Clip and set the speed of the robot arm to 60%. Step 2 Set the coordinates of the 2 points. Since the rubber duck on the left and the bowl on the right are on the same line, you will find that their Y coordinate values are the same.
Page 71
• PiArm raises his head (start_coord_up) and then turns to the right side above the bowl (end_coord_up). • PiArm lowers his head (end_coord_up), then opens the Hanging Clip (20°) to let the rubber duck fall into the bowl, and finally raises his head again (end_coord_up).
Page 72
Piarm, Release 1.0 Step 4 Click on the Download button in the bottom right corner and you will see PiArm repeating the actions described above. Note: You can also find the code with the same name on the Examples page of Ezblock Studio and click Run or Edit directly to view the code.
Piarm provides a function of recording actions, which can be used to record the actions that PiArm has done. In this project, we will use the Dual Joystick Module to control the movement of the Arm of PiArm in Coordinate Control mode, and record the motion trajectory of the Arm through the joystick buttons so that PiArm can move repeatedly along the recorded trajectory.
Page 74
Step 1 Create five variables (HIGH, LOW, xAxis, yAxis and zAxis) and set their initial values. Step 2 Create a function named [set_position] to make the Dual Joystick Module move the PiArm in Coordinate Mode. • If the left joystick is toggled to the right, the Arm will turn right.
Page 75
Piarm, Release 1.0 • If the left joystick is toggled forward, the Arm will extend forward. • If the left joystick is toggled backward, the Arm will retract backward. • If the right joystick is toggled forward, the Arm will raise up.
Page 76
• The buttons will output low level (0) when pressed and output high level (1) when released. • When the button of the left joystick is pressed, the action of PiArm will be recorded at this time, and there will be a voice prompt to indicate the completion of recording.
3.8 GAME - Catching Dolls Now let’s play a game of catching dolls and see who can catch more dolls with PiArm in the given time. In order to play this game, we need to implement two functions, the first one is to control PiArm with the dual joystick module, and the second one is to timing, when the countdown is over, we can’t control PiArm anymore.
Page 78
Piarm, Release 1.0 3.8.1 Programming Step 1 Create five variables (HIGH, LOW, , , , flag, angle) and and set initial values for them. Then initialize the PiArm rotation speed and Hanging Clip pin. Note: • For the reason of the values of the HIGH and LOW variables, please refer to Dual Joystick Module.
Page 79
Piarm, Release 1.0 Step 2 Create another 5 variables (LX, LY, RY, LB, RB) to read the X, Y and pressed values of the Dual Joystick Module respectively. 3.8. GAME - Catching Dolls...
Page 80
Piarm, Release 1.0 Step 3 Set pressing the left and right joysticks at the same time as the game start action, so if LB and RB are read as 0 at the same time, it means the left and right joysticks are pressed, then the timing starts and the flag is set to 1.
Page 81
Create a function [control] to set the rotation effect of PiArm based on the Dual Joystick Module. • When flag is 1, it means the game starts. At this time you can start to control PiArm. • If the left joystick (LX) is toggled to the right, the Arm will turn right.
Page 82
Piarm, Release 1.0 Step 6 Put the [control] function into the [Forever] block. Chapter 3. Play with Ezblock...
Page 83
Piarm, Release 1.0 Step 7 Create a function named [timing] to use for timing. The game time is set to 60 seconds (60000), and a countdown will chime in the last 3 seconds to let you know that time is almost up.
Page 84
Piarm, Release 1.0 Let the [timing] function run in a separate thread. This allows you to control PiArm while counting down. The complete code is as follows: Chapter 3. Play with Ezblock...
3.9 GAME - Iron Collection In this project, prepare 3 shapes of iron pieces: triangle, circle and square, PiArm will randomly say a shape, you need to control PiArm to put the corresponding shape of iron pieces into the corresponding box in the specified time, you will not be able to control PiArm when the time is over.
Page 86
• , and represent the 3 servo rotation ranges on PiArm, refer to: Angle Mode. Step 2 Drag 2 D-pads from the remote control page to control PiArm, a button to start the game, and a Digital Tube to display the time. Chapter 3. Play with Ezblock...
Page 87
Create a function named [magnet] to enable the left and right control of the D-pad B to turn the electromagnet on and off. Step 4 Create a function named [control] to implement the Arm of PiArm to be controlled by the D-pad A and D-pad B. Note: 3.9. GAME - Iron Collection...
Page 88
Piarm, Release 1.0 • , and represent the 3 servo rotation ranges on PiArm, refer to: Angle Mode. • [constrain () low () high ()]: From Math category for setting the variation of a constant to a certain range. • [if else]: Conditional judgment block, you can create multiple conditional judgments by clicking the set icon and dragging [else] or [else if] to the right below the [if].
Page 89
Create the function [say_shape] to have PiArm speak a random shape. Step 6 The main flow of the code: when button E is pressed, the timer starts and PiArm will say a random shape. flag is used to represent the start of the countdown and you can control PiArm.
Page 90
Here the [time] block is used for timing, in Forever, when button E is pressed, the timing starts and [time - startTime] represents how many seconds have passed since then. Step 8 Let the [timing] function run in a separate thread. This allows you to control PiArm while counting down. The complete code is as follows: Chapter 3. Play with Ezblock...
Page 91
Piarm, Release 1.0 3.9. GAME - Iron Collection...
Page 92
Piarm, Release 1.0 Chapter 3. Play with Ezblock...
CHAPTER FOUR PLAY WITH PYTHON If you want to program in python, then you will need to learn some basic Python programming skills and basic knowledge of Raspberry Pi, please configure the Raspberry Pi first according to Quick Guide on Python.
Page 94
Piarm, Release 1.0 Power Adapter To connect to a power socket, the Raspberry Pi has a micro USB port (the same found on many mobile phones). You will need a power supply which provides at least 2.5 amps. Micro SD Card Your Raspberry Pi needs an Micro SD card to store all its files and the Raspberry Pi OS.
Page 95
Piarm, Release 1.0 Sound or Earphone The Raspberry Pi is equipped with an audio port about 3.5 mm that can be used when your screen has no built-in speakers or when there is no screen operation. 4.1.2 Installing the OS...
Page 96
Piarm, Release 1.0 Warning: Upgrading the Raspberry Pi OS to Debian Bullseye will cause some features to not work, so it is recommended to continue using the Debian Buster version. In the Raspberry Pi Imager, click CHOOSE OS -> Raspberry Pi OS(other).
Page 97
Piarm, Release 1.0 Step 5 Select the SD card you are using. Step 6 Press Ctrl+Shift+X or click the setting ** button to open the **Advanced options page to enable SSH and con- figure wifi, these 2 items must be set, the others depend on your choice . You can choose to always use this image customization options.
Page 98
Piarm, Release 1.0 Then scroll down to complete the wifi configuration and click SAVE. Note: wifi country should be set the two-letter ISO/IEC alpha2 code for the country in which you are using your Raspberry Pi, please refer to the following link: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_...
Page 99
Piarm, Release 1.0 Step 7 Click the WRITE button. 4.1. Quick Guide on Python...
Page 100
Piarm, Release 1.0 Step 8 If your SD card currently has any files on it, you may wish to back up these files first to prevent you from permanently losing them. If there is no file to be backed up, click Yes.
Page 101
Piarm, Release 1.0 Step 9 After waiting for a period of time, the following window will appear to represent the completion of writing. 4.1. Quick Guide on Python...
Page 102
Piarm, Release 1.0 4.1.3 Set up Your Raspberry Pi If You Have a Screen If you have a screen, it will be easy for you to operate on the Raspberry Pi. Required Components Any Raspberry Pi 1 * Power Adapter...
Page 103
Piarm, Release 1.0 If You Have No Screen If you don’t have a display, you can log in to the Raspberry Pi remotely, but before that, you need to get the IP of the Raspberry Pi. Get the IP Address After the Raspberry Pi is connected to WIFI, we need to get the IP address of it.
Page 104
Piarm, Release 1.0 Use the SSH Remote Control We can open the Bash Shell of Raspberry Pi by applying SSH. Bash is the standard default shell of Linux. The Shell itself is a program written in C that is the bridge linking the customers and Unix/Linux. Moreover, it can help to complete most of the work needed.
Page 105
Piarm, Release 1.0 Step 4 Input the passcode and the default password is raspberry. Step 5 We now get the Raspberry Pi connected and are ready to go to the next step. 4.1. Quick Guide on Python...
Page 106
Piarm, Release 1.0 Note: When you input the password, the characters do not display on window accordingly, which is normal. What you need is to input the correct password. For Windows Users If you’re a Windows user, you can use SSH with the application of some software. Here, we recommend PuTTY.
Page 107
Piarm, Release 1.0 Step 3 Click Open. Note that when you first log in to the Raspberry Pi with the IP address, there prompts a security reminder. Just click Yes. Step 4 When the PuTTY window prompts “login as:”, type in “pi” (the user name of the RPi), and password: “raspberry”...
Page 108
Piarm, Release 1.0 Step 5 Here, we get the Raspberry Pi connected and it is time to conduct the next steps. Note: If you are not satisfied with using the command window to control the Raspberry Pi, you can also use the remote desktop function, which can help us manage the files in the Raspberry Pi easily.
Page 109
Piarm, Release 1.0 Then download the code and install the piarm library. /home/pi/ git clone -b 2.0.0 https://github.com/sunfounder/piarm.git cd piarm sudo python3 setup.py install This step will take a little time, so please be patient. Finally you need to run the script i2samp.sh to install the components needed for the i2s amplifier, otherwise it may not have sound.
Page 110
Piarm, Release 1.0 Type y and press Enter to continue running the script. Type y and press Enter to make /dev/zero run in the background. Chapter 4. Play with Python...
Page 111
Piarm, Release 1.0 Enter y and press Enter to restart the robot. Note: If there is no sound after a restart, you may need to run the i2samp.sh script several times. 4.1.5 Servo Adjust To ensure that the servo has been properly set to 0°, first insert the rocker arm into the servo shaft and then gently rotate the rocker arm to a different angle.
Page 112
Piarm, Release 1.0 Wait for 1-2 minutes, there will be a sound to indicate that the Raspberry Pi boots successfully. Now, run servo_zeroing.py in the examples/ folder. cd /home/pi/piarm/examples sudo python3 servo_zeroing.py Note: If you get an error, try re-enabling the Raspberry Pi’s I2C port, see: Configuration.
Page 113
Piarm, Release 1.0 At this point you will see the servo arm rotate to a specific position (0°). If the servo arm does not return to 0°, press the RST button to restart the Robot HAT. Now you can continue the installation as instructed on the assembly foldout.
Piarm, Release 1.0 4.2 Assemble and Test 3 EoATs This is the first program, and the one you must see. In this program, you will learn how to assemble and use PiArm’s 3 end-of-arm tools. 4.2.1 Shovel Bucket Run the code cd /home/pi/piarm/examples sudo python3 shovel.py...
Page 115
Piarm, Release 1.0 Initialize the MCU first, then initialize the individual servo connection pins of PiArm and the connection pin of the bucket. • PiArm( ): Initialize the 3 servo pins on the Arm. • bucket_init( ): Set the pin of the bucket.
• set_electromagnet( ): Used to control the Electromagnet on/off. 4.3 Sound Effects In this example, we use the sound effects of PiArm (Robot HAT to be exact). It consists of three parts: Muisc, Sound, and Text to Speech. Install i2samp Before using this function, please activate the speaker so that it can produce sound.
Page 117
After the code is run, you will find that PiArm first plays the sound effect in the sound function, and then plays the background music. When the background music is played, the [tts] function is run for timing, and the countdown voice broadcast will be performed after 30 seconds.
• say(): Writing characters or strings in parentheses will make PiArm speak them out. 4.4 Dual Joystick Module Control In this project, we will use the Dual Joystick Module that comes with the kit to control the PiArm. • Shovel Bucket - Joystick Control •...
Page 119
Once the code is run, you will be able to control the rotation of PiArm’s arm by toggling the left and right joysticks, and controlling the angle of the Shovel Bucket by pressing the left and right joysticks respectively.
Page 120
Piarm, Release 1.0 (continued from previous page) _angles_control(): arm.speed flag False alpha,beta,gamma arm.servo_positions bucket arm.component_staus leftJoystick.read_status() "up": alpha flag True elif leftJoystick.read_status() "down": alpha flag True leftJoystick.read_status() "left": gamma flag True elif leftJoystick.read_status() "right": gamma flag True rightJoystick.read_status() "up": beta...
Page 121
Once the code is running, you will be able to control the rotation of PiArm’s arm by toggling the left and right joysticks, and control the opening/closing of the Hanging Clip by pressing the left and right joysticks respectively.
Page 122
Piarm, Release 1.0 Code from robot_hat import Servo,PWM,Joystick,ADC,Pin from robot_hat.utils import reset_mcu from time import sleep from piarm import PiArm reset_mcu() sleep(0.01) leftJoystick Joystick(ADC('A0'),ADC('A1'),Pin('D0')) rightJoystick Joystick(ADC('A2'),ADC('A3'),Pin('D1')) PiArm([1,2,3]) arm.hanging_clip_init(PWM('P3')) arm.set_offset([0,0,0]) _angles_control(): arm.speed flag False alpha,beta,gamma arm.servo_positions clip arm.component_staus leftJoystick.read_status() "up": alpha...
Page 123
Once the code is run, you will be able to control the rotation of PiArm’s arm by toggling the left and right joysticks, and controlling the on/off of the Electromagnet by pressing the left and right joysticks respectively.
Page 124
True: _angles_control() sleep(0.01) In this code, the _angles_control() function is created to control the PiArm. • alpha, beta and gamma refer to the angles of the 3 servos on the Arm respectively, refer to: Angle Mode. • If the left joystick is toggled up, alpha increases and the Arm will extend forward.
Piarm, Release 1.0 4.5 Keyboard Control In this project, we will use w, s, a, d, i, k, j and l on the keyboard to control the PiArm. • Shovel Bucket - Keyboard Coboardntrol • Hanging Clip - Keyboard Control •...
Page 126
Piarm, Release 1.0 (continued from previous page) import import termios reset_mcu() sleep(0.01) PiArm([1,2,3]) arm.bucket_init(PWM('P3')) arm.set_offset([0,0,0]) controllable manual Press keys on keyboard w: extend s: retract a: turn left d: turn right i: go up k: go down j: open l: close...
Page 127
Piarm, Release 1.0 (continued from previous page) 'k': elif beta flag True 'j': bucket flag True 'l': elif bucket flag True flag True: arm.set_angle([alpha,beta,gamma]) arm.set_bucket(bucket) print('servo angles: , bucket angle: '%(arm.servo_positions,arm. component_staus)) __name__ "__main__": print(manual) while True: readchar().lower() control(key) chr(27):...
Page 128
In this code, the control() function is created to control the PiArm by reading the key values on the keyboard. • alpha, beta and gamma refer to the angles of the 3 servos on the arm respectively, refer to: Angle Mode.
Page 129
Piarm, Release 1.0 4.5.2 Hanging Clip - Keyboard Control Run the code cd /home/pi/piarm/examples sudo python3 keyboard_control2.py After running the code, follow the prompts and press the keys on the keyboard to control the Arm and Hanging Clip of PiArm.
Page 130
In this code, the control() function is created to control the PiArm by reading the key values on the keyboard. • alpha, beta and gamma refer to the angles of the 3 servos on the arm respectively, refer to: Angle Mode.
Page 131
4.5.3 Electromagnet - Keyboard Control Run the code cd /home/pi/piarm/examples sudo python3 keyboard_control1.py After running the code, follow the prompts and press the keys on the keyboard to control the PiArm’s arms and Electromagnet. But you need to assemble to PiArm first.
Page 132
Piarm, Release 1.0 (continued from previous page) d: turn right i: go up k: go down j: on l: off ESC: Quit readchar(): sys.stdin.fileno() old_settings termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return control(key): arm.speed flag False alpha,beta,gamma arm.servo_positions status ""...
Coordinate Mode is used in this project. This project sets 2 coordinate points by coordinate mode, and let the PiArm clip the rubber duck on the left to the bowl on the right. But you need to mount to the PiArm first.
Page 134
After the code is run, after the code is run, you will be able to control the rotation of PiArm’s Arm by toggling the left and right joystick, and control the angle of the Shovel Bucket by pressing the left and right joystick respectively.
Run the code cd /home/pi/piarm/examples sudo python3 memory_function.py After the code is run, you can use the left and right joystick to control the rotation of PiArm and the Shovel Bucket (But you need to assemble Shovel Bucket to PiArm first), press the left joystick to record one movement of PiArm, after recording several sets of movements, you can press the right joystick to make PiArm to reproduce these movements.
Page 137
Piarm, Release 1.0 (continued from previous page) alpha flag True leftJoystick.read_status() "left": gamma flag True elif leftJoystick.read_status() "right": gamma flag True rightJoystick.read_status() "up": beta flag True elif rightJoystick.read_status() "down": beta flag True rightJoystick.read_status() "left": bucket flag True elif rightJoystick.read_status() "right":...
Page 138
Piarm, Release 1.0 (continued from previous page) flag True elif leftJoystick.read_status() "down": alpha flag True leftJoystick.read_status() "left": gamma flag True elif leftJoystick.read_status() "right": gamma flag True rightJoystick.read_status() "up": beta flag True elif rightJoystick.read_status() "down": beta flag True • alpha, beta and gamma refer to the angles of the 3 servos on the Arm respectively, refer to: Angle Mode.
4.8 GAME - Catching Dolls Now let’s play a game of catching dolls and see who can catch more dolls with PiArm in the given time. In order to play this game, we need to implement two functions, the first one is to control PiArm with the dual joystick module, and the second one is to timing, when the countdown is over, we can’t control PiArm anymore.
Page 140
After the code runs, press the left and right joystick at the same time to start the game. Then you can use the dual joystick module to control PiArm to catch the doll, please pay attention to the time, after 60 seconds, PiArm will tell the game is over and you will not be able to continue to control PiArm.
Page 141
Use the sleep() function to count down in 60 seconds, then let PiArm count down to 3, 2, 1, and when the time is over, let game_flag be 0, then PiArm will no longer be controlled. __name__ "__main__":...
This is the main flow of the code, when the left and right joysticks are pressed at the same time, PiArm says the timer starts, let game_flag be 1, then you can call control() function to control PiArm.
Page 143
Piarm, Release 1.0 (continued from previous page) arm.speed flag False readchar(): sys.stdin.fileno() old_settings termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return manual1 Press keys on keyboard p: Game Start ESC: Stop manual2 Press keys on keyboard w: extend s: retract...
Page 144
Piarm, Release 1.0 (continued from previous page) 'l': elif arm.set_electromagnet('off') arm.set_angle([alpha,beta,gamma]) timing(): flag global while True: flag True: t.say("game start") sleep(60) t.say("three") sleep(1) t.say("two") sleep(1) t.say("one") sleep(1) t.say("game over") flag False say_shape(): random.randint(1,3) t.say("Round") t.say("Triangle") t.say("Square") __name__ "__main__": print(manual1) thread1 threading.Thread(target...
Page 145
3 seconds, call the say_shape() function to make PiArm say a random shape. • If flag is True, call the control() function to make the PiArm rotate according to the key value. • chr(27) represents the Esc key, and if the Esc key is pressed, exit the main loop. This step is because the readchar() function is used to read the keyboard all the time, so you can’t stop the code directly with...
Page 146
Piarm, Release 1.0 Ctrl+C. • At this point, you can stop the code with Ctrl+C. Chapter 4. Play with Python...
CHAPTER FIVE APPENDIX 5.1 I2C Configuration Enable the I2C port of your Raspberry Pi (If you have enabled it, skip this; if you do not know whether you have done that or not, please continue). sudo raspi-config 3 Interfacing options P5 I2C...
Piarm, Release 1.0 5.2 Remote Desktop There are two ways to control the desktop of the Raspberry Pi remotely: VNC and XRDP, you can use any of them. 5.2.1 VNC You can use the function of remote desktop through VNC.
Page 150
Piarm, Release 1.0 Step 3 P3 VNC Step 4 Select Yes -> OK -> Finish to exit the configuration. Login to VNC Step 1 You need to download and install the VNC Viewer on personal computer. After the installation is done, open it.
Page 151
Piarm, Release 1.0 Step 2 Then select “New connection”. Step 3 Input IP address of Raspberry Pi and any Name. 5.2. Remote Desktop...
Page 152
Piarm, Release 1.0 Step 4 Double click the connection just created: Chapter 5. Appendix...
Page 153
Piarm, Release 1.0 Step 5 Enter Username (pi) and Password (raspberry by default). 5.2. Remote Desktop...
Page 154
Piarm, Release 1.0 Step 6 Now you can see the desktop of the Raspberry Pi: Chapter 5. Appendix...
Page 155
Piarm, Release 1.0 That’s the end of the VNC part. 5.2.2 XRDP Another method of remote desktop is XRDP, it provides a graphical login to remote machines using RDP (Microsoft Remote Desktop Protocol). Install XRDP Step 1 Login to Raspberry Pi by using SSH.
Page 156
Piarm, Release 1.0 Step 4 Finished the installation, you should login to your Raspberry Pi by using Windows remote desktop applications. Login to XRDP Step 1 If you are a Windows user, you can use the Remote Desktop feature that comes with Windows. If you are a Mac user, you can download and use Microsoft Remote Desktop from the APP Store, and there is not much difference between the two.
Page 157
Piarm, Release 1.0 Then the xrdp login page pops out. Please type in your username and password. After that, please click “OK”. At the first time you log in, your username is “pi” and the password is “raspberry”. Step 4 Here, you successfully login to RPi by using the remote desktop.
Piarm, Release 1.0 5.3 About the Battery Applicable Parameters • 3.7V • 18650 • Rechargeable • Li-ion Battery • Button Top • No Protective Board Note: • Robot HAT cannot charge the battery, so you need to buy a battery charger.
Page 159
Piarm, Release 1.0 Button Top Flat Top No protective board? You are recommend to use 18650 batteries without a protective board. Otherwise, the robot may be cut power and stop running because of the overcurrent protection of the protective board.
CHAPTER THANK YOU Thanks to the evaluators who evaluated our products, the veterans who provided suggestions for the tutorial, and the users who have been following and supporting us. Your valuable suggestions to us are our motivation to provide better products! Particular Thanks •...
SEVEN COPYRIGHT NOTICE All contents including but not limited to texts, images, and code in this manual are owned by the SunFounder Company. You should only use it for personal study,investigation, enjoyment, or other non-commercial or nonprofit purposes, under therelated regulations and copyrights laws, without infringing the legal rights of the author and relevant right holders.
Need help?
Do you have a question about the PiArm and is the answer not in the manual?
Questions and answers