background image

ROBOT.HEAD to TOE 

Product User’s Manual - 

HAT-MAKER 

 

8. PYTHON DEMO CODE

 

 
User can try this python demo code to control the LEDs and buzzer using push button on

 

 

 

 

 

 

   

 

 

 

 

 

 

 

 

 

Maker pHAT. Click on ​Menu - Programming - Python 3 (IDLE)​. Then click ​File - New File​.

 

 

 

 

   

   

   

 

 

 

   

 

 

Write (or copy and paste) the following python code (​

gist

). 

 

MakerpHATDemo.py - /home/pi/Documents/MakerpHATDemo.py (3.5.3) 

F​ile   ​E​dit   F​o​rmat   ​R​un   ​O​ptions   ​W​indow   ​H​elp 

from

 gpiozero 

import

 LED, Button, Buzzer 

from

 time 

import

 sleep 

import

 os 

 

LED1 = LED(17) 

LED2 = LED(18) 

LED3 = LED(27) 

LED4 = LED(22) 

LED5 = LED(25) 

LED6 = LED(12) 

LED7 = LED(13) 

LED8 = LED(19) 

 

SW1 = Button(21) 

SW2 = Button(16) 

SW3 = Button(20) 

 

BUZZER = Buzzer(26) 

 

NONE = 0 

DECREASE = 1 

INCREASE = 2 

ALL_OFF = 9 

ALL_ON = 10 

 

def

 

beep

(times, sec): 

  

for

 x 

in

 

range

(times): 

    BUZZER.on() 

    sleep(sec) 

    BUZZER.off() 

    sleep(sec) 

 

def

 

led

(ledNumber): 

  

if

 ledNumber == 1: 

    LED1.on() 

  

else

    LED1.off() 

 

  

if

 ledNumber == 2: 

    LED2.on() 

  

else

    LED2.off() 

 

  

if

 ledNumber == 3: 

    LED3.on() 

  

else

    LED3.off() 

 

 

 

Created by 

Cytron Technologies Sdn Bhd

 – All Rights Reserved 

Back to 

INDEX

  22 

Содержание Maker-pHAT

Страница 1: ...presentation or warranty is given and no liability is assumed by Cytron Technologies Incorporated with respect to the accuracy or use of such information or infringement of patents or other intellectual property rights arising from such use or otherwise Use of Cytron Technologies s products as critical components in life support system is not authorized except with express written approval by Cytr...

Страница 2: ...CKING LIST 3 PRODUCT SPECIFICATIONS 4 BOARD LAYOUT 5 HARDWARE INSTALLATION 6 GETTING STARTED 7 HIGHLIGHTED FEATURES 8 PYTHON DEMO CODE 9 SCHEMATIC 10 GALLERY 11 WARRANTY PAGES 2 3 4 5 6 8 20 21 24 25 27 Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 1 ...

Страница 3: ...ld like to introduce Maker pHAT It is designed to ease everyone in getting started with Raspberry Pi in the absence of additional monitor keyboard or mouse Headless and also prototyping It helps user to remote access Raspberry Pi through serial with minimum steps The on board LEDs push buttons and buzzer will further assist beginner in interfacing with sensors actuator and coding Maker pHAT is des...

Страница 4: ...and components according to the packing list If there are any parts missing please contact us at sales cytron io immediately No ITEMS QUANTITY 1 Maker pHAT Code HAT MAKER 1 2 2x20 Stacking Header Code CN PH PC104 1 Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 3 ...

Страница 5: ...T SPECIFICATIONS Dimension Absolute Maximum Rating of Maker pHAT No PARAMETERS Min Typ Max Unit 1 Input Voltage via USB connector 4 8 5 2 V 2 DC Current for 5V Pin Max Continuous USB mA Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 4 ...

Страница 6: ...PIO 11 CE0 GPIO 8 and CE1 GPIO 7 through SPI pins G GPIO INDICATOR LED Selected GPIO is equipped with LED where it can controlled or act as indicator for input H USB MICRO B CONNECTOR Supply alternative to Raspberry Pi and to remote through SSH serial I USB SERIAL INDICATOR LED Indicates USB Serial activity J USB SERIAL IC CONVERTER FT231X Converts USB data to serial data Used to remote Raspberry ...

Страница 7: ...spberry Pi Zero WH It can stack to Raspberry Pi Zero WH directly without any extra components 5 2 Raspberry Pi 3 Model B and Model B Plus Maker pHAT has standard Raspberry Pi GPIO footprint So it is compatible with Raspberry Pi 3 Model B or Model B Plus too You need PC104 Header Pin 2x20 in order to stack Maker pHAT on Raspberry Pi Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to...

Страница 8: ...t Pads on Maker pHAT Maker pHAT Rev1 10 comes with pre soldered SMD header pin on the breakout pads No worry about short circuit when you stack the Maker pHAT Rev1 10 on the Raspberry Pi Zero WH Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 7 ...

Страница 9: ...B Micro B Cable 6 2 Install the latest Raspbian OS Note The latest NOOBS V2 9 0 already comes with Raspbian pre installed If you get 16GB Micro SD Card with NOOBS for RPI you don t need to write Raspbian image Download the latest Raspbian OS Raspbian Stretch with Desktop and write the image on the SD card using Etcher Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 8 ...

Страница 10: ...r pHAT to Raspberry Pi Zero WH yet Connect Maker pHAT to your laptop using USB Micro B Cable Check either your laptop is able to detect the Maker pHAT Open Device Manager and check under Ports COM LPT category It should be detected as USB Serial Port COM number If yes you can proceed to the next step If not download and install Maker pHAT driver Download and install Maker pHAT driver Please choose...

Страница 11: ...oad and install PuTTY Connect your Maker pHAT to your laptop using USB Micro B Cable Since Maker pHAT is already stacked on the Raspberry Pi this connection will power up Raspberry Pi through Maker pHAT Please be reminded to not simply disconnect the cable without proper shutdown it might corrupt the microSD card Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 10 ...

Страница 12: ...pen Press Enter then insert Raspberry Pi default login information as follow raspberrypi login pi Password raspberry You can t see while typing the password So far you re able to access Raspberry Pi through serial remote Maker pHAT We will further guide you until we can remote using VNC Viewer Virtual Network Computing Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 11 ...

Страница 13: ...can set the WiFi connection in Raspberry Pi Software Configuration Tool Write the following command and Enter pi raspberrypi sudo raspi config To enter Raspberry Pi Configuration Tool Go to number 2 Network Options Then Enter Choose N2 Wi fi and Enter Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 12 ...

Страница 14: ...BOT HEAD to TOE Product User s Manual HAT MAKER Choose your country and press Enter Confirm your WiFi country by pressing Enter Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 13 ...

Страница 15: ...nual HAT MAKER Write your WiFi SSID WiFi name then Enter followed by WiFi passphrase WiFi password then Enter Done setting for WiFi connection Press Enter to Ok Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 14 ...

Страница 16: ...anual HAT MAKER Next we need to enable VNC server in Raspberry Pi Go back to the top menu and select to the number 5 Interfacing Options Select P3 VNC and Enter Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 15 ...

Страница 17: ...ROBOT HEAD to TOE Product User s Manual HAT MAKER Choose Yes and Enter VNC server is enabled Press Enter to Ok Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 16 ...

Страница 18: ...r pi raspberrypi sudo reboot Restart Raspberry Pi Login to Raspberry Pi like previous If all your setting is correct your Pi will connect to WiFi Next we need to trace the IP address Write following command and Enter pi raspberrypi ifconfig Check Raspberry Pi IP address Your Raspberry Pi will display IP address e g 192 168 0 106 Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to IN...

Страница 19: ...update your Raspbian with following command pi raspberrypi sudo apt get update Update Raspbian OS Done update open VNC Viewer and insert Raspberry Pi s IP address on the text bar Then press Enter Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 18 ...

Страница 20: ...ndow will popup Sometimes the warning is in yellow and sometimes in red Proceed with Continue button Fill up Raspberry Pi default login information Username pi Password raspberry Press OK Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 19 ...

Страница 21: ...roduct User s Manual HAT MAKER Tadaa Your VNC remote is successful Now you can access Raspberry Pi Desktop through VNC Viewer and WiFi connection Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 20 ...

Страница 22: ... push button are included in the Maker pHAT To utilize it user need to configure push button GPIO as input pullup SW1 is connected to GPIO 21 SW2 is connected to GPIO 16 SW3 is connected to GPIO 20 7 3 On board Active Buzzer Maker pHAT also comes with on board active buzzer It is standard output digital device connected to GPIO 26 To activate it set GPIO to high and to mute it just set GPIO to low...

Страница 23: ...ns W indow H elp from gpiozero import LED Button Buzzer from time import sleep import os LED1 LED 17 LED2 LED 18 LED3 LED 27 LED4 LED 22 LED5 LED 25 LED6 LED 12 LED7 LED 13 LED8 LED 19 SW1 Button 21 SW2 Button 16 SW3 Button 20 BUZZER Buzzer 26 NONE 0 DECREASE 1 INCREASE 2 ALL_OFF 9 ALL_ON 10 def beep times sec for x in range times BUZZER on sleep sec BUZZER off sleep sec def led ledNumber if ledNu...

Страница 24: ...8 LED8 on else LED8 off if ledNumber ALL_OFF LED1 off LED2 off LED3 off LED4 off LED5 off LED6 off LED7 off LED8 off elif ledNumber ALL_ON LED1 on LED2 on LED3 on LED4 on LED5 on LED6 on LED7 on LED8 on mode NONE ledPosition 0 led ALL_ON beep 1 0 1 led ALL_OFF try while True if SW1 is_pressed and mode DECREASE beep 2 0 07 mode DECREASE Created by Cytron Technologies Sdn Bhd All Rights Reserved Bac...

Страница 25: ... now elif SW2 is_pressed and mode INCREASE beep 2 0 07 mode INCREASE elif SW3 is_pressed and mode NONE beep 1 0 07 mode NONE if mode INCREASE if ledPosition 8 ledPosition ledPosition 1 else ledPosition 0 elif mode DECREASE if ledPosition 0 ledPosition ledPosition 1 else ledPosition 8 led ledPosition sleep 0 05 except KeyboardInterrupt led ALL_OFF Created by Cytron Technologies Sdn Bhd All Rights R...

Страница 26: ...p Wait until you hear a beep from Maker pHAT Now you can control the LED by pressing the push buttons SW1 Buzzer will produce double beep LED will running from right GPIO 19 to left GPIO17 SW2 Buzzer will produce double beep LED will running from left GPIO 17 to right GPIO19 SW3 Buzzer will produce single beep LED stop running Hold SW2 and SW3 Raspberry Pi shutdown Created by Cytron Technologies S...

Страница 27: ...ROBOT HEAD to TOE Product User s Manual HAT MAKER 9 SCHEMATIC Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 26 ...

Страница 28: ...ROBOT HEAD to TOE Product User s Manual HAT MAKER 10 GALLERY Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 27 ...

Страница 29: ...ROBOT HEAD to TOE Product User s Manual HAT MAKER Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 28 ...

Страница 30: ...s not covered under warranty Warranty does not cover freight cost for both ways Prepared by Cytron Technologies Sdn Bhd www cytron io No 1 Lorong Industri Impian 1 Taman Industri Impian 14000 Bukit Mertajam Penang Malaysia Tel 604 548 0668 Fax 604 548 0669 Email support cytron io sales cytron io Created by Cytron Technologies Sdn Bhd All Rights Reserved Back to INDEX 29 ...

Отзывы: