---
# System prepended metadata

title: Dobot藍牙遙控輸送帶套件

---

### 介紹影片
https://www.youtube.com/watch?v=v4wUC5L-KBc

### 零件清單
1. Dobot 手臂套件
![image](https://hackmd.io/_uploads/r1UP72bVA.png)

2. Dobot 輸送帶套件
![image](https://hackmd.io/_uploads/HyT_X3WVR.png)

3. Makeblock CyberPi 控制板 
![image](https://hackmd.io/_uploads/rJkbNnW4A.png)

4. Makeblock 藍牙搖桿
![image](https://hackmd.io/_uploads/By8QNnZVR.png)

5. 20cm 杜邦排線
![image](https://hackmd.io/_uploads/Hkw59hZEA.png)

6. 迷你棧板、貨櫃模型
https://skfb.ly/oVqpx
https://skfb.ly/oVqqn

### CyberPi 接線與程式燒錄
https://hackmd.io/bl-fxyf8Taar2aM6UEPCtg

### CyberPi Python程式

``` python=1
from machine import UART
import cyberpi,time,struct,gamepad,mbuild

uart1 = UART(1, baudrate=115200, tx=15, rx=21)

Sx=260;Sy=0;Sz=0;Sr=0


def MoveToPoint(x,y,z,r):
    UartCommand=[170,170]
    length=19
    ID=84
    Ctrl=3
    ptpmode=1
    
    # Home 260,0,-8.5,0
    
    # x = 200
    Dx=list(struct.pack("!f",x)) # 32float to 4 decimel list
    print(Dx[::-1]) # to reverse
    
    # y = 0
    Dy=list(struct.pack("!f",y))
    print(Dy[::-1])
    
    # z = -8.5
    Dz=list(struct.pack("!f",z))
    print(Dz[::-1])
    
    # r= 0 
    Dr=list(struct.pack("!f",r))
    print(Dx[::-1]) 
    
    payload=[]
    payload.append(ID)
    payload.append(Ctrl)
    payload.append(ptpmode)
    payload.extend(Dx[::-1])
    payload.extend(Dy[::-1])
    payload.extend(Dz[::-1])
    payload.extend(Dr[::-1])
    
    # print(payload)
    
    Checksum=256 - sum(payload) & 0xff
    # print(Checksum)
    
    UartCommand.append(length)
    UartCommand.extend(payload)
    UartCommand.append(Checksum)
    # print(UartCommand)
    
    uart1.write(bytes(UartCommand))
    # c=uart1.read()
    # cyberpi.console.println(x,y,z,r)




while True :

    suck=False
    if gamepad.is_key_pressed('Select'):
        cyberpi.console.print('homing')
        # homing commend
        data1 = [170,170, 6, 31,3,0,0,0,0,222]  
        uart1.write(bytes(data1))
        Sx=260;Sy=0;Sz=0;Sr=0
        time.sleep(1)
        
    elif gamepad.get_joystick('Rx')==100:
        cyberpi.console.print('x')
        Sr-=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Rx')==-100:
        cyberpi.console.print('o')
        Sr+=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Ry')==100:
        cyberpi.console.print('-')
        Sz-=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Ry')==-100:
        cyberpi.console.print('+')
        Sz+=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Lx')==100: # 檢測是否按下按鍵
        cyberpi.console.print('>')
        Sy-=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Lx')==-100:
        cyberpi.console.print('<')
        Sy+=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Ly')==100:
        cyberpi.console.print('^')
        Sx+=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.get_joystick('Ly')==-100:
        cyberpi.console.print('v')
        Sx-=5
        MoveToPoint(Sx,Sy,Sz,Sr)
        
    elif gamepad.is_key_pressed('L1'):
        UartCommand=[170, 170, 4, 63, 3, 0, 0, 190] # unsuck
        uart1.write(bytes(UartCommand))
        suck=False
        cyberpi.console.print('unsuck')
    elif gamepad.is_key_pressed('R1'):
        UartCommand=[170, 170, 4, 63, 3, 1, 1, 188] # suck
        uart1.write(bytes(UartCommand))
        suck=True
        cyberpi.console.print('suck')
    elif gamepad.is_key_pressed('Start'):
        uart1.write(bytes([170, 170, 8, 135, 3, 0, 1, 16, 39, 0, 0, 62])) # on 
        time.sleep(.295)
        uart1.write(bytes([170, 170, 8, 135, 3, 0, 1, 0, 0, 0, 0, 117])) # on 
    elif gamepad.is_key_pressed('N2'):
        Sx=200;Sy=0;Sz=50;Sr=0
        MoveToPoint(Sx,Sy,Sz,Sr)
    elif gamepad.is_key_pressed('N1'):
        Sx=0;Sy=200;Sz=50;Sr=0
        MoveToPoint(Sx,Sy,Sz,Sr)

```



