Code Monkey home page Code Monkey logo

easyaspi's Introduction

EasyAsPi

This project aims to remove a lot of the complexity of dealing with the GPIO and PiCamera for beginner level programmers working with the Raspberry Pi.

This project has been initially developed for use within my own classes that I teach but I hope it might find use for others too.

Getting started

This assumes you have a Raspberry Pi (and a PiCamera to use that functionality). All code tested on Raspberry Pi model 3, PiCamera model 2, running Raspbian 2018-06-29.

Install

pip install easyaspi

Usage

At present, the project supports LEDs, buttons, ultrasonics and the PiCamera. This list of tools is expected to grow as need arises.

Note: This library will set the default GPIO pin layout mode to BCM.

LEDs

  • Create the LED object
import easyaspi
led = easyaspi.LED( pin_number )
  • Turn an LED on
led.set(True)
  • Turn an LED off
led.set(False)

Buttons

  • Create the Button object
import easyaspi
button = easyaspi.Button( pin_number )
  • Retrieve if the button is being pressed
button_state = button.get()
  • Set an event callback for button presses
# Note: The function definition for the callback requires the state parameter even though it should always be set to True to indicate the button is currently pressed.

def was_pressed(state):
   print("Button was pressed!")

button.on_press(was_pressed)
  • Remove an event callback
button.remove_on_press()            # Remove any event listener for this button

Ultrasonic

  • Create the Ultrasonic variable
import easyaspi
ultra = easyaspi.Ultrasonic( trigger_pin_number, echo_pin_number )
  • Retrieve the distance in centimeters
distance = ultra.get_distance()

Pi Camera

  • Create the Camera object
import easyaspi
camera = easyaspi.Camera()
  • Take a photo (without a message)
camera.photo("myphoto.png")
  • Take a photo (with a message)
camera.photo("myphoto.png", "my message")
  • Start video recording
camera.record("myvideo.h264", "my message")
  • Check to see if camera is recording video
recording_state = camera.recording      # Returns True or False
  • Stop video recording
camera.stop()
  • Close the camera preview window when finished
camera.preview(False)

Author

License

MIT License (C) 2018 Paul Baumgarten

easyaspi's People

Contributors

paulbaumgarten avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.